Post data to InfluxDB

There is another flow that outputs data to Influx but it isn't a complete example and it uses a confusing Function node.

This example uses a Template node to correctly format the record for POSTing.

The example is taken from my home automation hub and shows the ping results from a Raspberry Pi 2 to two devices on the network, my router and my NAS.

These are posted to the database (called "domotica") in the form:

network,device={{topic}} value={{payload}}

Where "network" is the measure (like a table in SQL) and "device" is a tag.

You can easily then graph the data using Grafana using a query like:

SELECT mean("value") FROM "network" WHERE "device" =~ /NAS$/ AND $timeFilter GROUP BY time($interval) fill(null)

Note that the data is also written out to MQTT.

Capture

Installing Influx on a Raspberry Pi is not as easy as it should be. They do not publish ARM versions so you need to source it elsewhere. Padcom's Blog has some pre-compiled binaries, not the latest versions but they work just fine. Otherwise, you need to start by installing the Go language which is a marathon in its own right. Installing via GVM is probably easiest. Or maybe try this though I've not tried it myself.

One installed and running though, it is easy to create nice dashboards using Grafana.

[{"id":"3b2726f7.c4d8da","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"Pi2_NR-Live","usetls":false,"verifyservercert":true,"compatmode":false,"keepalive":"15","cleansession":true,"willTopic":"DEVICES/PI2NR-LIVE","willQos":"1","willRetain":"false","willPayload":"Offline","birthTopic":"DEVICES/PI2NR-LIVE","birthQos":"1","birthRetain":"false","birthPayload":"Online"},{"id":"8f2636c6.70d9c8","type":"ping","z":"106a5b82.ef95a4","name":"NAS","host":"192.168.1.2","timer":"20","x":90,"y":580,"wires":[["67f7d6c0.980828"]]},{"id":"254dbbd2.dab244","type":"ping","z":"106a5b82.ef95a4","name":"Router","host":"192.168.1.1","timer":"20","x":90,"y":640,"wires":[["320ac6fd.cdf53a"]]},{"id":"207b9895.df8468","type":"mqtt out","z":"106a5b82.ef95a4","name":"","topic":"","qos":"2","retain":"false","broker":"3b2726f7.c4d8da","x":430,"y":580,"wires":[]},{"id":"111b77b8.eee488","type":"debug","z":"106a5b82.ef95a4","name":"Check Influx Add Record","active":false,"console":"false","complete":"true","x":950,"y":640,"wires":[]},{"id":"fae034e2.051fc8","type":"http request","z":"106a5b82.ef95a4","name":"Post to Influx DB (domotica)","method":"POST","ret":"txt","url":"http://localhost:8086/write?db=domotica","x":700,"y":640,"wires":[["111b77b8.eee488"]]},{"id":"f9c2968b.063d68","type":"template","z":"106a5b82.ef95a4","name":"Fmt Influx Output","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"network,device={{topic}} value={{payload}}","x":470,"y":640,"wires":[["fae034e2.051fc8"]]},{"id":"67f7d6c0.980828","type":"change","z":"106a5b82.ef95a4","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"DEVICES/IP/NAS","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":580,"wires":[["f9c2968b.063d68","207b9895.df8468"]]},{"id":"320ac6fd.cdf53a","type":"change","z":"106a5b82.ef95a4","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"DEVICES/IP/Router","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":640,"wires":[["207b9895.df8468","f9c2968b.063d68"]]}]

Flow Info

Created 9 years, 7 months ago
Updated 9 years, 6 months ago
Rating: not yet rated

Actions

Rate:

Node Types

Core
  • change (x2)
  • debug (x1)
  • http request (x1)
  • mqtt out (x1)
  • mqtt-broker (x1)
  • template (x1)
Other
  • ping (x2)

Tags

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