mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-17 07:14:23 +01:00
sphinx-key: timeout sntp setup and restart
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use esp_idf_svc::sntp::EspSntp;
|
||||
use esp_idf_svc::sntp::SyncStatus::Completed;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
pub fn sync_time() {
|
||||
let sntp = EspSntp::new_default().unwrap();
|
||||
pub fn sync_time_timeout() -> Result<()> {
|
||||
let mut counter = 0;
|
||||
let sntp = EspSntp::new_default()?;
|
||||
loop {
|
||||
let status = sntp.get_sync_status();
|
||||
println!("SNTP status {:?}", status);
|
||||
if status == Completed {
|
||||
break;
|
||||
break Ok(());
|
||||
} else if counter == 30 {
|
||||
break Err(anyhow!("SNTP setup timed out"));
|
||||
}
|
||||
counter = counter + 1;
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,11 @@ fn main() -> Result<()> {
|
||||
};
|
||||
|
||||
led_tx.send(Status::SyncingTime).unwrap();
|
||||
conn::sntp::sync_time();
|
||||
if let Err(e) = conn::sntp::sync_time_timeout() {
|
||||
log::error!("Could not setup sntp: {}", e);
|
||||
log::info!("Restarting esp!");
|
||||
unsafe { esp_idf_sys::esp_restart() };
|
||||
}
|
||||
let now = SystemTime::now()
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user