How can I check for network device presence for a raspberry pi connected via WebioPi script?


#1

I have a raspberry Pi (actually2) on my network. One I connect ST to it by using a WebioPi script. the other I do not. Can anyone suggest a method for alerting me when they are offline? Especially the one that I am connecting to usint the Webiopi

Thanks


(Bryan) #2

#3

Are you trying to detect when they are offline or just when they are shut off? Because if you are trying to detect when they are offline, well, you won’t be able to do that because anything on your network also will be offline and unable to tell the ST cloud that it’s offline. However, you should get a notification from the ST app on your phone if your hub goes offline. You can assume that if your hub is offline (internet down) then so are your raspberry pi’s.
If you are trying to tell when your pi is shut down, that you can do through the serial output channel. If you enable serial GPIO in raspi-config, that will turn on the UART GPIO pins. You can then either connect a relay/contact sensor or an LED to pins 8 (txd) and 6 (ground) and can tell then detect when the Pi is running. The LED will be lit only when the pi is running. I had a little trouble with the relay, since the flow is so low, so I hooked an LED and a photo-diode all shrink wrapped up so that it wouldn’t be affected by outside light. The photo-diode is then connected to an ESP8266 module (ESP01) that i run a ST_Anything program on. I even power the setup with the Pi, since the 3v pins are still hot even if the Pi is shut down.
I can get into a lot more detail if you’re interested or if you’re not quite getting what i’m saying.


(Ray) #4

(Jake) #5

You could use the host pinger script as provided above, but you will need a another device to run the polling, this could be another Pi a computer or an ESP8255/arduino type board…

Or depending on your technical knowledge of writing code, another alternative is to have the Pi send a post request to ST every minute or so, and ST have a timer set for just over minute at the end of the timer a notification is sent… so if the Pi posts to ST then the timer re-sets…


#6

Jake,

I have seen the pinger script but I like your idea with the post request. I know enough about programming to be dangerous. I am very new to ST so I haven’t wrapped my head around the whole thing yet.


(Jake) #7

The best way is to have a play, perhaps strip back the host pinger script… to explain it in detail would be pretty much writing the code for you :slight_smile:

But as a starting point all the host pinger app is sending out is a url and ST is just picking up that event via the function I created called AppCommandReceived.

So something like the below:
[getApiServerUrl()]/api/smartapps/installations/[app.id]/pwh?access_token=[state.accessToken]&command=online&ipadd=192.168.1.10

The bits in square brackets are unique to you, and can be obtained using the commands or variables in the bracket…

The bits in bold can be whatever you want, pwh is defined in the mappings section of the code, and the variables command and ipadd are defined in the AppCommandReceived function… the value you pass from you host can then be whatever you want…

You could then remove half the code from the host pinger smartapp, you don’t need a device etc… and just take the output of AppCommandReceived to trigger a runIn() command and the target command from the runIn could then just trigger a notification… searching the developer documentation should show you how to do this…

From the host side you could then just either loop a python script or add it to a cron to send a get request on the URL you obtain above…

Something here should help with the command:

Hope that helps and I haven’t lost you…


#8

Thanks Jake I will see what I can come up with


#9

How would this continue to update the switch it you lose internet. By definition you would also lose connectivity to the ST cloud. So, you couldn’t update the switch to off.