Testing credentials during setup?

Hi
on my ESP devices I frequently have the problem that something in the credentials does not match.
In that case my device get stuck on
thing.handle();
and is unresponsive.

Have we a way to test the device credentials during setup and issue a message if there is no match?

That would greatly improve my workflow.

Thank you.

Hi,

I think the state listener may be useful for you

      thing.set_state_listener([&](ThingerClient::THINGER_STATE state)
                                  {
          switch (state)
          {
          case ThingerClient::NETWORK_CONNECTING:
            break;
          case ThingerClient::NETWORK_CONNECTED:
            break;
          case ThingerClient::NETWORK_CONNECT_ERROR:
             break;
          case ThingerClient::SOCKET_CONNECTING:
            break;
          case ThingerClient::SOCKET_CONNECTED:
            break;
          case ThingerClient::SOCKET_CONNECTION_ERROR:
            break;
          case ThingerClient::SOCKET_DISCONNECTED:
            break;
          case ThingerClient::SOCKET_ERROR:
            break;
          case ThingerClient::SOCKET_TIMEOUT:
            break;
          case ThingerClient::THINGER_AUTHENTICATING:
            break;
          case ThingerClient::THINGER_AUTHENTICATED:
            break;
          case ThingerClient::THINGER_AUTH_FAILED:
            break;
          case ThingerClient::THINGER_STOP_REQUEST:
            break;
          } });
    }

You just need to decide what the device should do when it gets in any of those cases.

Hope this helps.

1 Like

Thank you !

THINGER_AUTH_FAILED

is at device level, right?

Hi,

Yes, the device is able to identify an authentication failure connection error.

Hope this helps.

Oh I am sorry that I forget to mention where to put the code,

The state listener should be put into the void setup(); function.

Hope this helps.

Hi,

I have put two parts of the listener in my code.

During Setup, I check

:THINGER_AUTH_FAILED: and :SOCKET_CONNECTED:

and in loop() I check

:SOCKET_DISCONNECTED: and :SOCKET_CONNECTION_ERROR:

If an error is detected, I set a variable GracePause to 5.
The thing.handle(); is paused until GracePause (which is decreased every second) reaches 0.

So, when I get a connection Problem with thinger.io the device keeps being responsive.

Hi,

No need to put into loop, at the setup you just establish what the device will do in any of the cases, declaring it into loop is like establishing, each loop, what will do, the device will detect and run instructions stablished into the setup.

Hope this helps.

1 Like

But I live in internet-underdeveloped Germany and my connection is wonky with frequent interruptions lasting a few, seconds, minutes or longer.
Then my measuring device gets blocked in a loop trying to reach thinger.io.

There is a 1S timeout, but then it tries immediately again, blocking effectively all processing.
That is the very reason to check periodically if Thinger can still be reached.
If not, pausing the
thing.handle();
for 5 seconds permits to keep my device halfway responsive.
That has saved my measurements many times.

OK, you tell me to place the periodical check in setup() too?
Thinger.io is confusing by placing looped code onto setup().
But Ok, you are the expert.
so now my code in setup() is:

  thing.set_state_listener([&](ThingerClient::THINGER_STATE state) 
  {
    switch (state) {
      case ThingerClient::THINGER_AUTHENTICATED:
        Serial.print("\nThinger Auth OK");
        break;
      case ThingerClient::THINGER_AUTH_FAILED:
        Serial.print("\n***Thinger Auth Fail***");
        break;
      case ThingerClient::NETWORK_CONNECT_ERROR:
      case ThingerClient::SOCKET_CONNECTION_ERROR:
      case ThingerClient::SOCKET_DISCONNECTED:
      case ThingerClient::SOCKET_ERROR:
      case ThingerClient::SOCKET_TIMEOUT:
        Console1.print("\n Network Error ! \n");
        GracePause = 64;
        break;
    }
  });

When GracePause is set to non-zero the processing of thing.handle() 8 times a second will stop until the countdown has finished.

I am curious, if I then get the error messages.

Regards.
Laszlo