guild icon
Toit
#adjust clock time (no ntp server)
Thread channel in help
crockedile
crockedile 05/30/2025 12:55 PM
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.
floitsch
floitsch 05/30/2025 12:58 PM
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)
floitsch
floitsch 05/30/2025 12:59 PM
set-real-time-clock (Time.parse "<your timestamp>")
floitsch
floitsch 05/30/2025 12:59 PM
That function is in the esp32 library.
floitsch
floitsch 05/30/2025 12:59 PM
So import esp32 show set-real-time-clock.
🙏1
crockedile
crockedile 05/30/2025 03:20 PM
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.
floitsch
floitsch 05/30/2025 03:21 PM
The simulated device is just running a host version of the Jaguar snapshot. Calling it "simulate" is pretty misleading.
floitsch
floitsch 05/30/2025 03:22 PM
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).
👍1
floitschfloitsch
The simulated device is just running a host version of the Jaguar snapshot. Calling it "simulate" is pretty misleading.
bitphlipphar
bitphlipphar 06/02/2025 05:34 AM
It simulates the Jaguar experience, not the ESP32 chip :😎:
👍1
crockedile
crockedile 06/02/2025 03:39 PM
thank you both for the clarification :🙏:
10 messages in total