An external service to watch for a heartbeat from Node-RED?

764 views
Skip to first unread message

Loren Amelang

unread,
Aug 22, 2014, 7:55:02 PM8/22/14
to node...@googlegroups.com
I'd like to receive an SMS whenever Node-RED is NOT updating the various external servers it connects with. That would catch problems like me stupidly doing something that kills the Node process, or the local router losing power, or somebody digging through the fiber that connects my whole valley. IFTTT can send SMS, but I'm not finding any "timeout" or (NOT) trigger functions there, nor any obvious IFTTT triggers that Node-RED could easily update. 

Before I create some arcane kludge, has someone maybe done this already? Hopefully using some free, public cloud service to watch for updates and warn if they stop? SMS (or an actual phone call) is about the only appropriate notification, since I intentionally don't monitor any other service in realtime. 

Andrew Lindsay

unread,
Aug 23, 2014, 4:55:41 AM8/23/14
to node...@googlegroups.com
With any monitoring that relies on the net connection to send alerts, how will it know that Node-RED has died or stopped working in some way when it could just be a router, fibre or any connection in between.

IFTTT can't at present poll specific REST URLs which is something I'd like but this requirement was before Node-RED came along. You could build a second Node-RED instance somewhere else to watch the first one, then they could watch each other. Probably get a third to watch the others.

Using a standalone SMS from a mobile network connected device that is triggered by Node-RED losing its connection could be an option.

Probably no help at all.

Andrew

chris mobberley

unread,
Aug 23, 2014, 7:25:04 AM8/23/14
to node...@googlegroups.com
I can offer a few options for outputting notifications that dont require IFTTT.

Node-red has a number of extra nodes which would be ideal three of which are:

push bullet - notifies your android/pc/iphone
pushover - same as above but you can prioritise the types of notifications e.g. high priority notification can sound an alert on your phone as opposed to a low priorty which will just display a notification.
twilio output node - produced by Andrew L this will send an sms to a given number via twilio.com

All of the above will be much more flexible to work with than IFTTT in my opinion.

Shem J

unread,
Aug 23, 2014, 9:43:21 AM8/23/14
to node...@googlegroups.com
Good question.

You would need to know if it is Node-red or your whole internet connection first. You could find out if your whole internet connection is down externally with a free uptime monitoring service.

To find out if Node-red is not 'doing its thing' you need to send a message periodically to another instance of Node-red elsewhere... Use your desired input(mqtt/tcp etc), trigger(this is the NOT one you are after), switch and twillio(sms) nodes together and you have your alert when Node-red is down! 

Dave C-J

unread,
Aug 23, 2014, 1:44:12 PM8/23/14
to node...@googlegroups.com
As already mentioned you really need multiple monitoring points to cover various failure modes... 
If your home box is up - but the wire internet link is down (determined by pinging one or more remote servers... (how about Google dns 8.8.8.8)) - then a local GSM modem (old phone) could be used to send an SMS - eg using gammu app and command line
    echo 'Here is the text of your SMS' | gammu sendsms TEXT +1234567890

If the local box fails then a remotely hosted box (maybe a small Bluemix trial) - can be used the other way to check (or accept) a connection from your house and fire a Twillio SMS message in case of failure...

Of course MQTT does have the concept of Last Will and Testament build in - so the broker will fire a message on behalf of the client if it disconnects uncleanly - but there again you would need a hosted MQTT server - (there are demo ones out there) - but even they go down as well...


chris mobberley

unread,
Aug 23, 2014, 1:45:00 PM8/23/14
to node...@googlegroups.com
To do the check to see if I have a net connection I use a ping node to ping www.google.com. I do this also to see if my servers are responding and send a push notification if the response fails multiple times over a set period.

Loren Amelang

unread,
Aug 24, 2014, 7:40:39 PM8/24/14
to node...@googlegroups.com
Many thanks for all the thoughts! Some reactions:

I don't really care whether the heartbeat system knows what has gone wrong (Red/Linux/router/network/...), I just want to be poked when my data are not being saved, so I can go figure out which bit is broken. 

Twilio seems to be the prime SMS link, and would be perfect for sending the hopefully rare problem notification. But to do the actual heartbeat, I need to send repeating messages 24/7. Even once per hour at $0.0075 per, that would add up! 

Running a second Red instance locally doesn't solve the problem of local power or local connectivity being down. Running one somewhere in the cloud is not going to be free, at least not long-term. 

I remembered my Android runs Tasker. The phone would seem a perfect alternate host for watching the heartbeat stream, with its own independent power and wireless connection. Tasker can be hooked up to send notifications via Pushbullet, and it sounds like Tasker 4.3+ can react to them:
-----
Pushbullet now takes advantage of the Event plugins Tasker introduced in its recent 4.3 update. Pushbullet already supported sending notifications with Pushbullet through Tasker, but now Tasker can react to messages received through Pushbullet.
-----
But my Android is too old for Tasker 4.3, and I'm only seeing v4.2 on the PlayStore anyway. Oh, well...  

