node-red - thingSpeak

En aquesta pràctica utilitzarem la nodeMCU per mesurar temperatura, humitat i nivell d'il·luminació. Les dades analògiques més l'upTime les enviarem a la plataforma del núvol thingSpeak per tal de visualitzar-les en gràfiques. Primer ens haurem de crear un compte. Després farem un nou canal segons aquest tutorial. En aquest altre podem veure com instal·lar la llibreria per Arduino.

Aquí tenim un exemple de visualització.

Connectarem un DHT11 a la GPIO0 (Q0), un DS18B20 a la GPIO2 (Q2) i una LDR a l'entrada analògica. Els sensors de temperatura cal alimentar-los a 3,3V!!

L'aplicació podria semblar-se a aquesta:

I l'sketch aquest:

Importa aquest flow i configura'l amb el teu canal de thingSpeak.

[{"id":"7b3baab4.bb9424","type":"inject","z":"4d3bfa25.536b34","name":"Cada 30''","topic":"","payload":"","payloadType":"date","repeat":"30","crontab":"","once":false,"x":194.83343505859375,"y":549.111083984375,"wires":[["ca452e2.671e9d","41a291a9.e4fbc","ca08883f.5557e","f80346de.cabc8"]]},{"id":"ca452e2.671e9d","type":"http request","z":"4d3bfa25.536b34","name":"GET V0 il·luminació","method":"GET","ret":"obj","url":"http://vps249990.ovh.net:8080/e3a46512f9884b7495e9ff5fa2932e9c/get/V0","tls":"","x":561.7223510742188,"y":440.333251953125,"wires":[["f319fbcb.ad18e"]]},{"id":"f319fbcb.ad18e","type":"function","z":"4d3bfa25.536b34","name":"str to int, topic","func":"var value=parseInt(msg.payload);\nmsg.payload = value;\nmsg.topic=\"ilum\";\nreturn msg;\n","outputs":1,"noerr":0,"x":850.166748046875,"y":440.22222900390625,"wires":[["c48f3249.4aed18"]]},{"id":"41a291a9.e4fbc","type":"http request","z":"4d3bfa25.536b34","name":"GET V24 tDS","method":"GET","ret":"obj","url":"http://vps249990.ovh.net:8080/e3a46512f9884b7495e9ff5fa2932e9c/get/V24","tls":"","x":539.6668701171875,"y":525.8888549804688,"wires":[["5c7dcd2d.04c8fc"]]},{"id":"5c7dcd2d.04c8fc","type":"function","z":"4d3bfa25.536b34","name":"str to int, topic","func":"var value=parseInt(msg.payload);\nmsg.payload = value;\nmsg.topic=\"tDS\";\nreturn msg;\n","outputs":1,"noerr":0,"x":843.666748046875,"y":520.2222290039062,"wires":[["c48f3249.4aed18"]]},{"id":"a1063ece.9453f8","type":"comment","z":"4d3bfa25.536b34","name":"enviament multiple a thingSpeak","info":"","x":189.44442749023438,"y":482.22222900390625,"wires":[]},{"id":"ca08883f.5557e","type":"http request","z":"4d3bfa25.536b34","name":"GET V25 tDHT","method":"GET","ret":"obj","url":"http://vps249990.ovh.net:8080/e3a46512f9884b7495e9ff5fa2932e9c/get/V25","tls":"","x":543.5556640625,"y":596.7777099609375,"wires":[["bdf2a94d.3046a8"]]},{"id":"bdf2a94d.3046a8","type":"function","z":"4d3bfa25.536b34","name":"str to int, topic","func":"var value=parseInt(msg.payload);\nmsg.payload = value;\nmsg.topic=\"tDHT\";\nreturn msg;\n","outputs":1,"noerr":0,"x":845.333251953125,"y":593.3334350585938,"wires":[["c48f3249.4aed18"]]},{"id":"f80346de.cabc8","type":"http request","z":"4d3bfa25.536b34","name":"GET V26 humitat","method":"GET","ret":"obj","url":"http://vps249990.ovh.net:8080/e3a46512f9884b7495e9ff5fa2932e9c/get/V26","tls":"","x":559.1112060546875,"y":671.2222900390625,"wires":[["ee26644b.d1dfa8"]]},{"id":"ee26644b.d1dfa8","type":"function","z":"4d3bfa25.536b34","name":"str to int, topic","func":"var value=parseInt(msg.payload);\nmsg.payload = value;\nmsg.topic=\"humitat\";\nreturn msg;\n","outputs":1,"noerr":0,"x":846.444580078125,"y":672.2223510742188,"wires":[["c48f3249.4aed18"]]},{"id":"673e5161.f3d3d","type":"ThingspeakSendSimple","z":"4d3bfa25.536b34","name":"","writekey":"HEX4NZBPRNKFC4R8","fieldid":"3","x":1114.2222900390625,"y":317.00006103515625,"wires":[]},{"id":"c48f3249.4aed18","type":"thingspeak42","z":"4d3bfa25.536b34","name":"","delay":"15","topic1":"ilum","topic2":"tDS","topic3":"","topic4":"tDHT","topic5":"humitat","topic6":"","topic7":"","topic8":"","endpoint":"https://thingspeak.com","x":1114.9996337890625,"y":555.5554809570312,"wires":[]},{"id":"5ef6e947.9d8f2","type":"function","z":"4d3bfa25.536b34","name":"str to int","func":"var value=parseInt(msg.payload);\nmsg.payload = value;\nreturn msg;\n","outputs":1,"noerr":0,"x":820.0001220703125,"y":318.8888244628906,"wires":[["673e5161.f3d3d","832fcc79.9592c"]]},{"id":"e3619.f08dd1e7","type":"http request","z":"4d3bfa25.536b34","name":"GET V16 upTime","method":"GET","ret":"obj","url":"http://vps249990.ovh.net:8080/e3a46512f9884b7495e9ff5fa2932e9c/get/V16","tls":"","x":544.4444580078125,"y":321.111083984375,"wires":[["5ef6e947.9d8f2"]]},{"id":"ab9fa3d3.aadd08","type":"inject","z":"4d3bfa25.536b34","name":"Cada minut","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":false,"x":187.22222900390625,"y":323.3332824707031,"wires":[["e3619.f08dd1e7"]]},{"id":"832fcc79.9592c","type":"debug","z":"4d3bfa25.536b34","name":"","active":true,"console":"false","complete":"false","x":1016.111083984375,"y":245.5555419921875,"wires":[]},{"id":"87a75981.fd2f8","type":"comment","z":"4d3bfa25.536b34","name":"enviament simple a thingSpeak","info":"","x":200,"y":267.77777099609375,"wires":[]}]