Skip to content

Commit 32a7248

Browse files
committed
remove TEST_STORED_CONFIG state of NetworkConfigurator
1 parent 0e1e80c commit 32a7248

File tree

3 files changed

+15
-60
lines changed

3 files changed

+15
-60
lines changed

examples/provisioning/provisioning.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ void setup() {
129129
NetworkConfigurator.resetStoredConfiguration();
130130
}
131131

132-
NetworkConfigurator.setCheckStoredCred(false);
133132
NetworkConfigurator.updateNetworkOptions();
134133
NetworkConfigurator.begin();
135134
ClaimingHandler.begin(&secureElement, &uhwid, clearStoredCredentials);

src/NetworkConfigurator.cpp

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,16 @@
3030
#endif
3131
constexpr char *STORAGE_KEY{ "NETWORK_CONFIGS" };
3232

33-
NetworkConfiguratorClass::NetworkConfiguratorClass(AgentsManagerClass &agentManager, ConnectionHandler &connectionHandler, bool startConfigurationIfConnectionFails)
33+
NetworkConfiguratorClass::NetworkConfiguratorClass(AgentsManagerClass &agentManager, ConnectionHandler &connectionHandler)
3434
: _agentManager{ &agentManager },
3535
_connectionHandler{ &connectionHandler },
36-
_startBLEIfConnectionFails{ startConfigurationIfConnectionFails },
3736
_connectionTimeout{ NC_CONNECTION_TIMEOUT_ms, NC_CONNECTION_TIMEOUT_ms },
3837
_connectionRetryTimer{ NC_CONNECTION_RETRY_TIMER_ms, NC_CONNECTION_RETRY_TIMER_ms },
3938
_optionUpdateTimer{ NC_UPDATE_NETWORK_OPTIONS_TIMER_ms, NC_UPDATE_NETWORK_OPTIONS_TIMER_ms } {
4039
_optionUpdateTimer.begin(NC_UPDATE_NETWORK_OPTIONS_TIMER_ms); //initialize the timer before calling begin
4140
}
4241

