Check Cloud Connection on Arduino


#1

Dear together,

in Arduino IDE i want check if the network and cloud connection established.

Could you please tell me how i can realize that.

Best Regards
Marcel


#2

Hello @starlight1986,

There is a command that allows you print the status of the connection, it is documented here: http://docs.thinger.io/arduino/#coding-enabling-debug-output

Bascialy you only have to put #define _DEBUG_ before including Thigner.io library and open a Serial port to start showing all the connection trace.

Hope it helps!


#3

Hey jtrinc26,

thanks for your support. I want to get the status of the Network and/or Thinger-Server connection to check with an if request in the code.
Finaly depends on connection i wanna turn on/off a led, to see what happend.
Do you’ve a solution for that?

Regards Marcel


#4

Hi, the current solution relies on overriding a function defined in ThingerClient called thinger_state_listener, that provides information about any state inside thinger, like network connecting, thinger.io connection, etc.

Thus, you can extend your own class to provide such functionality, i.e., replace your thing definition (supposing you are using a ESP8266) with:

class ClientListener : public ThingerESP8266{
public:
    ClientListener(const char* user, const char* device, const char* device_credential) : 
      ThingerESP8266(user, device, device_credential){}
protected:
  virtual void thinger_state_listener(THINGER_STATE state){
    // call current implementation (debug)
    ThingerESP8266::thinger_state_listener(state);
    switch(state){
        case THINGER_AUTHENTICATED:
            // turn on your led
            break;
        default:
            // turn off your led
            break;
    }
  }
};

ClientListener thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

If you want to do something more advanced, for example, blink your led while connecting to the network, here you have all possible states:

    switch(state){
        case NETWORK_CONNECTING:
            break;
        case NETWORK_CONNECTED:
            break;
        case NETWORK_CONNECT_ERROR:
            break;
        case SOCKET_CONNECTING:
            break;
        case SOCKET_CONNECTED:
            break;
        case SOCKET_CONNECTION_ERROR:
            break;
        case SOCKET_DISCONNECTED:
            break;
        case SOCKET_TIMEOUT:
            break;
        case THINGER_AUTHENTICATING:
            break;
        case THINGER_AUTHENTICATED:
            break;
        case THINGER_AUTH_FAILED:
            break;
        case THINGER_STOP_REQUEST:
            break;
    }