https://toitlang.org/ logo
adjust clock time (no ntp server)
# help
c
My device is on a locked down network with no access to ntp servers or worldtime API's. I receive a MQTT message on device boot-up which contains the current timestamp in ISO 8601 format. I would like to set the ESP32's internal clock to this new timestamp, however I can only figure out how to use "adjust-real-time-clock" when using ntp.synchronize and getting the "adjustment" amount I think I just need to figure out the difference between the actual time I receive and the epoch that the device defaults too and use that difference (in seconds?) to adjust the clock. Any insight or help on this task is greatly appreciated.
f
I think you can just set the clock with
set-real-time-clock
. https://libs.toit.io/esp32/library-summary#set-real-time-clock(1%2C0%2C0%2C)
set-real-time-clock (Time.parse "<your timestamp>")
That function is in the
esp32
library.
So
import esp32 show set-real-time-clock
.
c
Thank you floitsch - it works on device Funny enough, when I was attempting that method using "jag simulate" to run the program, doing "Time.now" did not return the updated time. Thought I was going crazy but might just be a difference with how a simulated vs real jag instance behaves.
f
The simulated device is just running a host version of the Jaguar snapshot. Calling it "simulate" is pretty misleading.
You can run an actual simulation using qemu, but it's a bit more involved (as qemu doesn't support WiFi for the ESP32 yet).
k
It simulates the Jaguar experience, not the ESP32 chip 😎
c
thank you both for the clarification 🙏