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?
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.
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.
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.