Skip to content

Managed exit cases for IOT_STATUS_CLOUD_CONNECTED, removed unused states #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/ArduinoIoTCloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,11 @@ void ArduinoIoTCloudClass::handleMessage(int length)
}

void ArduinoIoTCloudClass::connectionCheck() {
if(connection != NULL){
if(connection != NULL) {
connection->check();

if (connection->getStatus() != CONNECTION_STATE_CONNECTED) {
if(iotStatus == IOT_STATUS_CLOUD_CONNECTED){
setIoTConnectionState(IOT_STATUS_CLOUD_DISCONNECTED);
}else{
//setIoTConnectionState(IOT_STATUS_CLOUD_CONNECTING);
}
if (iotStatus == IOT_STATUS_CLOUD_CONNECTED)
setIoTConnectionState(IOT_STATUS_CLOUD_RECONNECTING);
return;
}
}
Expand All @@ -299,7 +295,7 @@ void ArduinoIoTCloudClass::connectionCheck() {


switch (iotStatus) {
case IOT_STATUS_IDLE:
case IOT_STATUS_CLOUD_IDLE:
{
int connectionAttempt;
if(connection == NULL){
Expand All @@ -314,17 +310,15 @@ void ArduinoIoTCloudClass::connectionCheck() {
}
setIoTConnectionState(IOT_STATUS_CLOUD_CONNECTING);
break;
}

}
case IOT_STATUS_CLOUD_ERROR:
debugMessage("Cloud Error. Retrying...", 0);
setIoTConnectionState(IOT_STATUS_CLOUD_RECONNECTING);
break;
case IOT_STATUS_CLOUD_CONNECTED:
debugMessage(".", 4, false, true);
break;
case IOT_STATUS_CLOUD_DISCONNECTED:
setIoTConnectionState(IOT_STATUS_CLOUD_RECONNECTING);
if (!_mqttClient->connected())
setIoTConnectionState(IOT_STATUS_CLOUD_RECONNECTING);
break;
case IOT_STATUS_CLOUD_RECONNECTING:
int arduinoIoTReconnectionAttempt;
Expand Down
6 changes: 2 additions & 4 deletions src/ArduinoIoTCloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ typedef struct {
extern ConnectionManager *ArduinoIoTPreferredConnection;

enum ArduinoIoTConnectionStatus {
IOT_STATUS_IDLE,/* only at start */
IOT_STATUS_CLOUD_IDLE,
IOT_STATUS_CLOUD_CONNECTING,
IOT_STATUS_CLOUD_CONNECTED,
IOT_STATUS_CLOUD_DISCONNECTED,
IOT_STATUS_CLOUD_RECONNECTING,
IOT_STATUS_CLOUD_ERROR,
IOT_STATUS_ERROR_GENERIC
IOT_STATUS_CLOUD_ERROR
};

class ArduinoIoTCloudClass {
Expand Down Expand Up @@ -106,7 +104,7 @@ class ArduinoIoTCloudClass {
ArduinoIoTConnectionStatus getIoTStatus() { return iotStatus; }
void setIoTConnectionState(ArduinoIoTConnectionStatus _newState);
private:
ArduinoIoTConnectionStatus iotStatus = IOT_STATUS_IDLE;
ArduinoIoTConnectionStatus iotStatus = IOT_STATUS_CLOUD_IDLE;
ConnectionManager *connection;
static void onMessage(int length);
void handleMessage(int length);
Expand Down