Alert for when Imp on battery stops posting data to Xively?

This is a general question. I’m asking for any ideas.

I have been working on a project which places Imps (Joel’s C3V0 and P3V3) on battery in remote greenhouses (wide area wi-fi coverage) to alert farmers to overheating in manually-vented greenhouses.

For the last two months my friend has had one deployed, posting temp data to Xively, with an alert in place for over-temp conditions. Problem is, it was too reliable…he got out of the habit of checking it online every day to confirm the battery was still good and the Imp was posting data to Xively.

Bad news is the battery died of course, and the greenhouse overheated without sending him an alert. Now he’s wondering if he lost the tomato plants. He was relying on receiving an alert and wasn’t confirming the device was online every day.

My question is this. While we can use Xively to activate alerts on over-temp conditions, what I could really use is some mechanism to monitor the timestamp on the most recent Xively data…and send an alarm if the timestamp gets too old (meaning battery died or device went offline).

Or, I could use some other mechanism you suggest. Ideas?

Your device will keep running even if the device dies. One way to manage this is to have the agent have a watchdog timer, that the device resets every so often. If it doesn’t get reset, the agent fires off a text message with Twilio, an email, etc:

Agent Code
`watchdog <- null;

function sendAlert() {
// code to send alert here:

watchdog = imp.wakeup(21600, sendAlert); // send the alert in 6 hours

device.on(“temp”, function(data) {
// do your normal send thing

// cancel / recreate the alert time for 6 hours from now
if (watchdog != null) {
watchdog = imp.wakeup(21600, sendAlert);


Wow. Thanks @beardedinventor. I didn’t realize it could be that simple. Well, still over my head of course, but I think I can make that work.

I’m still struggling to understand the full power of the imp/cloud service/agents stuff. Your team is building something really amazing.

PS - He didn’t lose the crop! So, a lot of CSA shares will have their tomatoes. Disaster narrowly averted.

As my friend said, “today would have been a good day to have the sensor and alarms working…the sun came out after the rain, and it took me a while to get out to the high tunnels and open the sides. Man was it steamy in there! Like a sauna. Hope I didn’t stew any of the tomato plants…gulp. Really reinforces why these devices are worth the investment”.

Another option is to consider using GroveStreams in lieu of Xively. They offer the ability to create an event that can send off a message (SMS, email, etc.) when data is not received for a stream for a period of time you specify.

As a side note - it also looks like you can trigger an event in Xively when a channel “freezes” - although I’m not sure what their definition of “freeze” is (nor do I see a way to change that).

Thanks, @beardedinventor. good catch about Xively. @ctmorrisonhvacsp, thank you for the suggestion. I will try GroveStreams, too…

I have had a C3VO on Li-Po posting maxim ds18b20 temps on Xively for about 3 weeks now (2500 mah battery still going). I set up a freeze trigger in Xively to Zapier and got it online at 1:33pm Eastern Time today, 6-25-14. Test triggers seem ok.

I unplugged the Li-Po at 1:35pm. I’ll let you know if/when my phone gets a text indicating the C3V0 is offline. Seems like a good test of Xively “freeze” function.

Got a text from Zapier already. Looks like “freeze” trigger on Xively indicates ~15 minutes of inactivity. Am testing again now to confirm.

Ok! Second test of Xively “freeze” trigger using Zapier URL worked in 18 minutes. that seems like good confirmation.

Thanks again, everyone, including @beardedinventor. I am so grateful this community exists and is so helpful.

Now back to thinking about how HVAC mixing valves can be used best to retrofit-existing homes (paired with imps) for precise temperature of water flow to each plumbing fixture!

Oh. This is probably why i got variability between test one and two. Xively is on some schedule, and so is Zapier.

-Edit- test 3 starts. 3:05pm Eastern Time. More soon.

-Edit again - Test 3 came in at 17 minutes - Seems like this offline alarm through Xively works within 20 minutes or less.

I had very poor reliability with the Xively “freeze” feature, but that was several months ago. It may have been a problem with my setup, but I never did get it to work every time. The resume feature seemed to work more reliably. You may want to do some extensive testing before trusting the “freeze” to trigger. I had a web hook to Zapier which was easy to set up for an email alert. There is a tutorial either on Zapier or Xively showing you how to set that up. If your application is critical, I would consider using both, an agent watchdog timer AND the Xively freeze feature until you are comfortable with the reliability with Xively. As was previously noted, the Xively freeze feature is non-variable, only after 15 minutes of inactivity.

How about a small solar panel with rechargeable battery? It’s a greenhouse, so I assume there is adequate sunlight?

Seriously, I’m not affiliated with GroveStreams in any fashion other than being a very satisfied customer. We have numerous monitoring systems deployed and have events set up to notify us when the systems go offline (usually due to cellular issues). The delay time can be from nearly instant to as long as you want. It’s simple to set up a “latency” event and the action can take many forms (SMS, email, HTTP, etc.). I do believe it’s worth your time to consider what they offer. End of plug!

Thanks @ctmorrisonhvacsp, I will give GroveStreams a serious look.

Thanks for the info @joeolives, that’s valuable to know. I will also set up that watchdog timer.

@mlseim, right on. I do know that’s an option. One version of this hardware will probably go that way soon. The goal of this project is to write an “Instructable” of sorts for the Farmhack website. My friend initiated the project (farmer). At the end of the summer we are going to write this up and define a kit (with instructions). I do plan at least two variations (Joel’s C3V0 and P3V3), latter using a common 9v and former a Li-Po. After using Joel’s C3V0 and a 2500 mah battery, I’m convinced it’s too awesome to ignore for this project (high emphasis on low cost) even though it’s a few bucks more to build (per unit).

There are lots of reasons why things might fail so I would pursue getting a redundant and reliable “freeze” alarm, especially as there are cash crops at risk. But since battery level is always a recurring issue if you run solely off of batteries, you should consider including a battery monitor. It is quite simple to wire up although it does use up two pins. I believe it has been described elsewhere on the forum. I just connect a 10k resistor from bat+ to an ADC pin and then another from there to a digital pin. The programming is similar to the thermistor examples - bring the digital pin low to read battery voltage from the ADC pin. I use the same digital pin I am using to turn on and off the thermistor circuit. This way I save a pin, but then you have the thermistor and battery circuits active at the same time. Not a real problem as it uses very little current anyway. You can then set low battery level triggers at various levels so you can recharge or replace as necessary, well ahead of when the battery gets too low to transmit.