(WeMo + Pi + ThingSpeak) Power cycle my Pi

Apparently the Pi is more stable when the fan is not attached.  I suspect something to do with power because with the fan attached it will log for a day or so and then stop, but without it will last for about 3 days, 4 maximum and then stop.  I’m checking in my script for network connectivity and attempting to re-establish this on network loss, then I’m re-booting the whole thing ever 48 logs.  So, every day it reboots. There’s a gradual creep up in CPU load, then the Pi is re-booted and a spike in CPU load is recorded as the Pi starts up, then it goes back to minimal CPU use after re-booting.

So, how do you make my system log all the time with only small interruptions? Time for a plan.

We’ll use a third party to check and make sure there’s been an update in the last hour time and if not, cycle the power.  Since the power cycle is a Belkin WeMo switch, we’re going to need a way of being able to access the commands for cycling power using upnp over a python script, running on a pi that isn’t the SkySlab monitor. Luckily, we have a Pi running as a third party controller checking up-time, logs and the server health of this webserver, so it can also be used to be the ‘independent’ monitor.

Step 1: Find out how to set a flag when ThingSpeak is updated.
The script here shows that every 1800 seconds a new log should be made, so it’s safe to say that somewhere within a bracket of 3600 seconds. I need a script that will pull down the data from ThingSpeak, check the latest update and if it’s not within the last 3600 from (now), cycle the power.

Step 2: How do you call the WeMo power cycle without an iDevice?
Help is here and here and here and here. The last link is particularly relevant. I’ve assigned a permanent IP address to the WeMo. I’ll look into importing the Miranda library and calling the correct upnp call to the WeMo to turn power off, wait 5 seconds, then power on.  This might take a bit of experimenting because at the moment the WeMo is attached to the main power supply on SkySlab. If SkySlab power was interrupted during viewing or photo session, that might be bad in a ‘don’t cross the streams’ kind of way. The code is likely to involve this:

I’ve tested the code, a binary state of 0 turns the WeMo off and a binary state of 1 turns it on.  I monitored this using my iDevice and looked at it after executing the code. Works! As the man says, ‘LIKE A BOSS’.HAc6jtgo_400x400If I can figure out how to get a network signal to the WeMo through an insulated tin-shed then it might not be so bad, but that would involve having a wireless repeater inside SkySlab and likely broadcasting a signal from something like Ethernet over Power. I read somewhere that someone was able to effectively hack the WeMo and add an external antenna just by drilling a hole in the PCB aerial (seen on the first link in this step). I’d do that, but don’t know how to because any aerial will have an active signal and a ground.  Need to figure out how to do that on a PCB antenna…

Step 3: Need to plan some stats on this so that I can see if this is all working autonomously.
The script will need to add a graph I think to ThingSpeak which will show the number of power cycles per day over the last 10 days. Then I’ll modify the blog to show that. I might also build in some CPU load and CPU temperature monitoring for the webserver, that seems prudent.

There, that’s a plan, now to do some research and coding!

Related Posts
idas-light-pollution-suppression-lps-filter-2-round-mountedpython-logo-master-v3-TM