mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-17 15:24:32 +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::EspSntp;
|
||||||
use esp_idf_svc::sntp::SyncStatus::Completed;
|
use esp_idf_svc::sntp::SyncStatus::Completed;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
pub fn sync_time() {
|
pub fn sync_time_timeout() -> Result<()> {
|
||||||
let sntp = EspSntp::new_default().unwrap();
|
let mut counter = 0;
|
||||||
|
let sntp = EspSntp::new_default()?;
|
||||||
loop {
|
loop {
|
||||||
let status = sntp.get_sync_status();
|
let status = sntp.get_sync_status();
|
||||||
println!("SNTP status {:?}", status);
|
println!("SNTP status {:?}", status);
|
||||||
if status == Completed {
|
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));
|
thread::sleep(Duration::from_secs(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,11 @@ fn main() -> Result<()> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
led_tx.send(Status::SyncingTime).unwrap();
|
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()
|
let now = SystemTime::now()
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user