Expand description
Embassy async runtime UDP socket adapter for the sntpc SNTP client library.
This crate provides a wrapper around embassy_net::udp::UdpSocket that implements
the NtpUdpSocket trait, enabling asynchronous SNTP requests in embedded systems
using the Embassy async runtime.
§Design Rationale
The network adapters are separated into their own crates to:
- Enable independent versioning (updating Embassy doesn’t require updating
sntpccore) - Allow version flexibility (works with embassy-net 0.8.x)
- Maintain
no_stdcompatibility for embedded systems
§Features
ipv6: Enables IPv6 protocol support (propagates toembassy-net)log: Enables logging support via thelogcratedefmt: Enables logging support via thedefmtcrate for embedded systems
Note: The log and defmt features are mutually exclusive. If both are enabled,
defmt takes priority.
§Example
ⓘ
use sntpc::{get_time, NtpContext};
use sntpc_net_embassy::UdpSocketWrapper;
use embassy_net::udp::UdpSocket;
// Within an Embassy async context
let socket = UdpSocket::new(stack, &mut rx_buffer, &mut tx_buffer);
socket.bind(local_port).unwrap();
let socket = UdpSocketWrapper::from(socket);
let result = get_time(server_addr, &socket, ntp_context).await;
match result {
Ok(time) => defmt::info!("Received time: {}.{}", time.sec(), time.sec_fraction()),
Err(e) => defmt::error!("Failed to get time: {:?}", e),
}For more examples, see the repository examples.
Structs§
- UdpSocket
Wrapper - A wrapper around
embassy_net::udp::UdpSocketthat implementsNtpUdpSocket.