Skip to content

Commit 8366d0e

Browse files
Bl00d-B0bclaude
andcommitted
[lightning-ln882h] Fix static IP ignored after WiFi connect (libretiny-eu#375)
wifi_sta_connect() always starts DHCP internally; there is no way to pass a dhcp_mode parameter to it like BK72XX's bk_wlan_start_sta_adv_fix. Apply static IP and stop DHCP in wifiEventStaConnected(), immediately after the L2 association event fires, before the SDK-initiated DHCP exchange completes. Emit GOT_IP manually since the netdev callback won't fire when DHCP is stopped. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent af7e7e8 commit 8366d0e

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

cores/lightning-ln882h/arduino/libraries/WiFi/WiFiEvents.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ static void wifiEventStaConnected(void *arg) {
2828
memcpy(eventInfo.wifi_sta_connected.bssid, pWiFi->BSSID(), 6);
2929

3030
pWiFi->postEvent(ARDUINO_EVENT_WIFI_STA_CONNECTED, eventInfo);
31+
32+
// If static IP is configured, apply it now and stop DHCP before the SDK
33+
// starts it. wifi_sta_connect() always starts DHCP internally; we have no
34+
// way to pass dhcp_mode to it (unlike BK72XX's bk_wlan_start_sta_adv_fix).
35+
WiFiNetworkInfo &info = pDATA->sta;
36+
if (info.localIP) {
37+
struct netif *ifs = netdev_get_netif(NETIF_IDX_STA);
38+
ip4_addr_t ipaddr, netmask, gw;
39+
ipaddr.addr = info.localIP;
40+
netmask.addr = info.subnet;
41+
gw.addr = info.gateway;
42+
netif_set_addr(ifs, &ipaddr, &netmask, &gw);
43+
netifapi_dhcp_release_and_stop(ifs);
44+
// Emit GOT_IP manually — DHCP is stopped so the netdev callback won't fire
45+
wifiEventIpReceived(ifs);
46+
}
3147
}
3248

3349
static void wifiEventStaDisconnected(void *arg) {

0 commit comments

Comments
 (0)