rust-esp32-std-demo icon indicating copy to clipboard operation
rust-esp32-std-demo copied to clipboard

Time synchronisation example

Open mohs8421 opened this issue 3 years ago • 1 comments
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?

mohs8421 avatar Oct 18 '22 08:10 mohs8421

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.

mohs8421 avatar Oct 18 '22 12:10 mohs8421

SysTime from esp-idf-svc.

ivmarkov avatar Nov 18 '22 16:11 ivmarkov