Crates.io | esp-hal-dhcp-server |
lib.rs | esp-hal-dhcp-server |
version | 0.1.2 |
source | src |
created_at | 2024-08-30 05:44:39.398801 |
updated_at | 2024-10-19 10:33:53.144171 |
description | A simple DHCP server for embassy-net (main target is esp-hal) |
homepage | |
repository | https://github.com/filipton/esp-hal-dhcp-server |
max_upload_size | |
id | 1357395 |
size | 15,534 |
Simple dhcp server for embassy tested on esp-hal (esp32-s3 - WiFiAP with android phone).
To see full example look inside ./example
dir, you can cd into it and run it as normal crate
// ...
// spawn your dhcp_server task
spawner.spawn(dhcp_server(stack)).ok();
log::info!("Closing dhcp server after 2m...");
Timer::after(Duration::from_secs(120)).await;
log::info!("Closing dhcp server...");
// you can close your server using builtin SIGNAL
esp_hal_dhcp::dhcp_close();
// ...
// ...
#[embassy_executor::task]
async fn dhcp_server(stack: &'static Stack<WifiDevice<'static, WifiApDevice>>) {
let config = DhcpServerConfig {
ip: Ipv4Addr::new(192, 168, 2, 1),
lease_time: Duration::from_secs(3600),
gateways: &[],
subnet: None,
dns: &[],
};
let mut leaser = SimpleDhcpLeaser {
start: Ipv4Addr::new(192, 168, 2, 50),
end: Ipv4Addr::new(192, 168, 2, 200),
leases: Default::default(),
};
esp_hal_dhcp::run_dhcp_server(stack, config, &mut leaser).await;
}