Babysitting my dashboard

Ok so this is a weird one maybe.
I have node red running on a raspberry pi at my brewery.
I just had an instant where the pi lost connection with router and i could no longer see it remotely.
is there a way to check the external connection ip and if there is no response i can send a reboot command to the pi itself?
am i wasting my time trying to do that.
obviously im planning on setting up dashboard on web server. and the communication needs to happen or the webserver will be blank
right now im just port fowarding to my pi. which i know isnt secure but it is what i have to i complete better solution.

When you pi loses the connection to the internet it is useless sending any remote command as it will not reach the pi. When the connectivy is restored there should be no need to command a restart as it should be readilly available again.

Perhaps you want the pi sensing internet disconnecting and generating an auto-restart ?

well for some reason the pi disconnected from router. and was having issues.
it took rebooting the pi to correct the issue.
so rebooting the pi when it looses connection. this disruption will also cause a problem with my mqtt and temp controls. so a reboot is needed ,
or maybe a script to turn off and turn the wifi back on on the pi itself since that was the issue.

You can have Node-red on the Pi monitor the connection - eg ping the gateway, ping etc - and reboot if it's not connected.

Probably better is the Pi's hardware watchdog which can reboot it if connectivity is lost (or other circumstances)


And the rabbit hole appears !!

You have to decide how far down this you want to go and what you are worried about making allowances for.

But yes if you are using a system like this then you need to work out what problems you are going to cater for and then how to handle them.

My system runs as a virtual machine so it is slightly different - but i have a number of different safeguards in place - some of which run on the Virtual machine - others on other machines and some even on Power plugs.

For instance in the case of losing internet connection the power plug that controls my router will go into a countdown and do a reboot of the router every 5 minutes until the internet is back and running etc


I almost just pm'd you on this but figured that would be your response. lol!
so the issue is , when the my private network goes down or for somereason the pi looses connection thats the biggest issue.

  1. all my esp8266's need that network to message my mqtt server.
  2. yes I want the internet working so i can do things remotely, however the internal network is crucial to thingks working properly. I E, temperatures reporting to mqtt. and then mqtt telling valves to open or close depending on the temp status.

so yes i need the pi to verify at least its ip address if its not the correct ip i need it to turn off wifi and turn back on so all my other devices can reach the mqtt server.

and to really clarify this is not my rabbit hole, just a fork in the rabbit hole im already in!

Sorry, off-topic question: Can you explain how that works @craigcurtin? I considered using a smart socket to turn off my router in the small hours, but when it's off there is no wifi so I can't tell the socket to turn back on.

Depends on the socket / firmware - If flashed with tasmota for example then you can setup rules and schedules etc on the socket itself.

1 Like

@jbudd - as @smcgann99 has said - dependant on firmware - in my case i flash all my stuff with tasmota - so i can use its inbuilt timers to initiate actions at a certain time (like turning your wifi back on)

You can also use the tasmota Backlog (essentially a scripting language) facility to automate a range of things to happen directly on the plug

Lastly with the newer ESP32 implementations they have released a totally new scripting language that i will be starting to explore.

Here is an example


1 Like

There is a ping node I use to ping an IP every 5 minutes, if I don't get a response then I reboot the PI. Also. The Pi generates a heartbeat (MQTT) my nodemcu's look for. If they miss 20 heartbeats they reboot.
[EDIT] sometimes my router will change IP's as it is a dynamic setting so I have my pi email me the outside IP of the router so I know how to connect

So i don't think i really need to reboot pi, but turn the wifi off and then back on it was the only device that had an issue with the private network.

Probably easier just to reboot it.

1 Like

This' my script which is loaded at boot. It reboots the Rpi if pingging Google fails. If you don't want to use "reboot", just issue a "network restart" but it's best to reboot. However, "network restart" may solve the issue with the router.

# #

import os
import time
import requests as req

url = ""
count = 0

def ping_url():
    global count
        r = req.get(url)
        # print(r.status_code)
        if r.status_code !=
          # if not 200, reboot
          count += 1
          if count > 9:
            os.system("sudo reboot")
          # print("ok")
    except Exception as err:
        # print(err)
        count += 1
        if count > 9:
          os.system("sudo reboot")

oldtime = 0
timer = 60 # delay in seconds

if __name__ == "__main__":
    while True:
      if time.time() - oldtime > timer:
        oldtime = time.time()
1 Like

I once had a Pi that did that but none of my other 2 Pi's ever had that issue. They always managed to reconnect. Maybe try a clean OS build?

A note of caution - given the recent hacking incidents. If you are using something to reboot your server, you should of course ensure that nothing can execute that from the Internet.

Yes , totally understand that, i still need to figure out the safety in the network side of things, been a little slow on messing with system as of late, the vfw post in town needed signs for there new location so I've been busy making those. Just got these 2 cut out this morning


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.