Skip to content

Instantly share code, notes, and snippets.

@M-rTom

M-rTom/README.md Secret

Created April 21, 2017 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save M-rTom/2417af9101b096f64662348750f122eb to your computer and use it in GitHub Desktop.
Save M-rTom/2417af9101b096f64662348750f122eb to your computer and use it in GitHub Desktop.
OBi Connection Status Monitor & Alert

This flow checks the connection status of your Obihai OBi device every 30 seconds and will email and/or text you a notification if it's disconnected or otherwise not available.

You may need to download and install the www-request node to get this flow to work correctly. http://flows.nodered.org/node/node-red-contrib-http-request

I have only tested this with my OBi200, but it looks like all OBi devices have the same status page so it should work with other OBi devices too.

Nodes you'll need to edit are 'Set Variables', 'Check OBi Status', 'Send a Text Msg' & 'Send an Email'.

[{"id":"a1fef95d.b00f08","type":"tab","label":"Flow 1"},{"id":"9258e64b.fd31e8","type":"inject","z":"a1fef95d.b00f08","name":"Set Schedule","topic":"","payload":"","payloadType":"date","repeat":"30","crontab":"","once":true,"x":120,"y":80,"wires":[["f1a44282.334b88"]]},{"id":"fca625cb.5669b8","type":"debug","z":"a1fef95d.b00f08","name":"Debug Output","active":true,"console":"false","complete":"payload","x":780,"y":240,"wires":[]},{"id":"f0e93aff.a7f828","type":"switch","z":"a1fef95d.b00f08","name":"Connected?","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"Normal (User Mode)","vt":"str"},{"t":"else"}],"checkall":"true","outputs":2,"x":110,"y":260,"wires":[["4a6c9c5.56b9ce4"],["30b21812.c31e6"]]},{"id":"6574963.2d58868","type":"function","z":"a1fef95d.b00f08","name":"Clear Headers","func":"msg.headers = null;\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":160,"wires":[["422ff7b3.5dbdf8"]]},{"id":"89c7a013.8e71d8","type":"www-request","z":"a1fef95d.b00f08","name":"Check OBi Status","method":"GET","ret":"txt","url":"http://192.168.1.2/DI_S_.xml","tls":"","x":130,"y":160,"wires":[["6574963.2d58868"]]},{"id":"4a6c9c5.56b9ce4","type":"change","z":"a1fef95d.b00f08","name":"Yes","rules":[{"t":"set","p":"payload","pt":"msg","to":"Connected","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":240,"wires":[["553ba9dd.b15238"]]},{"id":"30b21812.c31e6","type":"change","z":"a1fef95d.b00f08","name":"No","rules":[{"t":"set","p":"payload","pt":"msg","to":"Not Connected","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":280,"wires":[["3aef0390.a3d594"]]},{"id":"422ff7b3.5dbdf8","type":"xml","z":"a1fef95d.b00f08","name":"","attr":"","chr":"","x":510,"y":160,"wires":[["d55466c9.2778f"]]},{"id":"d55466c9.2778f","type":"json","z":"a1fef95d.b00f08","name":"","x":650,"y":160,"wires":[["f0e93aff.a7f828"]]},{"id":"67a4c0e6.84c7f8","type":"catch","z":"a1fef95d.b00f08","name":"","scope":["89c7a013.8e71d8"],"x":100,"y":360,"wires":[["241df6b7.06aef2"]]},{"id":"241df6b7.06aef2","type":"change","z":"a1fef95d.b00f08","name":"Error Message","rules":[{"t":"set","p":"payload","pt":"msg","to":"error.message","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":360,"wires":[["3aef0390.a3d594"]]},{"id":"f1a44282.334b88","type":"function","z":"a1fef95d.b00f08","name":"Set Variables","func":"// Number of errors it takes to trigger an error\nflow.set(\"ErrorThreshold\",3);\n\n// Repeat the error notification every # of errors\nflow.set(\"ErrorRepeatEvery\",120); // 0=disabled\n\n// Notification methods\nflow.set(\"SendEmail\",false);\nflow.set(\"SendTextMsg\",true);\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":80,"wires":[["89c7a013.8e71d8"]]},{"id":"3aef0390.a3d594","type":"function","z":"a1fef95d.b00f08","name":"Increment Error Count","func":"var ErrorCount = flow.get(\"ErrorCount\")||0;\nflow.set(\"ErrorCount\",++ErrorCount);\nmsg.payload += \"(\" + ErrorCount + \")\";\n\nif (ErrorCount % flow.get(\"ErrorRepeatEvery\") === 0) {\n flow.set(\"ErrorRepeat\",ErrorCount); \n} else {\n flow.set(\"ErrorRepeat\",0);\n}\nreturn msg;","outputs":"1","noerr":0,"x":560,"y":360,"wires":[["a57bb264.cc2b4"]]},{"id":"50de87be.80851","type":"e-mail","z":"a1fef95d.b00f08","server":"smtp.gmail.com","port":"465","secure":true,"name":"","dname":"Send an Email","x":780,"y":560,"wires":[]},{"id":"bc0395e6.dcc83","type":"switch","z":"a1fef95d.b00f08","name":"Notify By Email?","property":"SendEmail","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","outputs":1,"x":540,"y":560,"wires":[["50de87be.80851"]]},{"id":"cb15e640.1fa81","type":"switch","z":"a1fef95d.b00f08","name":"Notify By Text Msg?","property":"SendTextMsg","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","outputs":1,"x":550,"y":500,"wires":[["e29ab38d.626248"]]},{"id":"e29ab38d.626248","type":"e-mail","z":"a1fef95d.b00f08","server":"smtp.gmail.com","port":"465","secure":true,"name":"","dname":"Send a Text Msg","x":790,"y":500,"wires":[]},{"id":"32db1f34.ddc388","type":"comment","z":"a1fef95d.b00f08","name":"Sending a Text Msg Info","info":"Send an email to 10DigitPhoneNumber@ below address\nExample: 2024561111@txt.att.net\n\nU.S. Carrier SMS Gateway\nAltel @sms.alltelwireless.com\nAT&T @txt.att.net\nBoost Mobile @sms.myboostmobile.com\nSprint @messaging.sprintpcs.com\nT-Mobile @tmomail.net\nU.S. Cellular @email.uscc.net\nVerizon @vtext.com\nVirgin Mobile @vmobl.com\n\nMore Info:\nhttp://www.digitaltrends.com/computing/how-to-send-free-text-messages-online/\nhttps://20somethingfinance.com/how-to-send-text-messages-sms-via-email-for-free/","x":800,"y":460,"wires":[]},{"id":"227d9b16.dde254","type":"catch","z":"a1fef95d.b00f08","name":"","scope":["e29ab38d.626248","50de87be.80851"],"x":100,"y":420,"wires":[["7c4ff1b2.e5659"]]},{"id":"7c4ff1b2.e5659","type":"change","z":"a1fef95d.b00f08","name":"Error Message","rules":[{"t":"set","p":"payload","pt":"msg","to":"error.message","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":420,"wires":[["fca625cb.5669b8"]]},{"id":"a57bb264.cc2b4","type":"function","z":"a1fef95d.b00f08","name":"Trigger Error?","func":"if (flow.get(\"ErrorCount\") === flow.get(\"ErrorThreshold\") ||\n flow.get(\"ErrorCount\") === flow.get(\"ErrorRepeat\")) {\n return [msg, null];\n} else {\n return [null, msg];\n}","outputs":"2","noerr":0,"x":780,"y":360,"wires":[["fca625cb.5669b8","cb15e640.1fa81","bc0395e6.dcc83"],["fca625cb.5669b8"]]},{"id":"4d7699aa.7dbc28","type":"comment","z":"a1fef95d.b00f08","name":"About","info":"v1.0\nObi Status / By MrTom / April 2017\n----------------------------------\n___\nChecks the connection status of your Obihai OBi\ndevice every 30 seconds and will email and/or\ntext you a notification if it's disconnected or\notherwise not available.","x":90,"y":20,"wires":[]},{"id":"553ba9dd.b15238","type":"change","z":"a1fef95d.b00f08","name":"Clear Error","rules":[{"t":"set","p":"ErrorCount","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":240,"wires":[["fca625cb.5669b8"]]}]
@hepcat72
Copy link

hepcat72 commented Apr 9, 2023

I just tried this out. (Of course, I replaced the www-request node with the http-request node set to GET.) However, I get an error from the xml node:

Error: Unexpected close tag
Line: 3
Column: 4
Char: >

So I attached a debug node to the one before it and this was the response from my Obi200:

<html><head>
<title>OBi200</title>
<body><p><font size="5">401 Unauthorized!
</p></body>
</head></html>

Do you happen to know the steps to authorize the requests?

  • Probably should include that in your flow's instructions.

@hepcat72
Copy link

hepcat72 commented Apr 9, 2023

OK, I figured it out. For the http-request node, you have to set the authentication type to "digest authentication" and enter the (admin) username/password. (I'm not sure what the "User" username would be - there's no setting for it in the web interface - only the password.)

@M-rTom
Copy link
Author

M-rTom commented Apr 12, 2023

OK, I figured it out. For the http-request node, you have to set the authentication type to "digest authentication" and enter the (admin) username/password. (I'm not sure what the "User" username would be - there's no setting for it in the web interface - only the password.)

Hi, thanks for the interest. I believe it's just 'admin' for the username.

@hepcat72
Copy link

Yeah, I know for the admin login it's admin - that's what I used to make it work, but you can set a "user" password in addition to an "admin" password in the obi200 WAN settings and I was just idly wondering what the username for that was...

@hepcat72
Copy link

Although, maybe you're suggesting the username is admin for both the admin account and user account?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment