(ESP32) trigger something if the connexion to thingerIO is lost

Hi guys,

Basically i’m controlling a relay thanks to ThingerIO and an ESP32 and i want to make sure that if the connexion to ThingerIO and/or to Internet is lost the relay will eventually turn off (if it was on).
The thread bellow:

already discuss that topic but, correct me if i’m wrong, the solutions mentioned, are based on the fact that the ESP32’s wifi is connected to the AP… This is “unsafe” in my point of view because you can have a valid wifi connection to an AP that lost the Internet.

What would be the best approach to tackle that in your opinion?
I have red plenty of generic topics about that presenting different solutions (ping a website every x minutes / call a DNS server to have an address resolved …)
… but i’m wondering if there is not a solution “thingerIO centered” like an error raised if the ESP32<–>ThingerIO communication is broken for a certain time.

Thank you !

Here is the code i use for now

#define THINGER_SERIAL_DEBUG

#include <ThingerESP32.h>
#include “arduino_secrets.h”

ThingerESP32 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void setup() {
// open serial for debugging
Serial.begin(115200);
pinMode(26 , OUTPUT);
digitalWrite(26,HIGH);
thing.add_wifi(SSID, SSID_PASSWORD);

thing[“GPIO2”] << [](pson& in){
if(in.is_empty()){
in = !(bool) digitalRead(26);
}
else{
digitalWrite(26, in ? LOW : HIGH);
}
};
}

void loop() {
thing.handle();
}

Hi,

I would use this —> CODING GUIDE - Thinger.io Documentation

Any state different from THINGER_AUTHENTICATED may trigger the ‘no connection routine’

Hope this helps.