Skip to content

Commit 9626567

Browse files
committed
- handled some compilation errors for ESP12/32
- nicer messages on manual disconnection - Example: resolved an issue which would trigger WDT on ESP12 because `!Serial` was used
1 parent 213b74b commit 9626567

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

Arduino_ConnectionHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class ConnectionHandler {
114114
#define NETWORK_CONNECTED GSM3_NetworkStatus_t::GPRS_READY
115115
#endif
116116

117-
#if defined(ARDUINO_ESP8266_ESP12) || defined(ARDUINO_ARCH_ESP32)
117+
#if defined(ARDUINO_ESP8266_ESP12) || defined(ARDUINO_ARCH_ESP32) || defined(ESP8266)
118118
#ifdef ARDUINO_ESP8266_ESP12
119119
#include <ESP8266WiFi.h>
120120

Arduino_WiFiConnectionHandler.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,16 @@ WiFiConnectionHandler::WiFiConnectionHandler(const char *_ssid, const char *_pas
5151
void WiFiConnectionHandler::init() {
5252
}
5353

54+
// INIT, CONNECTING, CONNECTED, DISCONNECTING, DISCONNECTED, CLOSED, ERROR
5455
void WiFiConnectionHandler::addCallback(NetworkConnectionEvent const event, OnNetworkEventCallback callback){
5556
switch (event) {
5657
case NetworkConnectionEvent::CONNECTED: _on_connect_event_callback = callback; break;
5758
case NetworkConnectionEvent::DISCONNECTED: _on_disconnect_event_callback = callback; break;
5859
case NetworkConnectionEvent::ERROR: _on_error_event_callback = callback; break;
60+
case NetworkConnectionEvent::INIT: ; break;
61+
case NetworkConnectionEvent::CONNECTING: ; break;
62+
case NetworkConnectionEvent::DISCONNECTING: ; break;
63+
case NetworkConnectionEvent::CLOSED: ; break;
5964
}
6065
}
6166

@@ -92,7 +97,7 @@ void WiFiConnectionHandler::update() {
9297
switch (netConnectionState) {
9398
case NetworkConnectionState::INIT: {
9499
debugMessage(DebugLevel::Verbose, "::INIT");
95-
#if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32)
100+
#if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32) && !defined(ESP8266)
96101
networkStatus = WiFi.status();
97102

98103
debugMessage(DebugLevel::Info, "WiFi.status(): %d", networkStatus);
@@ -111,7 +116,9 @@ void WiFiConnectionHandler::update() {
111116
#else
112117
debugMessage(DebugLevel::Error, "WiFi status ESP: %d", WiFi.status());
113118
WiFi.disconnect();
119+
delay(300);
114120
networkStatus = WiFi.begin(ssid, pass);
121+
delay(1000);
115122
#endif
116123

117124
changeConnectionState(NetworkConnectionState::CONNECTING);
@@ -121,7 +128,7 @@ void WiFiConnectionHandler::update() {
121128
debugMessage(DebugLevel::Verbose, "::CONNECTING");
122129
networkStatus = WiFi.status();
123130

124-
#if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32)
131+
#if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32) && !defined(ESP8266)
125132

126133
if (networkStatus != WL_CONNECTED) {
127134
networkStatus = WiFi.begin(ssid, pass);
@@ -168,7 +175,7 @@ void WiFiConnectionHandler::update() {
168175
}
169176
break;
170177
case NetworkConnectionState::DISCONNECTED: {
171-
#if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32)
178+
#if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32) && !defined(ESP8266)
172179
WiFi.end();
173180
#endif
174181
if (keepAlive) {
@@ -229,13 +236,16 @@ void WiFiConnectionHandler::changeConnectionState(NetworkConnectionState _newSta
229236
debugMessage(DebugLevel::Verbose, "WiFi.status(): %d", WiFi.status());
230237

231238
debugMessage(DebugLevel::Error, "Connection to \"%s\" lost.", ssid);
232-
debugMessage(DebugLevel::Error, "Attempting reconnection");
239+
if(keepAlive){
240+
debugMessage(DebugLevel::Error, "Attempting reconnection");
241+
}
242+
233243
newInterval = CHECK_INTERVAL_DISCONNECTED;
234244
}
235245
break;
236246
case NetworkConnectionState::CLOSED: {
237247

238-
#if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32)
248+
#if !defined(ARDUINO_ESP8266_ESP12) && !defined(ARDUINO_ARCH_ESP32) && !defined(ESP8266)
239249
WiFi.end();
240250
#endif
241251

Arduino_WiFiConnectionHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "Arduino_ConnectionHandler.h"
2626

2727
#ifdef BOARD_HAS_WIFI /* Only compile if the board has WiFi */
28-
28+
#pragma message("Board has wifi")
2929
extern void connectionStateChanged(NetworkConnectionState _newState);
3030

3131

examples/ConnectionHandlerDev/ConnectionHandlerDev.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ FTDebouncer deb;
1515
void setup(){
1616
Serial.begin(9600);
1717
unsigned long serialBeginTime = millis();
18-
while(millis() - serialBeginTime < 4000 || !Serial){}
18+
//while(millis() - serialBeginTime < 4000 || !Serial){}
19+
delay(4000);
1920
setDebugMessageLevel(4);
2021
deb.addPin(PIN_CONNECT, HIGH, INPUT_PULLUP);
2122
deb.addPin(PIN_DISCONNECT, HIGH, INPUT_PULLUP);

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ sentence=Arduino Library for network connection management (WiFi, GSM, Ethernet)
66
paragraph=Originally part of ArduinoIoTCloud
77
category=Communication
88
url=https://github.com/arduino-libraries/Arduino_ConnectionHandler
9-
architectures=SAMD,ESP12,ESP32
9+
architectures=SAMD,ESP12,ESP32,esp8266

0 commit comments

Comments
 (0)