#dhcp-server #esp-hal #embassy-net #ip #target #android #stack

esp-hal-dhcp-server

A simple DHCP server for embassy-net (main target is esp-hal)

6 releases

0.2.2 Jan 2, 2025
0.2.1 Dec 13, 2024
0.1.2 Oct 19, 2024
0.1.1 Sep 3, 2024
0.1.0 Aug 30, 2024

#557 in Hardware support

Download history 19/week @ 2024-09-18 6/week @ 2024-09-25 2/week @ 2024-10-02 1/week @ 2024-10-09 150/week @ 2024-10-16 14/week @ 2024-10-23 6/week @ 2024-10-30 6/week @ 2024-11-06 1/week @ 2024-11-13 1/week @ 2024-12-04 228/week @ 2024-12-11 11/week @ 2024-12-18 146/week @ 2025-01-01

386 downloads per month

MIT license

14KB
293 lines

esp-hal-dhcp-server

Simple dhcp server for embassy tested on esp-hal (esp32-s3 - WiFiAP with android phone).

crates.io MIT license

Example

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: Stack<'static>) {
    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;
}

Dependencies

~5MB
~104K SLoC