4342
bool NetworkConfiguratorClass::begin() {
44-
_connectionLostStatus = false;
4543
_state = NetworkConfiguratorStates::READ_STORED_CONFIG;
4644
memset(&_networkSetting, 0x00, sizeof(models::NetworkSetting));
4745

@@ -95,15 +93,14 @@ NetworkConfiguratorStates NetworkConfiguratorClass::poll() {
9593
NetworkConfiguratorStates nextState = _state;
9694
switch (_state) {
9795
#ifdef BOARD_HAS_ETHERNET
98-
case NetworkConfiguratorStates::CHECK_ETH: nextState = handleCheckEth (); break;
96+
case NetworkConfiguratorStates::CHECK_ETH: nextState = handleCheckEth (); break;
9997
#endif
100-
case NetworkConfiguratorStates::READ_STORED_CONFIG: nextState = handleReadStorage (); break;
101-
case NetworkConfiguratorStates::TEST_STORED_CONFIG: nextState = handleTestStoredConfig(); break;
102-
case NetworkConfiguratorStates::WAITING_FOR_CONFIG: nextState = handleWaitingForConf (); break;
103-
case NetworkConfiguratorStates::CONNECTING: nextState = handleConnecting (); break;
104-
case NetworkConfiguratorStates::CONFIGURED: nextState = handleConfigured (); break;
105-
case NetworkConfiguratorStates::UPDATING_CONFIG: nextState = handleUpdatingConfig (); break;
106-
case NetworkConfiguratorStates::END: break;
98+
case NetworkConfiguratorStates::READ_STORED_CONFIG: nextState = handleReadStorage (); break;
99+
case NetworkConfiguratorStates::WAITING_FOR_CONFIG: nextState = handleWaitingForConf(); break;
100+
case NetworkConfiguratorStates::CONNECTING: nextState = handleConnecting (); break;
101+
case NetworkConfiguratorStates::CONFIGURED: nextState = handleConfigured (); break;
102+
case NetworkConfiguratorStates::UPDATING_CONFIG: nextState = handleUpdatingConfig(); break;
103+
case NetworkConfiguratorStates::END: break;
107104
}
108105

109106
if(_state != nextState){
@@ -292,6 +289,7 @@ void NetworkConfiguratorClass::connectReqHandler() {
292289

293290
void NetworkConfiguratorClass::setNetworkSettingsHandler(models::NetworkSetting *netSetting) {
294291
memcpy(&_networkSetting, netSetting, sizeof(models::NetworkSetting));
292+
printNetworkSettings();
295293
_receivedEvent = NetworkConfiguratorEvents::NEW_NETWORK_SETTINGS;
296294
}
297295

@@ -343,11 +341,6 @@ NetworkConfiguratorStates NetworkConfiguratorClass::handleConnectRequest() {
343341
return nextState;
344342
}
345343

346-
void NetworkConfiguratorClass::handleNewNetworkSettings() {
347-
printNetworkSettings();
348-
_connectionLostStatus = false; //reset for updating the failure reason
349-
}
350-
351344
String NetworkConfiguratorClass::decodeConnectionErrorMessage(NetworkConnectionState err, StatusMessage *errorCode) {
352345
switch (err) {
353346
case NetworkConnectionState::ERROR:
@@ -418,11 +411,7 @@ NetworkConfiguratorStates NetworkConfiguratorClass::handleReadStorage() {
418411
nextState = NetworkConfiguratorStates::WAITING_FOR_CONFIG;
419412
} else {
420413
_connectionHandlerIstantiated = true;
421-
if (_checkStoredCred){
422-
nextState = NetworkConfiguratorStates::TEST_STORED_CONFIG;
423-
} else {
424-
nextState = NetworkConfiguratorStates::CONFIGURED;
425-
}
414+
nextState = NetworkConfiguratorStates::CONFIGURED;
426415
}
427416

428417
} else {
@@ -439,26 +428,6 @@ NetworkConfiguratorStates NetworkConfiguratorClass::handleReadStorage() {
439428
return nextState;
440429
}
441430

442-
NetworkConfiguratorStates NetworkConfiguratorClass::handleTestStoredConfig() {
443-
NetworkConfiguratorStates nextState = _state;
444-
StatusMessage err;
445-
ConnectionResult res = connectToNetwork(&err);
446-
if (res == ConnectionResult::SUCCESS) {
447-
nextState = NetworkConfiguratorStates::CONFIGURED;
448-
} else if (res == ConnectionResult::FAILED) {
449-
sendStatus(StatusMessage::CONNECTION_LOST);
450-
_connectionLostStatus = true;
451-
if (_startBLEIfConnectionFails) {
452-
_agentManager->enableBLEAgent(true);
453-
}
454-
if(_optionUpdateTimer.getWaitTime() == 0) {
455-
updateNetworkOptions();
456-
}
457-
nextState = NetworkConfiguratorStates::WAITING_FOR_CONFIG;
458-
}
459-
return nextState;
460-
}
461-
462431
NetworkConfiguratorStates NetworkConfiguratorClass::handleWaitingForConf() {
463432
NetworkConfiguratorStates nextState = _state;
464433

@@ -467,8 +436,8 @@ NetworkConfiguratorStates NetworkConfiguratorClass::handleWaitingForConf() {
467436
switch (_receivedEvent) {
468437
case NetworkConfiguratorEvents::SCAN_REQ: updateNetworkOptions (); break;
469438
case NetworkConfiguratorEvents::CONNECT_REQ: nextState = handleConnectRequest (); break;
470-
case NetworkConfiguratorEvents::NEW_NETWORK_SETTINGS: handleNewNetworkSettings(); break;
471439
case NetworkConfiguratorEvents::GET_WIFI_FW_VERSION: handleGetWiFiFWVersion (); break;
440+
case NetworkConfiguratorEvents::NEW_NETWORK_SETTINGS: break;
472441
}
473442
_receivedEvent = NetworkConfiguratorEvents::NONE;
474443
if (nextState == _state) {
@@ -495,9 +464,7 @@ NetworkConfiguratorStates NetworkConfiguratorClass::handleConnecting() {
495464
if (res == ConnectionResult::SUCCESS) {
496465
nextState = NetworkConfiguratorStates::CONFIGURED;
497466
} else if (res == ConnectionResult::FAILED) {
498-
if (!_connectionLostStatus) {
499-
sendStatus(err);
500-
}
467+
sendStatus(err);
501468
nextState = NetworkConfiguratorStates::WAITING_FOR_CONFIG;
502469
}
503470

src/NetworkConfigurator.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
enum class NetworkConfiguratorStates { CHECK_ETH,
1717
READ_STORED_CONFIG,
18-
TEST_STORED_CONFIG,
1918
WAITING_FOR_CONFIG,
2019
CONNECTING,
2120
CONFIGURED,
@@ -24,15 +23,9 @@ enum class NetworkConfiguratorStates { CHECK_ETH,
2423

2524
class NetworkConfiguratorClass {
2625
public:
27-
NetworkConfiguratorClass(AgentsManagerClass &agentManager, ConnectionHandler &connectionHandler, bool startBLEIfConnectionFails = false);
26+
NetworkConfiguratorClass(AgentsManagerClass &agentManager, ConnectionHandler &connectionHandler);
2827
bool begin();
2928
NetworkConfiguratorStates poll();
30-
void startBLEIfConnectionFails(bool enable) {
31-
_startBLEIfConnectionFails = enable;
32-
};
33-
void setCheckStoredCred(bool check) {
34-
_checkStoredCred = check;
35-
};
3629
bool resetStoredConfiguration();
3730
bool end();
3831
bool updateNetworkOptions();
@@ -41,13 +34,11 @@ class NetworkConfiguratorClass {
4134
AgentsManagerClass *_agentManager;
4235
ConnectionHandler *_connectionHandler;
4336
static inline models::NetworkSetting _networkSetting;
44-
bool _startBLEIfConnectionFails;
4537
bool _connectionHandlerIstantiated = false;
46-
bool _checkStoredCred = true;
4738
TimedAttempt _connectionTimeout;
4839
TimedAttempt _connectionRetryTimer;
4940
TimedAttempt _optionUpdateTimer;
50-
bool _connectionLostStatus = false;
41+
5142
enum class NetworkConfiguratorEvents { NONE,
5243
SCAN_REQ,
5344
CONNECT_REQ,
@@ -63,21 +54,19 @@ class NetworkConfiguratorClass {
6354
NetworkConfiguratorStates handleCheckEth();
6455
#endif
6556
NetworkConfiguratorStates handleReadStorage();
66-
NetworkConfiguratorStates handleTestStoredConfig();
6757
NetworkConfiguratorStates handleWaitingForConf();
6858
NetworkConfiguratorStates handleConnecting();
6959
NetworkConfiguratorStates handleConfigured();
7060
NetworkConfiguratorStates handleUpdatingConfig();
7161

7262
NetworkConfiguratorStates handleConnectRequest();
73-
void handleNewNetworkSettings();
7463
void handleGetWiFiFWVersion();
7564

7665
String decodeConnectionErrorMessage(NetworkConnectionState err, StatusMessage *errorCode);
7766
ConnectionResult connectToNetwork(StatusMessage *err);
7867
ConnectionResult disconnectFromNetwork();
7968
bool sendStatus(StatusMessage msg);
80-
void printNetworkSettings();
69+
static void printNetworkSettings();
8170
#ifdef BOARD_HAS_WIFI
8271
bool scanWiFiNetworks(WiFiOption &wifiOptObj);
8372
bool insertWiFiAP(WiFiOption &wifiOptObj, char *ssid, int rssi);

0 commit comments

Comments
 (0)