Nous avons de plus en plus d'objets connectés, la question est comment s'assurer de leur bon fonctionnement ? Voici un exemple de flow simple mis en oeuvre sur Node-Red pour vérifier la disponibilité de ses objets connectés et être immédiatement averti en cas de problème.
J'utilise pour cela le nœud "Ping" disponible sur le portail de Node-Red. Ce nœud peut s'installer très rapidement au travers de la commande suivante:


$ npm install node-red-node-ping

Il est aussi possible d'utiliser le plugin Ping Advanced, plus riche en fonctionnalités, mais mis à jour il y a plus d'un an.

node-red-flow-ping.png

  • Première étape, le serveur ping l'ensemble des objets et le DNS de Google pour s'assurer de la connectivité à Internet.
  • Seconde étape, si un ping échoue et retourne "false", je construis un SMS et un email que j'envoie dans une limite de 5 messages par heure et 10 par jour.

Pour l'envoi du SMS, j'utilise le flow Node-Red précédemment décrit sur ce blog.

Voici le flow en détail pouvant être directement importé dans Node-Red via la fonction d'import disponible dans le menu de l'application :


[{"id":"9eb4b49c.614b48","type":"ping","name":"Check Internet","host":"8.8.8.8","timer":"60","x":114,"y":74,"z":"38ba78b3.c74588","wires":[["12de3311.ed21cd"]]},{"id":"ebb458eb.144ba8","type":"ping","name":"Check Karotz","host":"192.168.1.6","timer":"60","x":111,"y":118,"z":"38ba78b3.c74588","wires":[["12de3311.ed21cd"]]},{"id":"59174860.a6e8b8","type":"ping","name":"Check Arduino","host":"192.168.1.4","timer":"60","x":113,"y":164,"z":"38ba78b3.c74588","wires":[["12de3311.ed21cd"]]},{"id":"46b5d3a9.b94a2c","type":"ping","name":"Check Switch","host":"192.168.1.1","timer":"60","x":111,"y":210,"z":"38ba78b3.c74588","wires":[["12de3311.ed21cd"]]},{"id":"9b7fa33e.64806","type":"ping","name":"Check Freebox","host":"192.168.1.254","timer":"60","x":117,"y":254,"z":"38ba78b3.c74588","wires":[["12de3311.ed21cd"]]},{"id":"12de3311.ed21cd","type":"switch","name":"","property":"payload","rules":[{"t":"false"}],"checkall":"true","outputs":1,"x":402,"y":150,"z":"38ba78b3.c74588","wires":[["feeab731.011548"]]},{"id":"feeab731.011548","type":"delay","name":"","pauseType":"rate","timeout":"1","timeoutUnits":"hours","rate":"5","rateUnits":"hour","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":572,"y":151,"z":"38ba78b3.c74588","wires":[["95c19115.6a3e7"]]},{"id":"95c19115.6a3e7","type":"delay","name":"","pauseType":"rate","timeout":"4","timeoutUnits":"seconds","rate":"10","rateUnits":"day","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":737,"y":150,"z":"38ba78b3.c74588","wires":[["17b9866d.e8467a"]]},{"id":"6aa677bb.955988","type":"http request","name":"SMS Alert Ludovic","method":"GET","ret":"txt","url":"http://localhost:8080/api/sendsms?phone=0646340951&msg={{{payload}}}","x":1168,"y":157,"z":"38ba78b3.c74588","wires":[[]]},{"id":"17b9866d.e8467a","type":"template","name":"Ping message","field":"payload","format":"handlebars","template":"Serveur {{topic}} indisponible ! ","x":919,"y":157,"z":"38ba78b3.c74588","wires":[["6aa677bb.955988","da3155a.f25cea8"]]},{"id":"da3155a.f25cea8","type":"e-mail","server":"smtp.gmail.com","port":"465","name":"ltoinel@free.fr;sterenn.lenir@gmail.com","dname":"Email Alert","x":1149,"y":209,"z":"38ba78b3.c74588","wires":[]},{"id":"7490e004.8b6f2","type":"comment","name":"Ping toutes les 60 secondes","info":"","x":157,"y":30,"z":"38ba78b3.c74588","wires":[]},{"id":"9740b72f.68bf48","type":"comment","name":"Si KO","info":"","x":401,"y":98,"z":"38ba78b3.c74588","wires":[]},{"id":"cf2d3049.30d2d","type":"comment","name":"Anti-Spam","info":"","x":559,"y":95,"z":"38ba78b3.c74588","wires":[]},{"id":"e289635a.1d76a","type":"comment","name":"Construction du message","info":"","x":923,"y":97,"z":"38ba78b3.c74588","wires":[]},{"id":"ab74252b.548bd8","type":"comment","name":"Transmission","info":"","x":1150,"y":99,"z":"38ba78b3.c74588","wires":[]}]

Ce flow vous permettra de vous assurer que vos objets connectés sont correctement allumés et disponibles, en cas de problème vous serez immédiatement averti par SMS et email.