My current fantasy is a custom Python script on the Android phone, which would periodically poke my Node-RED server via the internet for a status update. If no response for any reason, the phone can notify me locally. 

-----
Any status other than 200 is considered a problem and highlighted in the application or directly on the widget(s).
-----

Clues for setting up a responding flow:

I guess seeing that response doesn't prove the other flows are actually saving data, but it does show Node-RED is alive and has a network connection. That covers the problems I've seen so far! 

Loren Amelang

unread,
Sep 4, 2014, 4:28:30 PM9/4/14
to node...@googlegroups.com
My first version of this is working. Hasn't caught any Node-RED failures yet, but has poked me about a few other connectivity glitches. It is intentionally rather mild at notification, just vibrating once and saving a status icon. There are lots of places where different choices might suit someone else, but this seems like the simplest solution for me. 

It does require that the Node-RED interface is accessible from the internet. The example of the "HTTP In" node shows "http://localhost:1880/hello", but the interesting applications aren't limited to the local network. Maybe there should be some mechanism for isolating the Node-RED control interface from the accessible nodes? (Have I missed it?) In my case I've limited the incoming address of the port forward to my phone's address, but not all routers can do that. 

The script (with usage clues):

#!/usr/bin/env python

# A script for Android sl4a to verify Node-RED is alive
# Your Node-RED installation must be accessible from your phone
# If your phone switches between local and internet access, 
#  you may need two scripts; Tasker can choose based on current connection.

# Be sure to set <address of your Node-RED machine> below!

# Loren Amelang, 31Aug14

# Distributed under the Apache license, like sl4a itself:
# -----
# Copyright 2014 Loren Amelang
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -----


# sl4a is available here:
# Installing interpreters (like Python) is detailed here:

# My sl4a has libPython 2.6
# Scripts live in /mnt/sdcard/sl4a/scripts

# To simplify launching the script, create a home screen shortcut: 
# Long-press an empty space on a home screen and select Shortcuts, 
# then Scripts. Once SL4A opens up, select hbRED.py from the list 
# and then click the gear icon.

# One could run Python in an infinite loop, but I already have Tasker running...
# To set Android Tasker to run this script periodically:
# Along the top - Tasks
# Bottom - Green +
# (add task)
# Name - hbRED
# Green checkmark
# (task edit)
# Blue +
# Script
# Run SL4A Script
# (run script)
# Magnifying Glass
# (select script)
# tap name
# Green checkmark
# Green checkmark
# Along the top - Profiles
# Bottom - Green +
# (new profile)
# Name - hbRun
# Green checkmark
# (first context)
# Time
# uncheck From and To
# check repeat every 1 hours
# Green checkmark
# (task selection)
# hbRED
# [there is a New Task choice if you did this part first]


import android, os, re
import urllib2

droid = android.Android()

url = 'http://<address of your Node-RED machine>:1880'

# urllib2.urlopen(url[, data][, timeout])

try:
   rsp = urllib2.urlopen(url)
except urllib2.HTTPError, e:
   print ('No HTTP ')
   droid.vibrate(999)
   droid.notify(
      'Node-RED',
      'not responding')
except urllib2.URLError, e:
   print ('No URL ')
   droid.vibrate(999)
   droid.notify(
      'Node-RED',
      'inaccessible')
else:
   hdr = rsp.read()
   print (hdr[:50])

print "OK"
os._exit (1)

#eof

Paul Reed

unread,
Sep 13, 2014, 6:39:28 PM9/13/14
to node...@googlegroups.com
Martin Harizanov has a great solution to this, see - http://harizanov.com/2014/09/monitoring-my-home-automation-system-uptime/
I have followed his lead, and am well impressed with his solution.

Paul


On Saturday, 23 August 2014 00:55:02 UTC+1, Loren Amelang wrote:

Andrew Lindsay

unread,
Sep 14, 2014, 3:20:35 AM9/14/14
to node...@googlegroups.com
Not read that yet myself but have seen lots of other projects by Martin, clever guy!

Cheers

Andrew

Andrew Lindsay

unread,
Sep 14, 2014, 3:39:57 AM9/14/14
to node...@googlegroups.com
Now I've read it, need to set this up myself.

Cheers

Andrew

Dave C-J

unread,
Sep 14, 2014, 6:10:14 AM9/14/14
to node...@googlegroups.com
+1 from me - very simple and works well.

Christopher Mobberley

unread,
Sep 14, 2014, 6:23:02 AM9/14/14
to node...@googlegroups.com
Indeed I love using services like this! Kinda looks like something
bluemix could easily incorporate too. I liked the IOT raspberry pi
connector showing cpu and temps when I was using a beta account there.

On 14 September 2014 11:10, Dave C-J <dce...@gmail.com> wrote:
> +1 from me - very simple and works well.
>
> --
> http://nodered.org
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "Node-RED" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/node-red/2b_g5IJmXBY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> node-red+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages