Spark Core Watchdog Timer

Due to various stability issues on the Core, I hacked together a little Watchdog Timer this afternoon for fun.

I’ve got a small USB charger plugged into a Belkin Wemo Outlet, which powers the Spark Core. Using ouimeaux give me command line access to the Wemo, I’ve written a bash script to curl the Cloud API and check to make sure a variable is regularly being updated. My script loops every 60 seconds; if the variable hasn’t changed the script immediately checks it two more times, waiting 10 seconds between checks. If the variable hasn’t changed at this point, we turn the Wemo Outlet off, wait 5 seconds and turn it back on. At this point, the script sleeps for 3 minutes and starts the process over again!

So, what other interesting things can we do with the Spark Core and Belkin Wemo? Well, the Wemo has the ability to automatically turn the outlet off and on based on user set times. We could use this to save energy by allowing the Core to set a “deep sleep” timer, which would command the Wemo to turn the outlet off for X minutes. In this case, the Wemo would power up the outlet (that the Core is plugged into), allowing the Core to perform whatever tasks are needed, at which point it would set int deepsleep with however minutes it wanted to be turned off, rinse, lather, repeat.

Once UDPClient is working, we could actually talk to the Wemo directly, without having to rely on an externally running script or program.

Once I get the code cleaned up a bit I’ll post the bash script and a picture or two.

Anyway, this was just a fun little exercise. Perhaps someone will find it useful. :smiley:

2 Likes

I actually decided to rewrite the bash script in Python, since that’s what the API I’m using is written in. It’s better this way, as I can just use a REST interpreter for Python and add some logic to make it sort of universal. I’ll just write my Watchdog script on top of that. :smile:

I figure a server side script for Wemo control might interest some people using the Spark Core for home automation. E.g., when a temperature or light sensor hits a certain point on the Core, it can set a variable true which will trigger whichever Wemo outlet it’s set to.

Hey @timb,

Sounds cool! You should tag this with the “Project Share” label and be sure to update us once you clean up the code :smile:

Love hearing about the stuff people are building with the Core.

Will @ Spark