08-19-2025, 09:37 AM
(This post was last modified: 08-19-2025, 12:05 PM by Araqel.
Edit Reason: Misspelling
)
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:
Now, lets discuss the actual time data sending to microcontroller. Add an Script widget, in script field write
Input X needs to be the Android Device Sensor's V6-ms. If you do not divide this by 1000, this data will overflow the Output side variable (which need to be chosen as somewhat variable on microcontroller), even being chosen the unsigned long. On microcontroller side you will get milliseconds as fraction, which can be easily truncated or rounded to integer or since the data are coming as String type, it can be wiped out last 4 symbols, the decimal dot inclusive. The clock adjustmentt on server side needs in seconds data, instead of milliseconds, which sends the phone.
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.
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();
V[18] = String(now.unixtime());
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.