![]() |
Sending Android System Time Stamp to Arduino - Printable Version +- Virtuino Forum (https://virtuino.com/forum) +-- Forum: Virtuino (https://virtuino.com/forum/forumdisplay.php?fid=1) +--- Forum: Virtuino 6 (https://virtuino.com/forum/forumdisplay.php?fid=3) +--- Thread: Sending Android System Time Stamp to Arduino (/showthread.php?tid=21935) |
Sending Android System Time Stamp to Arduino - JimKazmer - 08-12-2024 Hello, I am using Virtuino 6 on Android to communicate via blue tooth to an Arduino. I'd like to send the phone's time stamp to the Arduino. It seems like such a simple thing... I want to avoid requiring the user to use the date time picker to select today's date/time (very many clicks). I've poked around what I thought was all the different widgets, but cannot figure it out. I can display the current date/time by using the hack of showing the "Updated Value date", but you cannot copy that value to anything. RE: Sending Android System Time Stamp to Arduino - iliaslamprou - 08-17-2024 Hi, no it is not possible. This ability is added to the newer app virtuino IoT RE: Sending Android System Time Stamp to Arduino - Araqel - 08-17-2025 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$ RE: Sending Android System Time Stamp to Arduino - Araqel - 08-19-2025 I have a newer refined answer to this topic. The preliminary options are as follows. The server is standalone, thus cannot get the data&time info from Internet. But the server is equipped with RTC module, so the actual time can be requested from smartphone and get the RTC adjusted. For phone and microcontroller time comparision, at least for debugging purpose you should have two value displaying widgets, one for phone time and another for controller time. If you have used Advanced Value Display widget and have used the value type as "Updated value data" for phone time, you should change it to "Time" value type. Being used the "Updated value data" that blocks most of Android Sensor data usage. As "Server" should be chousen the Android Device Sensor's V6, which returns Unix epoch time in milliseconds. On server side I have used Adafruit developed RTC library (available here), which can give the epoch time in seconds. The part of code looks like this: Code: DateTime now = rtc.now(); Now, lets discuss the actual time data sending to microcontroller. Add an Script widget, in script field write Code: x/1000 Another observation is that the refresh rate of script widget does not work as expected and it is bombarding the controller as fast as it can. Bug report - Araqel - 08-19-2025 A post earlier I wrote that the Script widget ignores the own refresh rate value and floods the connection with microcontroller. To overcome this trouble, I redirect the output of Script widget to some buffer cell in M memory, let's to say, to M30 of Android and planning to push the data to microcontroller on demand. I try to create a system button, which where the action set as something neutral thing, like "Select First Panel", then in "Command" section of widget I add a command, namely, on Click send command to Virtuino Server's V8 variable the content of Emulator's M30 value. On "System button" clicking nothing has been sent to controller. In meantime for debugging purpose the content of M30 is displayed by value widget. It is proven that the data is available and updates itself automatically. This post is the final fix of timestamp sending microcontroller subject. Select "Botton creator widget", "Operation": Custom Button "Server": Virtuino server1 "Memory": Somewhat V? "Click down": Emulator M30 (* See earlier post. This is the buffer memory where the Script widget fires the timestamp) "Click" up: Nothing "Long click: Nothing RE: Sending Android System Time Stamp to Arduino - Araqel - 08-20-2025 (08-17-2025, 05:55 PM)Araqel Wrote: I have a solution for this task. 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: //============================================================== 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}]}$ RE: Sending Android System Time Stamp to Arduino - Araqel - 08-25-2025 Here is a fine tuning becomes available. The app on the fly adds GMT difference between sent or received timestamps. It was a hard detecting feature, because of the sent and received data equal visualization result. My place's GMT is +4:00, thus I did 14400 seconds addition on sending and so much deduction on receiving, then multiplication by 1000, for milliseconds addition, as requires the widget input format. RE: Sending Android System Time Stamp to Arduino - Araqel - 08-31-2025 For JSON processing on controller side, I would like to recommend very handy to use library It seems that my comments are in need of some edition. Having used the Unixtime format, the JSON implantation is not required at all. But if the "Schedule" widget has been used, then the JSON processing is a must. And remember, do not use the "Updated Value date" option. |