Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending Android System Time Stamp to Arduino
#6
(08-17-2025, 05:55 PM)Araqel Wrote: I have a solution for this task.
Pick up the "Text script or Json creator", fill in "Script" field the following Json: {"Day":#value1, "Hour":#value2, "Minutes":#value3}. In the given example the "Day" stands for the day of week. Now choose an output variable on your Virtuino server. For testing that you should at least once in loop use that variable, for example print that on serial terminal.
Then you should chouse input variables by pressing "+" as much time, as you have input variable. The first input variable is the Android device sensor's V12-Day -of the week, next is the V9-Hour and last is V8-Minute. The Widget does not have its own refresh rate definition, so be careful to include the "seconds", which may overload the connection with server.
The following is the received Json on my terminal, sent to V[8] server side variable.
Code:
21:37:01.549 -> Received data: 1234!V08=%7B%22Day%22%3A0%2C+%22Hour%22%3A0%2C+%22Minute%22%3A37%7D$
21:37:01.549 -> %7B%22Day%22%3A0%2C+%22Hour%22%3A0%2C+%22Minute%22%3A37%7D

As it is obvious, the application has non-perfection in Json generating, where hex data is mixed with ascii codes. Cause of this it is impossible to feed such a date to app's Json converter widget, for further use or debugging.
I have modified the original sketch for on-the-fly Json correction.
Code:
//==============================================================
void virtuinoRun() {
  short s = 3;
  String tempStr = "";
  WiFiClient client = server.accept();
  if (!client) return;
  //if (debug) Serial.println("Connected");
  unsigned long timeout = millis() + 3000;
  while (!client.available() && millis() < timeout) delay(1);
  if (millis() > timeout) {
    //  Serial.println("timeout");
    client.clear();
    // client.stop();
    return;
  }
  virtuino.readBuffer = "";  // clear Virtuino input buffer. The inputBuffer stores the incoming characters
  while (client.available() > 0) {
    char c = client.read();  // read the incoming data
    if (c == '%') {
      s--;
    }
    if (c != '%' && s == 2) {
      tempStr += c;
      s--;
    } else {
      if (c != '%' && s == 1) {
        s--;
        tempStr += c;
        virtuino.readBuffer += (char)strtol(tempStr.c_str(), NULL, 16);
        tempStr = "";
      }
    }
    if (s == 0) {
      s = 3;
    } else {
      if (s == 3 && c != '%') {
        virtuino.readBuffer += c;  // add the incoming character to Virtuino input buffer
        // if (debug) Serial.write(c);
      }
    }
  }
Now, the Json of "Programmable button wedget's Json on IDE's Serial monitor looks like this, instead of earlier garbage:
Code:
00:33:48.928 -> Received data: 1234!V02={"ID":"schedule","date":"հնգ+2025-08-21+00:33:48","items":[{"D":"0111111","H":8,"M":0,"S":0,"ST":1},{"D":"0111111","H":18,"M":0,"S":0,"ST":0}]}$
00:33:48.928 -> V2 = {"ID":"schedule","date":"հնգ+2025-08-21+00:33:48","items":[{"D":"0111111","H":8,"M":0,"S":0,"ST":1},{"D":"0111111","H":18,"M":0,"S":0,"ST":0}]}
Reply


Messages In This Thread
RE: Sending Android System Time Stamp to Arduino - by Araqel - 08-20-2025, 08:59 PM
Bug report - by Araqel - 08-19-2025, 11:17 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)