node-red-contrib-radio-res

Use this flow to control differents objects :

-Download MySQL : npm install node-red-node-mysql -Go on MySQL interface : @ip-rpi/phpmyadmin and configure your BDD

On Node-RED : -Use the pin node where there is your radio receptor. -BDD 1 allows to capture just the first bit at the state “1” in a frame captured by the radio receptor. -BDD 2 could be use if you have an emetor and a radio recptor. This BBD 2 allows to select whose module will be used. -BDD 3 could be use if you have many object. This BDD 3 allows to select whose object well be used and control by radio remote -The counter allows to count the number of press on your radio remote

Ref: href="https://arno0x0x.wordpress.com/2015/04/02/rf433-outlet/ http://blog.idleman.fr/raspberry-pi-12-allumer-des-prises-distance/

References to IR : https://www.npmjs.com/package/node-red-contrib-lirc-easy

[{"id":"3ae300d6.67b13","type":"function","z":"fccf097d.2e7758","name":"Attendre \"1\"","func":"x=msg.payload;\n\nif(x==\"1nokrep\" || x==\"nok1rep\" || x==\"rep1nok\" || x==\"nokrep1\"){\n    var msg1={ topic: \"UPDATE message SET pwr='top' WHERE id=1\" };\n    var msg2={ payload: \"echo test1\" };    \n    return [msg1, msg2];\n}\n","outputs":"2","noerr":0,"x":641.9998779296875,"y":471.76038360595703,"wires":[["d684a345.0d1a8"],["5d52d7bb.8b96f8"]]},{"id":"aeb46542.b08908","type":"join","z":"fccf097d.2e7758","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","timeout":"","count":"3","x":301.829833984375,"y":559.1770629882812,"wires":[["3ae300d6.67b13","8b867087.b07e8"]]},{"id":"d684a345.0d1a8","type":"mysql","z":"fccf097d.2e7758","mydb":"c382d27a.c11ef","name":"BDD radio","x":430.895751953125,"y":323.76041412353516,"wires":[["69eb1a49.495a54"]]},{"id":"fbeac99a.102878","type":"function","z":"fccf097d.2e7758","name":"Test Topic","func":"x=msg.payload;\n\nif(x==\"1\"){ // à l'arriver d'un bit à \"1\"\n    var msg1={ topic: \"SELECT pwr FROM message;\" }; // on cré un objet qui contient une commande SQL pour sélectionner l'état de pwr dans la BDD\n    var msg2={ topic: \"SELECT emourep FROM emrep;\" }; // On vérifie dans la BDD que l'on authorise la réception radio\n    \n}\n\nreturn [msg1, msg2]; // On envoi ces messages","outputs":"2","noerr":0,"x":133.89584350585938,"y":323.76041412353516,"wires":[["d684a345.0d1a8"],["bcd35663.192358"]]},{"id":"9d5d04ee.075ee8","type":"debug","z":"fccf097d.2e7758","name":"","active":false,"console":"false","complete":"payload","x":888.8958129882812,"y":323.64933013916016,"wires":[]},{"id":"f821b762.1ffa78","type":"function","z":"fccf097d.2e7758","name":"RAZ","func":"x=msg.payload;\nif(x==\"1\"){\n    var msg1={ topic: \"UPDATE message SET pwr='nok' WHERE id=1\" };\n    return [msg1];\n}","outputs":"1","noerr":0,"x":380.8957824707031,"y":256.64929962158203,"wires":[["d684a345.0d1a8"]]},{"id":"4a520073.cc419","type":"inject","z":"fccf097d.2e7758","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"x":193.84030151367188,"y":225.00000762939453,"wires":[["f821b762.1ffa78"]]},{"id":"8b867087.b07e8","type":"debug","z":"fccf097d.2e7758","name":"","active":false,"console":"false","complete":"payload","x":529.8958129882812,"y":557.6492614746094,"wires":[]},{"id":"5d52d7bb.8b96f8","type":"trigger","z":"fccf097d.2e7758","op1":"","op2":"1","op1type":"nul","op2type":"str","duration":"0.5","extend":false,"units":"s","reset":"","name":"","x":163.89584350585938,"y":275.64929962158203,"wires":[["f821b762.1ffa78","b3f0b818.dfa3e8"]]},{"id":"69388ecd.e2f83","type":"debug","z":"fccf097d.2e7758","name":"","active":true,"console":"false","complete":"payload","x":625.8958129882812,"y":103.8888931274414,"wires":[]},{"id":"b3f0b818.dfa3e8","type":"function","z":"fccf097d.2e7758","name":"Compteur","func":"x=msg.payload;\nif(x==\"5\" || context.state == 5){\n    context.state = 0 ;\n    return [msg1];\n}\ncontext.state = context.state || 0;\n\ncontext.state ++;\nvar msg1 = { payload: context.state };\n\n\nreturn [msg1];","outputs":"1","noerr":0,"x":403.895751953125,"y":160.8888931274414,"wires":[["69388ecd.e2f83","8fdccc1a.c602d","4cc2e3b8.c6b8fc"]]},{"id":"9585bfc0.cc30e","type":"trigger","z":"fccf097d.2e7758","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"2","extend":true,"units":"s","reset":"","name":"","x":692,"y":242.00001525878906,"wires":[["17a3b5c4.ef9f0a","6a9750c8.920a9","81169f70.661a9"]]},{"id":"17a3b5c4.ef9f0a","type":"function","z":"fccf097d.2e7758","name":"Actions Télé","func":"x=msg.payload;\n\nif(x==\"1tele\" || x==\"tele1\"){\n    msg1={ payload : \"5\" };\n    return [msg1, null];\n}\nif(x==\"2tele\" || x==\"tele2\"){\n    msg1={ payload : \"5\" };\n    msg2={ payload : \"TELE/KEY_POWER\" };\n    return [msg1, msg2];\n}\nif(x==\"3tele\" || x==\"tele3\"){\n    msg1={ payload : \"5\" };\n    msg2={ payload : \"TELE/BTN_1\" };\n    return [msg1, msg2];\n}\nif(x==\"4tele\" || x==\"tele4\"){\n    msg1={ payload : \"5\" };\n    msg2={ payload : \"TELE/BTN_2\" };\n    return [msg1, msg2];\n}\nif(x==\"5tele\" || x==\"tele5\"){\n    msg1={ payload : \"5\" };\n    msg2={ payload : \"TELE/BTN_3\" };\n    return [msg1, msg2];\n}","outputs":"2","noerr":0,"x":873,"y":182.00000762939453,"wires":[["b3f0b818.dfa3e8"],["fcd44f39.7e947","40d63493.d2630c"]]},{"id":"fcd44f39.7e947","type":"TelecommandeIR","z":"fccf097d.2e7758","name":"TelecommandeIR","controller":"9845a5a.b366058","x":1165,"y":159.00001525878906,"wires":[]},{"id":"352a3285.5a6eee","type":"comment","z":"fccf097d.2e7758","name":"Forcer la remise à zéro du système","info":"","x":157,"y":187.00001525878906,"wires":[]},{"id":"24697aaf.d71e26","type":"comment","z":"fccf097d.2e7758","name":"Remise à zéro","info":"Passage automatique de la base de donnée à l'état\n\"nok\" après le traitement d'un bit à \"1\".","x":381,"y":222.00001525878906,"wires":[]},{"id":"6c6819e8.222058","type":"comment","z":"fccf097d.2e7758","name":"Le Compeur","info":"Le compteur comptabilise le nombre d'appui sur la\ntélécommande (correspond au nombre de bits à \"1\" \ntraités).\nAprès les trois secondes de temporisation, ce compteur\nest forcé à être réinitialisé.\n","x":403,"y":126.00000762939453,"wires":[]},{"id":"3147892d.771c56","type":"comment","z":"fccf097d.2e7758","name":"Gestion de la Base De Donnée (1)","info":"On sélection dans la base de donnée \"test\" \net dans la table \"message\", un état \"pwr\" qui \ncorrespond à \"top\" ou \"nok\".\n\nOn récupère le résultat en sortie de la BDD.\nOn adapte ce résultat en \"json\" pour faciliter son \nexploitation dans une fonction javascript.\n\nOn extrait le message du json dans la fonction \n\"info BDD\", pour récupérer une chaine de caractère\nqui sera par la suite exploité.\n\nSi le message est \"nok\" alors si le prochain bit\nreçu est un \"1\" alors on pourra autoriser le\ntraitement. Si il s'agit d'un top tout bit reçu sera\nobligatoirement refusé.","x":576,"y":291.00000762939453,"wires":[]},{"id":"bcd35663.192358","type":"mysql","z":"fccf097d.2e7758","mydb":"c382d27a.c11ef","name":"BDD radio","x":185,"y":419.00000762939453,"wires":[["df354e55.c8c61"]]},{"id":"df354e55.c8c61","type":"json","z":"fccf097d.2e7758","name":"","x":321,"y":419.00000762939453,"wires":[["9caf89d3.210bc8"]]},{"id":"9caf89d3.210bc8","type":"function","z":"fccf097d.2e7758","name":"Info BDD","func":"json=msg.payload;\nstr=json[13]+json[14]+json[15];\nobj = { payload: str };\nreturn obj;","outputs":1,"noerr":0,"x":453.0625,"y":418.94791412353516,"wires":[["aeb46542.b08908"]]},{"id":"2751ed0d.8f1502","type":"rpi-gpio in","z":"fccf097d.2e7758","name":"","pin":"36","intype":"in","debounce":"100","read":false,"x":98,"y":559,"wires":[["aeb46542.b08908","fbeac99a.102878"]]},{"id":"6a9750c8.920a9","type":"function","z":"fccf097d.2e7758","name":"Actions Drone","func":"x=msg.payload;\n\nif(x==\"1dron\" || x==\"dron1\"){\n    msg1={ payload : \"5\" };\n    return [msg1, null];\n}\nif(x==\"2dron\" || x==\"dron2\"){\n    msg1={ payload : \"5\" };\n    msg2={ payload : \"takeoff\" };\n    return [msg1, msg2];\n}\nif(x==\"3dron\" || x==\"dron3\"){\n    msg1={ payload : \"5\" };\n    msg2={ payload : \"land\" };\n    return [msg1, msg2];\n}","outputs":"2","noerr":0,"x":883,"y":220.00000762939453,"wires":[["b3f0b818.dfa3e8"],["bd60ea81.20ff58","3e9301a4.dc49fe"]]},{"id":"a990ec95.715f","type":"mysql","z":"fccf097d.2e7758","mydb":"c382d27a.c11ef","name":"BDD radio","x":135,"y":86.00000762939453,"wires":[["6742b731.9e53d8"]]},{"id":"69eb1a49.495a54","type":"json","z":"fccf097d.2e7758","name":"","x":565.8333740234375,"y":323.7013931274414,"wires":[["e3650d7e.78dc4"]]},{"id":"e3650d7e.78dc4","type":"function","z":"fccf097d.2e7758","name":"Info BDD","func":"json=msg.payload;\nstr=json[9]+json[10]+json[11];\nobj = { payload: str };\nreturn obj;","outputs":1,"noerr":0,"x":693.8958129882812,"y":323.64929962158203,"wires":[["3ae300d6.67b13","aeb46542.b08908","9d5d04ee.075ee8"]]},{"id":"6742b731.9e53d8","type":"json","z":"fccf097d.2e7758","name":"","x":298,"y":86.00000762939453,"wires":[["632ec686.80b528"]]},{"id":"632ec686.80b528","type":"function","z":"fccf097d.2e7758","name":"Info BDD","func":"json=msg.payload;\nstr=json[11]+json[12]+json[13]+json[14];\nobj = { payload: str };\nreturn obj;","outputs":1,"noerr":0,"x":430.06243896484375,"y":86.94791412353516,"wires":[["8fdccc1a.c602d"]]},{"id":"8fdccc1a.c602d","type":"join","z":"fccf097d.2e7758","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","timeout":"","count":"2","x":547,"y":242.00000762939453,"wires":[["9585bfc0.cc30e","69388ecd.e2f83"]]},{"id":"40d63493.d2630c","type":"debug","z":"fccf097d.2e7758","name":"","active":true,"console":"false","complete":"payload","x":1159,"y":194.00001525878906,"wires":[]},{"id":"bd60ea81.20ff58","type":"mqtt out","z":"fccf097d.2e7758","name":"","topic":"/drone","qos":"","retain":"","broker":"534a3ded.ec85a4","x":1166,"y":234.00001525878906,"wires":[]},{"id":"3e9301a4.dc49fe","type":"debug","z":"fccf097d.2e7758","name":"","active":true,"console":"false","complete":"payload","x":1168,"y":266.00001525878906,"wires":[]},{"id":"81169f70.661a9","type":"function","z":"fccf097d.2e7758","name":"Actions Hifi","func":"x=msg.payload;\n\nif(x==\"1hifi\" || x==\"hifi1\"){\n    msg1={ payload : \"5\" };\n    return [msg1, null];\n}\nif(x==\"2hifi\" || x==\"hifi2\"){\n    msg1={ payload : \"5\" };\n    msg2={ payload : \"HIFI/KEY_POWER\" };\n    return [msg1, msg2];\n}\nif(x==\"3hifi\" || x==\"hifi3\"){\n    msg1={ payload : \"5\" };\n    msg2={ payload : \"HIFI/BTN_1\" };\n    return [msg1, msg2];\n}\nif(x==\"4hifi\" || x==\"hifi4\"){\n    msg1={ payload : \"5\" };\n    msg2={ payload : \"HIFI/BTN_2\" };\n    return [msg1, msg2];\n}\nif(x==\"5hifi\" || x==\"hifi5\"){\n    msg1={ payload : \"5\" };\n    msg2={ payload : \"HIFI/BTN_3\" };\n    return [msg1, msg2];\n}","outputs":"2","noerr":0,"x":879,"y":255.00000762939453,"wires":[["b3f0b818.dfa3e8"],["fcd44f39.7e947","2645b3f2.40977c"]]},{"id":"2645b3f2.40977c","type":"debug","z":"fccf097d.2e7758","name":"","active":true,"console":"false","complete":"payload","x":1167,"y":298.00001525878906,"wires":[]},{"id":"4cc2e3b8.c6b8fc","type":"function","z":"fccf097d.2e7758","name":"Test Topic","func":"var msg3={ topic: \"SELECT objet FROM controle;\" };\nreturn msg3;","outputs":1,"noerr":0,"x":159,"y":132.00000762939453,"wires":[["a990ec95.715f"]]},{"id":"4b259944.242228","type":"comment","z":"fccf097d.2e7758","name":"Les différentes Actions","info":"A partir de l'interface web /radio, choisissez quel\nobjet vous voulez contrôler parmi :\n1- la Télévision\n2- la chaine HIFI\n3- le Drone","x":892,"y":129,"wires":[]},{"id":"dcb8133c.154ae","type":"comment","z":"fccf097d.2e7758","name":"Gestion de la Base De Donnée (3)","info":"On sélection dans la base de donnée \"radio\" \net dans la table \"controle\", un état \"objet\" qui \ncorrespond à \"tele\", \"hifi\" ou \"dron\".\n\nOn récupère le résultat en sortie de la BDD.\nOn adapte ce résultat en \"json\" pour faciliter son \nexploitation dans une fonction javascript.\n\nOn extrait le message du json dans la fonction \n\"info BDD\", pour récupérer une chaine de caractère\nqui sera par la suite exploité.\n\n","x":161,"y":43,"wires":[]},{"id":"5bad387b.baa548","type":"comment","z":"fccf097d.2e7758","name":"Gestion de la Base De Donnée (2)","info":"On sélection dans la base de donnée \"radio\" \net dans la table \"emrep\", un état \"emourep\" qui \ncorrespond à \"emi\" ou \"rep\".\n\nOn récupère le résultat en sortie de la BDD.\nOn adapte ce résultat en \"json\" pour faciliter son \nexploitation dans une fonction javascript.\n\nOn extrait le message du json dans la fonction \n\"info BDD\", pour récupérer une chaine de caractère\nqui sera par la suite exploité.\n\nSi le message est \"emi\" alors la réception ne sera \nfonctionnelle. Si le message est \"rep\", nous pourrons\ndonc avoir une réception des ondes radios.","x":282,"y":387,"wires":[]},{"id":"c382d27a.c11ef","type":"MySQLdatabase","z":"","host":"127.0.0.1","port":"3306","db":"radio","tz":""},{"id":"9845a5a.b366058","type":"lirc-controller","z":0},{"id":"534a3ded.ec85a4","type":"mqtt-broker","z":"","broker":"192.168.0.50","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]

Flow Info

Created 7 years, 8 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • comment (x7)
  • debug (x6)
  • function (x11)
  • inject (x1)
  • join (x2)
  • json (x3)
  • mqtt out (x1)
  • mqtt-broker (x1)
  • trigger (x2)
Other

Tags

Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option