Skip to content

Commit 1cc3d0d

Browse files
authored
[realtek-amb] Support static IP in WiFi connection (#354)
1 parent 60fa1cb commit 1cc3d0d

1 file changed

Lines changed: 28 additions & 20 deletions

File tree

cores/realtek-amb/arduino/libraries/WiFi/WiFiSTA.cpp

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ bool WiFiClass::reconnect(const uint8_t *bssid) {
7878
int ret;
7979
uint8_t dhcpRet;
8080
WiFiNetworkInfo &info = DATA->sta;
81+
EventInfo *eventInfo = nullptr;
8182

8283
LT_IM(WIFI, "Connecting to %s (bssid=%p)", info.ssid, bssid);
8384
DIAG_PRINTF_DISABLE();
@@ -127,31 +128,38 @@ bool WiFiClass::reconnect(const uint8_t *bssid) {
127128
// Feed watchdog after connect, before DHCP
128129
lt_wdt_feed();
129130

130-
if (ret == RTW_SUCCESS) {
131+
if (ret != RTW_SUCCESS) {
132+
LT_EM(WIFI, "Connection failed; ret=%d", ret);
133+
goto error;
134+
}
135+
136+
// Run DHCP only if not using static IP configuration
137+
if (!DATA->sta.localIP) {
131138
dhcpRet = LwIP_DHCP(0, DHCP_START);
132139
// Feed watchdog after DHCP
133140
lt_wdt_feed();
134-
if (dhcpRet == DHCP_ADDRESS_ASSIGNED) {
135-
LT_HEAP_I();
136-
EventInfo *eventInfo = (EventInfo *)calloc(1, sizeof(EventInfo));
137-
eventInfo->got_ip.if_index = 0;
138-
eventInfo->got_ip.esp_netif = NULL;
139-
eventInfo->got_ip.ip_info.ip.addr = localIP();
140-
eventInfo->got_ip.ip_info.gw.addr = gatewayIP();
141-
eventInfo->got_ip.ip_info.netmask.addr = subnetMask();
142-
eventInfo->got_ip.ip_changed = true;
143-
// pass the event through the queue
144-
wifi_indication(WIFI_EVENT_CONNECT, (char *)eventInfo, ARDUINO_EVENT_WIFI_STA_GOT_IP, -2);
145-
// free memory as wifi_indication creates a copy
146-
free(eventInfo);
147-
DIAG_PRINTF_ENABLE();
148-
return true;
141+
if (dhcpRet != DHCP_ADDRESS_ASSIGNED) {
142+
LT_EM(WIFI, "DHCP failed; dhcpRet=%d", dhcpRet);
143+
wifi_disconnect();
144+
goto error;
149145
}
150-
LT_EM(WIFI, "DHCP failed; dhcpRet=%d", dhcpRet);
151-
wifi_disconnect();
152-
goto error;
153146
}
154-
LT_EM(WIFI, "Connection failed; ret=%d", ret);
147+
148+
LT_HEAP_I();
149+
eventInfo = (EventInfo *)calloc(1, sizeof(EventInfo));
150+
eventInfo->got_ip.if_index = 0;
151+
eventInfo->got_ip.esp_netif = NULL;
152+
eventInfo->got_ip.ip_info.ip.addr = localIP();
153+
eventInfo->got_ip.ip_info.gw.addr = gatewayIP();
154+
eventInfo->got_ip.ip_info.netmask.addr = subnetMask();
155+
eventInfo->got_ip.ip_changed = true;
156+
// pass the event through the queue
157+
wifi_indication(WIFI_EVENT_CONNECT, (char *)eventInfo, ARDUINO_EVENT_WIFI_STA_GOT_IP, -2);
158+
// free memory as wifi_indication creates a copy
159+
free(eventInfo);
160+
161+
DIAG_PRINTF_ENABLE();
162+
return true;
155163
error:
156164
DIAG_PRINTF_ENABLE();
157165
return false;

0 commit comments

Comments
 (0)