rust-esp32-std-demo
rust-esp32-std-demo copied to clipboard
Time synchronisation example
trafficstars
I would like to sync the system clock and get unixtimestamps, but I am unsure how to do it.
I already found out, that I have to start with this:
use esp_idf_svc::sntp::EspSntp;
let sntp = EspSntp::new_default().unwrap();
but how do I access the correct time now?
After some searching, I found a solution, which looks like this:
pub fn time() -> i64 {
let mut timer: time_t = 0;
unsafe {
esp_idf_sys::time(&mut timer);
}
timer as i64
}
This might be a nice small addition to the examples.
SysTime from esp-idf-svc.