Skip to content

Commit d019f31

Browse files
Report ::connected() as false when WiFi link drops (#774)
There may be an issue in the CYW43 driver that causes a link to never be reported as going down once it has connected, when it was disassociated or when the wlan shuts off unexpectedly. Work around it by clearing the internal link active in a TCP callback for the CYW43 driver. Reports disconnection properly now, as well as reconnection. Fixes #762
1 parent e2afeae commit d019f31

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

cores/rp2040/sdkoverride/cyw43_arch_threadsafe_background.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#define CYW43_WL_GPIO_LED_PIN 0
3737
#endif
3838

39-
4039
volatile bool __inLWIP = false;
4140

4241
// note same code

libraries/Updater/src/Updater.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#include <hardware/flash.h>
2626
#include <PicoOTA.h>
2727

28-
#define DEBUG_UPDATER Serial
29-
3028
#include <Updater_Signing.h>
3129
#ifndef ARDUINO_SIGNING
3230
#define ARDUINO_SIGNING 0

libraries/WiFi/src/WiFiClass.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ int WiFiClass::begin(const char* ssid, const char *passphrase) {
9696
if (!_wifi.begin()) {
9797
return WL_IDLE_STATUS;
9898
}
99+
// Enable CYW43 event debugging (make sure Debug Port is set)
100+
//cyw43_state.trace_flags = 0xffff;
99101
while (!_calledESP && ((millis() - start < (uint32_t)2 * _timeout)) && !connected()) {
100102
delay(10);
101103
}
@@ -152,7 +154,7 @@ uint8_t WiFiClass::beginAP(const char *ssid, const char* passphrase) {
152154
#endif
153155

154156
bool WiFiClass::connected() {
155-
return (_apMode && _wifiHWInitted) || (_wifi.connected() && localIP().isSet());
157+
return (_apMode && _wifiHWInitted) || (_wifi.connected() && localIP().isSet() && (cyw43_wifi_link_status(&cyw43_state, _apMode ? 1 : 0) == CYW43_LINK_JOIN));
156158
}
157159

158160
/* Change Ip configuration settings disabling the dhcp client

libraries/WiFi/src/WiFiMulti.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ WiFiMulti::~WiFiMulti() {
3737

3838
bool WiFiMulti::addAP(const char *ssid, const char *pass) {
3939
struct _AP ap;
40+
if (!ssid) {
41+
return false;
42+
}
4043
ap.ssid = strdup(ssid);
4144
if (!ap.ssid) {
4245
return false;
@@ -82,7 +85,11 @@ uint8_t WiFiMulti::run(uint32_t to) {
8285

8386
// Connect!
8487
uint32_t start = millis();
85-
WiFi.begin(hit->ssid, hit->pass);
88+
if (hit->pass) {
89+
WiFi.begin(hit->ssid, hit->pass);
90+
} else {
91+
WiFi.begin(hit->ssid);
92+
}
8693
while (!WiFi.connected() && (millis() - start < to)) {
8794
delay(5);
8895
}

libraries/lwIP_CYW43/src/utility/CYW43shim.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ extern "C" {
2626
#include "pico/cyw43_arch.h"
2727
#include <Arduino.h>
2828

29+
// From cyw43_ctrl.c
30+
#define WIFI_JOIN_STATE_KIND_MASK (0x000f)
31+
#define WIFI_JOIN_STATE_ACTIVE (0x0001)
32+
#define WIFI_JOIN_STATE_FAIL (0x0002)
33+
#define WIFI_JOIN_STATE_NONET (0x0003)
34+
#define WIFI_JOIN_STATE_BADAUTH (0x0004)
35+
#define WIFI_JOIN_STATE_AUTH (0x0200)
36+
#define WIFI_JOIN_STATE_LINK (0x0400)
37+
#define WIFI_JOIN_STATE_KEYED (0x0800)
38+
#define WIFI_JOIN_STATE_ALL (0x0e01)
39+
40+
2941
netif *CYW43::_netif = nullptr;
3042

3143
CYW43::CYW43(int8_t cs, arduino::SPIClass& spi, int8_t intrpin) {
@@ -124,6 +136,7 @@ extern "C" void cyw43_cb_tcpip_set_link_down(cyw43_t *self, int itf) {
124136
if (CYW43::_netif) {
125137
netif_set_link_down(CYW43::_netif);
126138
}
139+
self->wifi_join_state &= ~WIFI_JOIN_STATE_ACTIVE;
127140
}
128141

129142
extern "C" int cyw43_tcpip_link_status(cyw43_t *self, int itf) {

0 commit comments

Comments
 (0)