Skip to content

Commit 5abd2ab

Browse files
committed
WIP: going for food. esp8266 working
1 parent a0aa472 commit 5abd2ab

File tree

3 files changed

+63
-20
lines changed

3 files changed

+63
-20
lines changed

src/network_interfaces/Wippersnapper_ESP32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class Wippersnapper_ESP32 : public Wippersnapper {
287287
if (_wifiMulti.run(20000) == WL_CONNECTED) {
288288
_status = WS_NET_CONNECTED;
289289
} else {
290-
_status = WS_NET_CONNECT_FAILED;
290+
_status = WS_NET_DISCONNECTED;
291291
}
292292
} else {
293293
// single network mode

src/network_interfaces/Wippersnapper_ESP8266.h

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#ifdef ARDUINO_ARCH_ESP8266
2121
#include "Adafruit_MQTT.h"
2222
#include "Adafruit_MQTT_Client.h"
23-
#include "ESP8266WiFiMulti.h"
2423
#include "ESP8266WiFi.h"
24+
#include "ESP8266WiFiMulti.h"
2525
#include "Wippersnapper.h"
2626

2727
/* NOTE - Projects that require "Secure MQTT" (TLS/SSL) also require a new
@@ -136,7 +136,14 @@ class Wippersnapper_ESP8266 : public Wippersnapper {
136136

137137
// Was the network within secrets.json found?
138138
for (int i = 0; i < n; ++i) {
139-
if (strcmp(_ssid, WiFi.SSID(i).c_str()) == 0)
139+
if (strlen(WS._multiNetworks[0].ssid) > 0) {
140+
// multi network mode
141+
for (int j = 0; j < 5; j++) {
142+
if (strcmp(WS._multiNetworks[j].ssid, WiFi.SSID(i).c_str()) == 0)
143+
return true;
144+
}
145+
} // else single network mode
146+
else if (strcmp(_ssid, WiFi.SSID(i).c_str()) == 0)
140147
return true;
141148
}
142149

@@ -227,21 +234,57 @@ class Wippersnapper_ESP8266 : public Wippersnapper {
227234
if (WiFi.status() == WL_CONNECTED)
228235
return;
229236

230-
// Attempt connection
231-
_disconnect();
232-
delay(100);
233-
// ESP8266 MUST be in STA mode to avoid device acting as client/server
234-
WiFi.mode(WIFI_STA);
235-
WiFi.begin(_ssid, _pass);
236-
_status = WS_NET_DISCONNECTED;
237-
delay(100);
237+
if (strlen(_ssid) == 0) {
238+
_status = WS_SSID_INVALID;
239+
} else {
240+
WiFi.setAutoReconnect(false);
241+
// Attempt connection
242+
_disconnect();
243+
delay(100);
244+
// ESP8266 MUST be in STA mode to avoid device acting as client/server
245+
WiFi.mode(WIFI_STA);
246+
WiFi.begin(_ssid, _pass);
247+
_status = WS_NET_DISCONNECTED;
248+
delay(100);
249+
250+
if (strlen(WS._multiNetworks[0].ssid) > 0) {
251+
// multi network mode
252+
for (int i = 0; i < 5; i++) {
253+
if (strlen(WS._multiNetworks[i].ssid) > 0 &&
254+
(_wifiMulti.existsAP(WS._multiNetworks[i].ssid) == false)) {
255+
// doesn't exist, add it
256+
_wifiMulti.addAP(WS._multiNetworks[i].ssid,
257+
WS._multiNetworks[i].pass);
258+
}
259+
}
260+
long startRetry = millis();
261+
WS_DEBUG_PRINTLN("CONNECTING");
262+
while (_wifiMulti.run(5000) != WL_CONNECTED && millis() - startRetry < 10000) {
263+
// ESP8266 WDT requires yield() during a busy-loop so it doesn't bite
264+
yield();
265+
}
266+
if (_wifiMulti.run(5000) == WL_CONNECTED) {
267+
_status = WS_NET_CONNECTED;
268+
} else {
269+
_status = WS_NET_DISCONNECTED;
270+
}
271+
} else {
272+
// single network mode
238273

239-
// wait for a connection to be established
240-
long startRetry = millis();
241-
WS_DEBUG_PRINTLN("CONNECTING");
242-
while (WiFi.status() != WL_CONNECTED && millis() - startRetry < 10000) {
243-
// ESP8266 WDT requires yield() during a busy-loop so it doesn't bite
244-
yield();
274+
// wait for a connection to be established
275+
long startRetry = millis();
276+
WS_DEBUG_PRINTLN("CONNECTING");
277+
while (WiFi.status() != WL_CONNECTED && millis() - startRetry < 10000) {
278+
// ESP8266 WDT requires yield() during a busy-loop so it doesn't bite
279+
yield();
280+
}
281+
if (WiFi.status() == WL_CONNECTED) {
282+
_status = WS_NET_CONNECTED;
283+
} else {
284+
_status = WS_NET_DISCONNECTED;
285+
}
286+
}
287+
WS.feedWDT();
245288
}
246289
}
247290

src/network_interfaces/ws_networking_pico.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ class ws_networking_pico : public Wippersnapper {
4343
_ssid = 0;
4444
_pass = 0;
4545
_mqtt_client = new WiFiClientSecure;
46-
WiFi.noLowPowerMode();
47-
WiFi.persistent(false);
48-
_wifiMulti.clearAPList();
46+
// WiFi.persistent(false);
47+
// _wifiMulti.clearAPList();
4948
}
5049

5150
/**************************************************************************/
@@ -283,6 +282,7 @@ class ws_networking_pico : public Wippersnapper {
283282
WS.feedWDT();
284283
if (strlen(WS._multiNetworks[0].ssid) > 0) {
285284
// multi network mode
285+
_wifiMulti.clearAPList();
286286
for (int i = 0; i < 5; i++) {
287287
_wifiMulti.addAP(WS._multiNetworks[i].ssid,
288288
WS._multiNetworks[i].pass);

0 commit comments

Comments
 (0)