Saving data received from MQTT to InfluxDB
My NodeMCU are sending data using MQTT to the broker. Then this flow get the topic and the data and save on InfluxDB using its HTTP API. After I use Grafana to show the data graphics.
http://jeanbrito.com/2016/02/24/saving-data-received-from-mqtt-to-influxdb-using-node-red/
[{"id":"e8ee0bf9.1711f8","type":"mqtt-broker","z":"5b94f478.a46b0c","broker":"localhost","port":"1883","clientid":"node-red","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"15","cleansession":true,"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":""},{"id":"2122f69.fdedd0a","type":"mqtt in","z":"5b94f478.a46b0c","name":"","topic":"sensors/#","broker":"e8ee0bf9.1711f8","x":377,"y":154,"wires":[["bbed4e22.4412b"]]},{"id":"bbed4e22.4412b","type":"function","z":"5b94f478.a46b0c","name":"MQTT to InfluxDB","func":"var tokens = msg.topic.split(\"/\");\nvar dest = tokens[tokens.length-1];\nmsg.url =\"http://localhost:8086/write?db=greenhouse\";\nmsg.payload = tokens[2] + \",device=\" + tokens[1] + \" value=\" + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":596,"y":156,"wires":[["92e875bf.6d1788","7804637a.87fb9c"]]},{"id":"92e875bf.6d1788","type":"http request","z":"5b94f478.a46b0c","name":"","method":"POST","ret":"txt","url":"http://localhost:8086/write?db=greenhouse","x":819,"y":155,"wires":[["989defec.67621"]]},{"id":"989defec.67621","type":"debug","z":"5b94f478.a46b0c","name":"","active":true,"console":"false","complete":"true","x":1013,"y":154,"wires":[]},{"id":"7804637a.87fb9c","type":"debug","z":"5b94f478.a46b0c","name":"","active":true,"console":"false","complete":"false","x":803,"y":295,"wires":[]}]