Skip to content

Commit 0e1e80c

Browse files
committed
Support check internet availability (#28)
1 parent fd2c854 commit 0e1e80c

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

.github/workflows/compile-examples.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@ jobs:
2929
# Install the NetworkConfigurator library from the repository
3030
- source-path: ./
3131
- name: Arduino_DebugUtils
32-
- source-url: https://github.com/andreagilardoni/Arduino_ConnectionHandler.git
33-
version: 0ca6d61eb538c5a21983e582ee1c8794442f8c75
32+
- source-url: https://github.com/fabik111/Arduino_ConnectionHandler.git
33+
version: 228ac355a957d60e1e06276ec12fe75598b09759
3434
- source-url: https://github.com/fabik111/ArduinoBLE.git
3535
version: 82e2a28f871e97b313846cee6d9efed8943dca53
3636
- source-url: https://github.com/andreagilardoni/ArduinoIoTCloud.git
3737
version: a4e171a058175f9615017bbf1e103663858a9610
3838
- name: Arduino_SecureElement
3939
- source-url: https://github.com/arduino-libraries/Arduino_CloudUtils.git
4040
- source-url: https://github.com/andreagilardoni/ArduinoStorage.git
41-
version: 39f0bd138103967aaafcaa7f5c0e1e237b4ccb4d
4241
- name: ArduinoJson
4342
- source-url: https://github.com/arduino-libraries/Arduino_UniqueHWId.git
4443
version: 8977827eed86dbd25292f861ee8de2b19c16b3a0

src/ConfiguratorAgents/MessagesDefinitions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ enum class StatusMessage {
2727
INVALID_PARAMS = -5,
2828
OTHER_REQUEST_IN_EXECUTION = -6,
2929
INVALID_REQUEST = -7,
30+
INTERNET_NOT_AVAILABLE = -8,
3031
SCAN_DISABLED_CONNECTING = -100,
3132
HW_ERROR_CONN_MODULE = -101,
32-
WIFI_IDLE = -102,
33-
WIFI_STOPPED = -103,
33+
HW_CONN_MODULE_STOPPED = -102,
3434
ERROR_STORAGE_BEGIN = -200,
3535
ERROR = -255
3636
};

src/NetworkConfigurator.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,9 @@ NetworkConfiguratorClass::ConnectionResult NetworkConfiguratorClass::connectToNe
168168
WiFi.end();
169169
#endif
170170
#endif
171-
int errorCode;
172-
String errorMsg = decodeConnectionErrorMessage(connectionRes, &errorCode);
171+
String errorMsg = decodeConnectionErrorMessage(connectionRes, err);
173172
DEBUG_INFO("Connection fail: %s", errorMsg.c_str());
174-
*err = (StatusMessage)errorCode;
173+
175174
_connectionRetryTimer.reload();
176175
res = ConnectionResult::FAILED;
177176
}
@@ -349,28 +348,30 @@ void NetworkConfiguratorClass::handleNewNetworkSettings() {
349348
_connectionLostStatus = false; //reset for updating the failure reason
350349
}
351350

352-
String NetworkConfiguratorClass::decodeConnectionErrorMessage(NetworkConnectionState err, int *errorCode) {
351+
String NetworkConfiguratorClass::decodeConnectionErrorMessage(NetworkConnectionState err, StatusMessage *errorCode) {
353352
switch (err) {
354353
case NetworkConnectionState::ERROR:
355-
*errorCode = (int)StatusMessage::HW_ERROR_CONN_MODULE;
354+
*errorCode = StatusMessage::HW_ERROR_CONN_MODULE;
356355
return "HW error";
357356
case NetworkConnectionState::INIT:
358-
*errorCode = (int)StatusMessage::WIFI_IDLE;
359-
return "Peripheral in idle";
357+
//the connection handler doesn't have a state of "Fail to connect", in case of invalid credentials or
358+
//missing network configuration the FSM stays on Init state so use this state to detect the fail to connect
359+
*errorCode = StatusMessage::FAILED_TO_CONNECT;
360+
return "Failed to connect";
360361
case NetworkConnectionState::CLOSED:
361-
*errorCode = (int)StatusMessage::WIFI_STOPPED;
362+
*errorCode = StatusMessage::HW_CONN_MODULE_STOPPED;
362363
return "Peripheral stopped";
363364
case NetworkConnectionState::DISCONNECTED:
364-
*errorCode = (int)StatusMessage::DISCONNECTED;
365+
*errorCode = StatusMessage::DISCONNECTED;
365366
return "Disconnected";
366-
//the connection handler doesn't have a state of "Fail to connect", in case of invalid credentials or
367-
//missing wifi network the FSM stays on Connecting state so use the connecting state to detect the fail to connect
368367
case NetworkConnectionState::CONNECTING:
369-
*errorCode = (int)StatusMessage::FAILED_TO_CONNECT;
370-
return "failed to connect";
368+
//the connection handler doesn't have a state of "Internet not available", in case of it's impossible to reach internet
369+
//the FSM stays on Connecting state so use this state to detect if internet is not available
370+
*errorCode = StatusMessage::INTERNET_NOT_AVAILABLE;
371+
return "Internet not available";
371372
default:
372-
*errorCode = (int)StatusMessage::ERROR;
373-
return "generic error";
373+
*errorCode = StatusMessage::ERROR;
374+
return "Generic error";
374375
}
375376
}
376377

src/NetworkConfigurator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class NetworkConfiguratorClass {
7373
void handleNewNetworkSettings();
7474
void handleGetWiFiFWVersion();
7575

76-
String decodeConnectionErrorMessage(NetworkConnectionState err, int *errorCode);
76+
String decodeConnectionErrorMessage(NetworkConnectionState err, StatusMessage *errorCode);
7777
ConnectionResult connectToNetwork(StatusMessage *err);
7878
ConnectionResult disconnectFromNetwork();
7979
bool sendStatus(StatusMessage msg);

0 commit comments

Comments
 (0)