Skip to content

Commit b13a37f

Browse files
authored
Merge pull request #32 from arduino-libraries/revert-28-connection-manager
Revert "Managed exit cases for IOT_STATUS_CLOUD_CONNECTED, removed unused states"
2 parents b4dd987 + c1ed078 commit b13a37f

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/ArduinoIoTCloud.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,15 @@ void ArduinoIoTCloudClass::handleMessage(int length)
282282
}
283283

284284
void ArduinoIoTCloudClass::connectionCheck() {
285-
if(connection != NULL) {
285+
if(connection != NULL){
286286
connection->check();
287+
287288
if (connection->getStatus() != CONNECTION_STATE_CONNECTED) {
288-
if (iotStatus == IOT_STATUS_CLOUD_CONNECTED)
289-
setIoTConnectionState(IOT_STATUS_CLOUD_RECONNECTING);
289+
if(iotStatus == IOT_STATUS_CLOUD_CONNECTED){
290+
setIoTConnectionState(IOT_STATUS_CLOUD_DISCONNECTED);
291+
}else{
292+
//setIoTConnectionState(IOT_STATUS_CLOUD_CONNECTING);
293+
}
290294
return;
291295
}
292296
}
@@ -295,7 +299,7 @@ void ArduinoIoTCloudClass::connectionCheck() {
295299

296300

297301
switch (iotStatus) {
298-
case IOT_STATUS_CLOUD_IDLE:
302+
case IOT_STATUS_IDLE:
299303
{
300304
int connectionAttempt;
301305
if(connection == NULL){
@@ -310,15 +314,17 @@ void ArduinoIoTCloudClass::connectionCheck() {
310314
}
311315
setIoTConnectionState(IOT_STATUS_CLOUD_CONNECTING);
312316
break;
313-
}
317+
}
318+
314319
case IOT_STATUS_CLOUD_ERROR:
315320
debugMessage("Cloud Error. Retrying...", 0);
316321
setIoTConnectionState(IOT_STATUS_CLOUD_RECONNECTING);
317322
break;
318323
case IOT_STATUS_CLOUD_CONNECTED:
319324
debugMessage(".", 4, false, true);
320-
if (!_mqttClient->connected())
321-
setIoTConnectionState(IOT_STATUS_CLOUD_RECONNECTING);
325+
break;
326+
case IOT_STATUS_CLOUD_DISCONNECTED:
327+
setIoTConnectionState(IOT_STATUS_CLOUD_RECONNECTING);
322328
break;
323329
case IOT_STATUS_CLOUD_RECONNECTING:
324330
int arduinoIoTReconnectionAttempt;

src/ArduinoIoTCloud.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ typedef struct {
2424
extern ConnectionManager *ArduinoIoTPreferredConnection;
2525

2626
enum ArduinoIoTConnectionStatus {
27+
IOT_STATUS_IDLE,/* only at start */
2728
IOT_STATUS_CLOUD_IDLE,
2829
IOT_STATUS_CLOUD_CONNECTING,
2930
IOT_STATUS_CLOUD_CONNECTED,
3031
IOT_STATUS_CLOUD_DISCONNECTED,
3132
IOT_STATUS_CLOUD_RECONNECTING,
32-
IOT_STATUS_CLOUD_ERROR
33+
IOT_STATUS_CLOUD_ERROR,
34+
IOT_STATUS_ERROR_GENERIC
3335
};
3436

3537
class ArduinoIoTCloudClass {
@@ -104,7 +106,7 @@ class ArduinoIoTCloudClass {
104106
ArduinoIoTConnectionStatus getIoTStatus() { return iotStatus; }
105107
void setIoTConnectionState(ArduinoIoTConnectionStatus _newState);
106108
private:
107-
ArduinoIoTConnectionStatus iotStatus = IOT_STATUS_CLOUD_IDLE;
109+
ArduinoIoTConnectionStatus iotStatus = IOT_STATUS_IDLE;
108110
ConnectionManager *connection;
109111
static void onMessage(int length);
110112
void handleMessage(int length);

0 commit comments

Comments
 (0)