Created
January 29, 2015 08:41
-
-
Save Oliv4945/3d99150fefce7115ce6e to your computer and use it in GitHub Desktop.
Node-Red flow for Air Quality in Grenoble
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"id":"53bd85c0.99ddac","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":"Node-Red"},{"id":"2c75144.fd38aec","type":"http request","name":"Get pollution Grenoble","method":"GET","url":"http://feeds.feedburner.com/atmorhonealpes_indicequaliteair_grenoble","x":170,"y":230,"z":"adc463f6.523ba","wires":[["315dd6ea.cea22a"]]},{"id":"6f1dc1f8.90e24","type":"inject","name":"Start flow","topic":"","payload":"","payloadType":"date","repeat":"1440","crontab":"","once":true,"x":92,"y":165,"z":"adc463f6.523ba","wires":[["2c75144.fd38aec"]]},{"id":"315dd6ea.cea22a","type":"xml","name":"","x":160,"y":295,"z":"adc463f6.523ba","wires":[["6c293291.93d6cc"]]},{"id":"78cdab88.873254","type":"change","action":"replace","property":"url","from":"","to":"msg.payload.rss.channel[0].item[0].link[0]","reg":false,"name":"Parse RSS to extract URL","x":431,"y":303,"z":"adc463f6.523ba","wires":[["933c52e6.6cc3b"]]},{"id":"6c293291.93d6cc","type":"switch","name":"Check HTTP status","property":"statusCode","rules":[{"t":"eq","v":200,"v2":0},{"t":"neq","v":200,"v2":0}],"checkall":"true","outputs":2,"x":205,"y":371,"z":"adc463f6.523ba","wires":[["78cdab88.873254"],["535a7ad4.aca584"]]},{"id":"933c52e6.6cc3b","type":"http request","name":"","method":"GET","url":"","x":634,"y":302,"z":"adc463f6.523ba","wires":[["667124ff.998edc"]]},{"id":"667124ff.998edc","type":"switch","name":"Check HTTP status","property":"statusCode","rules":[{"t":"eq","v":200,"v2":0},{"t":"neq","v":200,"v2":0}],"checkall":"true","outputs":2,"x":703,"y":368,"z":"adc463f6.523ba","wires":[["4ed2e306.b12d1c"],["610e33b6.9ef1cc"]]},{"id":"4ed2e306.b12d1c","type":"function","name":"Extract data","func":"// Extract value\nvar msgValue = { payload:msg.payload.split(\"<b>\")[1]};\nmsgValue.payload = msgValue.payload.split(\"</b>\")[0];\n\n// Extract text\nvar msgText = { payload:msg.payload.split(\"<td colspan=\\\"2\\\" style=\\\"width:400px;text-align:justify;\\\">\")[1]};\nmsgText.payload = msgText.payload.split(\"</td>\")[0].replace( /\\r\\n/g, '<br />');\nreturn [msgValue, msgText];","outputs":"2","x":913,"y":296,"z":"adc463f6.523ba","wires":[["6f545820.0c87bc"],["f4fe71d7.0b019"]]},{"id":"38229254.c7dd6e","type":"mqtt out","name":"","topic":"/Garden/AirQuality/Value","qos":"0","retain":"false","broker":"53bd85c0.99ddac","x":1320.2222900390625,"y":270.5555419921875,"z":"adc463f6.523ba","wires":[]},{"id":"535a7ad4.aca584","type":"change","action":"replace","property":"payload","from":"","to":"Erreur - Impossible de récupérer le flux RSS de la polution de Grenoble","reg":false,"name":"Add error message","x":846.8888854980469,"y":493.8888969421387,"z":"adc463f6.523ba","wires":[["e031f776.1fce08"]]},{"id":"610e33b6.9ef1cc","type":"function","name":"Add error message","func":"msg.payload = \"Erreur - Impossible de récupérer le flux RSS de la polution de Grenoble @\" + msg.url\nreturn msg;","outputs":1,"x":851.0000381469726,"y":454.7777786254883,"z":"adc463f6.523ba","wires":[["e031f776.1fce08"]]},{"id":"e031f776.1fce08","type":"twitter out","twitter":"","name":"Tweet","x":1027.2222137451172,"y":471.1111011505127,"z":"adc463f6.523ba","wires":[]},{"id":"ff22b310.00dd5","type":"mqtt in","name":"","topic":"/Garden/AirQuality/Value","broker":"53bd85c0.99ddac","x":156.66666412353516,"y":681.222336769104,"z":"adc463f6.523ba","wires":[["f1eb78b4.0e1488"]]},{"id":"f1eb78b4.0e1488","type":"switch","name":"Select air quality","property":"payload","rules":[{"t":"btwn","v":0,"v2":4},{"t":"btwn","v":5,"v2":7},{"t":"btwn","v":8,"v2":10}],"checkall":"true","outputs":3,"x":374.4444274902344,"y":681.2222833633423,"z":"adc463f6.523ba","wires":[["4c889cf9.b37764"],["e042100f.1fbdf"],["783c080a.87c3f8"]]},{"id":"e042100f.1fbdf","type":"function","name":"Add warning","func":"msg.payload = \"Attention - Air polué : \" + msg.payload\nreturn msg;","outputs":1,"x":588.2222175598144,"y":680.3333387374878,"z":"adc463f6.523ba","wires":[["c19a1f41.3e65e"]]},{"id":"783c080a.87c3f8","type":"function","name":"Add danger","func":"msg.payload = \"Danger - Air très polué : \" + msg.payload\nreturn msg;","outputs":1,"x":584.4444580078125,"y":723.3333740234375,"z":"adc463f6.523ba","wires":[["c19a1f41.3e65e"]]},{"id":"c19a1f41.3e65e","type":"twitter out","twitter":"","name":"Tweet","x":973.3332633972168,"y":702.2222633361816,"z":"adc463f6.523ba","wires":[]},{"id":"44567d30.bba984","type":"comment","name":"Get the data from http://www.air-rhonealpes.fr","info":"1. Every hour, get the RSS feed from \"Air rhone alpes\"\n2. Parse it to find last report URL\n3. Get the report and extract the data","x":495.55555555555554,"y":156.66666666666666,"z":"adc463f6.523ba","wires":[]},{"id":"f4fe71d7.0b019","type":"mqtt out","name":"","topic":"/Garden/AirQuality/Text","qos":"0","retain":"false","broker":"53bd85c0.99ddac","x":1156.6666564941406,"y":349.9999656677246,"z":"adc463f6.523ba","wires":[]},{"id":"a01e6be9.5fe198","type":"comment","name":"Send notifications in case of polution","info":"","x":299.4444580078125,"y":588.3333129882812,"z":"adc463f6.523ba","wires":[]},{"id":"6f545820.0c87bc","type":"function","name":"Filter if no change","func":"// 20 can't be a valid number => Update on startup\ncontext.oldValue = context.oldValue || 20;\n\nif ( context.oldValue != msg.payload ) {\n\tcontext.oldValue = msg.payload;\n} else {\n\tmsg = null;\n}\nreturn msg;","outputs":1,"x":1095,"y":280,"z":"adc463f6.523ba","wires":[["38229254.c7dd6e"]]},{"id":"4c889cf9.b37764","type":"function","name":"Add ok","func":"msg.payload = \"OK - Air correct : \" + msg.payload\nreturn msg;","outputs":1,"x":572,"y":637,"z":"adc463f6.523ba","wires":[["c19a1f41.3e65e"]]}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment