A RPi Pico powered Lightning Detector
at main 26 lines 742 B view raw
1use embassy_net::{dns, udp::UdpSocket}; 2use sachy_fmt::{error, unwrap}; 3use sachy_sntp::SntpSocket; 4 5use crate::rtc::GlobalRtc; 6 7pub async fn sntp_loop<'device>( 8 udp: &mut UdpSocket<'device>, 9 stack: embassy_net::Stack<'device>, 10 rtc: GlobalRtc<'static>, 11) { 12 loop { 13 let Ok(addr) = stack.dns_query("pool.ntp.org", dns::DnsQueryType::A).await else { 14 error!("Failed to query DNS for an NTP server. Retrying..."); 15 continue; 16 }; 17 18 match udp.resolve_time(addr.as_slice()).await { 19 Ok(time) => { 20 unwrap!(rtc.set_rtc_datetime(time).await); 21 break; 22 } 23 Err(e) => error!("Failed to resolve SNTP time: {}", e), 24 } 25 } 26}