From 33749b4edd864f646b336b4430cd6ce7a9e30fc6 Mon Sep 17 00:00:00 2001 From: Michael Wyraz Date: Sun, 29 Sep 2019 20:02:05 +0200 Subject: [PATCH] Add another example that sends values to influxdb --- examples/rain_to_influx.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 examples/rain_to_influx.md diff --git a/examples/rain_to_influx.md b/examples/rain_to_influx.md new file mode 100644 index 0000000..741fda2 --- /dev/null +++ b/examples/rain_to_influx.md @@ -0,0 +1,18 @@ +# Sending rain data (and other sensor data) to influxdb + +This script subscribes to a certain topic and sends all incoming values to influxdb database "iotdata". The values are tagged with a sensor id extracted from the topic. + +The script: + +```javascript +var request = require('request'); + +subscribe('sensor/+/rainDelta', function (topic,val,obj,prev,msg) { + var sensorId=topic.split("/")[1]; + data='rain_amount,sensor='+sensorId+' value='+val; + request.post({ + url: 'https://influxdb.example.com/write?db=iotdata', + body: data + }); +}); +```