Restart or Reboot on when device goes offline

I’ve a prototype running in a rural area where an Arduino mega based PLC detects rain and environmental parameters like Temperature and Humidity.

Sometimes ( every 5-6 days or so… ) goes offline and I need the simplest way to restart the board, is there any coding solution ? I prefer to keep installation clean, without relay or other devices.

My first idea is to add a device for temperature and humidity readings and the Arduino PLC will be used only for greenhouses motors

Any suggestion?

Thank you

TBH, the Mega is difficult device to work with effective in this type of situation.
If you use an Ethernet shield then they are notoriously problematic. If you use an ESP-01 as a WiFi modem then you have a very limited command set and your options are restricted regarding the non-blocking Blynk connection possibilities.

An ESP8266 or ESP32 based solution gives more possibilities, but I still tend to use a hardware watchdog to reboot my remote devices if they stop responding.


@RDinformarica I’ve addressed the device-going-offline problem two ways.
Agreed with @PeteKnight, and have moved entirely to the WiFi-enabled ESP32 and ESP8266 devices.

Way One. In the code of the monitored ESP device, I periodically check to see if it’s connected to WiFi. If not, and after an appropriate waiting period, I reboot the device from its own code. This is good as long as the device, itself, remains powered. The device reboots, tries to connect to WiFi, and reboots again after a time if it cannot connect. The only drawback here is that you never know the device is offline. Only the device knows. I have not attempted to use the Blynk notification to do anything when a device goes offline.

Way Two. I have the device I’m monitoring do routine ‘check-ins’ with my watchdog device. I use periodic HTTP ‘update’ calls from the devices being monitored to a Blynk datastream on the watchdog device. When the watchdog’s Blynk datastream gets hit, BLYNK_WRITE gets called and I reset the clock. The watchdog periodically checks to see how long since the last ‘check-in’ from each monitored device and takes action with too much time is elapsed. Usually, it’s as simple as sending me a notification or coloring a Blynk widget red.

On one of my systems, however, I have a WiFi switch (SONOFF or Shelly) powering the monitored device. On a fatal error, the watchdog turns the device’s power switch off, then on again after 60 seconds for a ‘cold’ reboot of the monitored device.

If helpful, I will publish my code for doing an HTTP ‘update’ to a remote Blynk device’s datastream. I use this code for communicating among Blynk devices all the time.

Hope this is helpful. .

thanks for your reply.
Can you share an example code please?