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
This commit is contained in:
Earle F. Philhower, III 2022-08-19 18:03:21 -07:00 committed by GitHub
parent e2afeaef27
commit d019f31ef1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 5 deletions

View file

@ -36,7 +36,6 @@
#define CYW43_WL_GPIO_LED_PIN 0 #define CYW43_WL_GPIO_LED_PIN 0
#endif #endif
volatile bool __inLWIP = false; volatile bool __inLWIP = false;
// note same code // note same code

View file

@ -25,8 +25,6 @@
#include <hardware/flash.h> #include <hardware/flash.h>
#include <PicoOTA.h> #include <PicoOTA.h>
#define DEBUG_UPDATER Serial
#include <Updater_Signing.h> #include <Updater_Signing.h>
#ifndef ARDUINO_SIGNING #ifndef ARDUINO_SIGNING
#define ARDUINO_SIGNING 0 #define ARDUINO_SIGNING 0

View file

@ -96,6 +96,8 @@ int WiFiClass::begin(const char* ssid, const char *passphrase) {
if (!_wifi.begin()) { if (!_wifi.begin()) {
return WL_IDLE_STATUS; return WL_IDLE_STATUS;
} }
// Enable CYW43 event debugging (make sure Debug Port is set)
//cyw43_state.trace_flags = 0xffff;
while (!_calledESP && ((millis() - start < (uint32_t)2 * _timeout)) && !connected()) { while (!_calledESP && ((millis() - start < (uint32_t)2 * _timeout)) && !connected()) {
delay(10); delay(10);
} }
@ -152,7 +154,7 @@ uint8_t WiFiClass::beginAP(const char *ssid, const char* passphrase) {
#endif #endif
bool WiFiClass::connected() { bool WiFiClass::connected() {
return (_apMode && _wifiHWInitted) || (_wifi.connected() && localIP().isSet()); return (_apMode && _wifiHWInitted) || (_wifi.connected() && localIP().isSet() && (cyw43_wifi_link_status(&cyw43_state, _apMode ? 1 : 0) == CYW43_LINK_JOIN));
} }
/* Change Ip configuration settings disabling the dhcp client /* Change Ip configuration settings disabling the dhcp client

View file

@ -37,6 +37,9 @@ WiFiMulti::~WiFiMulti() {
bool WiFiMulti::addAP(const char *ssid, const char *pass) { bool WiFiMulti::addAP(const char *ssid, const char *pass) {
struct _AP ap; struct _AP ap;
if (!ssid) {
return false;
}
ap.ssid = strdup(ssid); ap.ssid = strdup(ssid);
if (!ap.ssid) { if (!ap.ssid) {
return false; return false;
@ -82,7 +85,11 @@ uint8_t WiFiMulti::run(uint32_t to) {
// Connect! // Connect!
uint32_t start = millis(); uint32_t start = millis();
if (hit->pass) {
WiFi.begin(hit->ssid, hit->pass); WiFi.begin(hit->ssid, hit->pass);
} else {
WiFi.begin(hit->ssid);
}
while (!WiFi.connected() && (millis() - start < to)) { while (!WiFi.connected() && (millis() - start < to)) {
delay(5); delay(5);
} }

View file

@ -26,6 +26,18 @@ extern "C" {
#include "pico/cyw43_arch.h" #include "pico/cyw43_arch.h"
#include <Arduino.h> #include <Arduino.h>
// From cyw43_ctrl.c
#define WIFI_JOIN_STATE_KIND_MASK (0x000f)
#define WIFI_JOIN_STATE_ACTIVE (0x0001)
#define WIFI_JOIN_STATE_FAIL (0x0002)
#define WIFI_JOIN_STATE_NONET (0x0003)
#define WIFI_JOIN_STATE_BADAUTH (0x0004)
#define WIFI_JOIN_STATE_AUTH (0x0200)
#define WIFI_JOIN_STATE_LINK (0x0400)
#define WIFI_JOIN_STATE_KEYED (0x0800)
#define WIFI_JOIN_STATE_ALL (0x0e01)
netif *CYW43::_netif = nullptr; netif *CYW43::_netif = nullptr;
CYW43::CYW43(int8_t cs, arduino::SPIClass& spi, int8_t intrpin) { 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) {
if (CYW43::_netif) { if (CYW43::_netif) {
netif_set_link_down(CYW43::_netif); netif_set_link_down(CYW43::_netif);
} }
self->wifi_join_state &= ~WIFI_JOIN_STATE_ACTIVE;
} }
extern "C" int cyw43_tcpip_link_status(cyw43_t *self, int itf) { extern "C" int cyw43_tcpip_link_status(cyw43_t *self, int itf) {