Writing to InfluxDB from HTTP Advanced controller?

Moderators: Voyager, BertB, rtenklooster, Stuntteam, grovkillen, TD-er

Post Reply
Message
Author
spachal
Normal user
Posts: 38
Joined: 22 Feb 2018, 22:11

Writing to InfluxDB from HTTP Advanced controller?

#1 Post by spachal » 04 May 2018, 00:30

Hi, I'm trying to 'simplify' my project and write values from sensors directly to influxdb. And I found some problems ..

At first, here is my configuration (as illustrative example, it a little complicated IRL):
- raspberry pi3 with influxdb and grafana as db and visualization tool
- nodeMCU 7 espeasy with DHT11 as datasource
- rasspi and nodeMCU at the same subnet, working communication

I used it in the past solution with MQTT communication, using rules in espeasy I was sending payloads to rasppi and there was script MQTT > influxdb. I found that I can use espeasy to write values to influxdb directly via HTTP POST.
So far so good, I can configure espeasy with HTTP Advaced controller to write single value to influxdb without any problems. But the problem starts in the moment when I need to write more values, in this example case temperature and humidity at the same time.

Here is my configuration:
Image
Configuration of DHT11 device


Image
Configuration of controller


Image
log with successful communication


Image
values are in db correctly written

This is perfect, BUT .. I'm now trying to write also humidity, for example. By wiki it shoud be easy to do: https://www.letscontrolit.com/wiki/inde ... dvanced.29 .
So I tried to add another line, influxdb allows to write multiple points: https://docs.influxdata.com/influxdb/v1 ... ple-points
So I tried to modify HTTP Body with many combinations:

HTTP Body

Code: Select all

%tskname%%vname1% value=%val1%
%tskname%%vname2% value=%val2%
Result:

Code: Select all

222613 : HTTP/1.1 400 Bad Request
222613 : Content-Type: application/json
222614 : Request-Id: 324a86d3-4f1e-11e8-ba7e-000000000000
222615 : X-Influxdb-Build: OSS
222618 : X-Influxdb-Error: partial write: unable to parse 'dht11Temperature value=23.00 ': invalid number dropped=0

HTTP Body

Code: Select all

%tskname%%vname1% value=%val1%%LF%%tskname%%vname2% value=%val2%
Result:

Code: Select all

383698 : HTTP/1.1 400 Bad Request
383699 : Content-Type: application/json
383700 : Request-Id: 92503c17-4f1e-11e8-ba8e-000000000000
383700 : X-Influxdb-Build: OSS
383704 : X-Influxdb-Error: unable to parse 'dht11Temperature value=23.00%0adht11Humidity value=33.00': invalid number

I also tried a lot of combinations with \n, \r\n, hex and dec values .. there is obviously problem with end of line/new line character. I tried to put values to quotas, also without success..
I found here on forum picture of working configuration: https://imgur.com/a/RyjzU , in my case without any success.
This problem is probably described on GITHub, but without solution: https://github.com/letscontrolit/ESPEasy/issues/1306

So here are my questions, do you know any solution how to write multiple values from sensor in one POST?
I found the only solution so far to configure 'separate' controller for each sensor value (in this case two HTTP Advanced controllers). But I need to use multiple sensors in my project and in this case it means A LOT of controllers ;] ..

Any help? Thank you! :]
Please excuse my English, thanks!

Drum
Normal user
Posts: 260
Joined: 07 Feb 2016, 11:56

Re: Writing to InfluxDB from HTTP Advanced controller?

#2 Post by Drum » 14 May 2018, 19:20

I took the easy way out, ESP to Node-red to Sqlite on a RaspberryPi using MQTT.

Working on adding SQL Server (MariaDB) on a Qnap Nas. It is pretty easy to send things multiple places with Node-red.

spachal
Normal user
Posts: 38
Joined: 22 Feb 2018, 22:11

Re: Writing to InfluxDB from HTTP Advanced controller?

#3 Post by spachal » 19 May 2018, 20:16

Hi, thanks for info, and yes, it's possible to use MQTT for this. But on rasspi there must be another interface, which writes payloads from broker to database. And it's another 'thing that can be broken' and that's why I'd like to write to db directly from espeasy :] .. I can try to learn node-red, but I don't like it :))

IMHO it must be some 'very small problem', but I'm not programmer, I tried to solve it by myself in USES_C011 file, but without any success ..
Please excuse my English, thanks!

spachal
Normal user
Posts: 38
Joined: 22 Feb 2018, 22:11

Re: Writing to InfluxDB from HTTP Advanced controller?

#4 Post by spachal » 22 May 2018, 19:18

OK, I give it up ;], HTTP Advanced controller in unstable anyway (http://www.letscontrolit.com/forum/view ... f=6&t=5369), I changed my configuration to mqtt > node-red > influxdb, it works..
Please excuse my English, thanks!

water
Normal user
Posts: 10
Joined: 29 Jul 2018, 19:42

Re: Writing to InfluxDB from HTTP Advanced controller?

#5 Post by water » 07 Aug 2018, 13:12

Can you tell me how you used node-red mqtt and influxdb ? HTTP Advanced is indeed to unstable :)

moebius
Normal user
Posts: 33
Joined: 22 May 2017, 19:36

Re: Writing to InfluxDB from HTTP Advanced controller?

#6 Post by moebius » 07 Aug 2018, 14:51

Can you tell me how you used node-red mqtt and influxdb ?
In node-red you have an mqtt-in node, where you get the values from the esp's.
Now you prepare the data for influxdb with a change or function node and finally connect it to the influxdb node (has to be installed over palette).

water
Normal user
Posts: 10
Joined: 29 Jul 2018, 19:42

Re: Writing to InfluxDB from HTTP Advanced controller?

#7 Post by water » 08 Aug 2018, 13:07

moebius wrote:
07 Aug 2018, 14:51
Can you tell me how you used node-red mqtt and influxdb ?
In node-red you have an mqtt-in node, where you get the values from the esp's.
Now you prepare the data for influxdb with a change or function node and finally connect it to the influxdb node (has to be installed over palette).
Do I also need a broker something like mosquitto?

spachal
Normal user
Posts: 38
Joined: 22 Feb 2018, 22:11

Re: Writing to InfluxDB from HTTP Advanced controller?

#8 Post by spachal » 09 Aug 2018, 11:12

water wrote:
07 Aug 2018, 13:12
Can you tell me how you used node-red mqtt and influxdb ? HTTP Advanced is indeed to unstable :)
Hi, here is sample float of my solution, for BME280. In espeasy I send mqtt message to broker (rasppi+mosquito, IP 192.168.166.177), node-red reads these payloads and writes them to DB.

Image

Here is code, just paste it to node-red and modify as need. Feel free to delete all debug (green) parts.
[{"id":"af688d56.e4791","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"ac5cba56.bbe348","type":"mqtt in","z":"af688d56.e4791","name":"","topic":"/esp08test/bme280/Temperature","qos":"2","broker":"18ae8bba.64bfd4","x":170,"y":80,"wires":[["890298ea.ba33d8","37e7f14c.10f7de"]]},{"id":"890298ea.ba33d8","type":"function","z":"af688d56.e4791","name":"MQTT to InfluxDB","func":"var tokens = msg.topic.split(\"/\");\nvar dest = tokens[tokens.length-1];\nmsg.url =\"http://192.168.166.177:8086/write?db=se ... sg.payload = \"bme280temperature,device=\" + tokens[1] + \" value=\" + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":80,"wires":[["1c498182.64822e","c768f51c.911118"]]},{"id":"1c498182.64822e","type":"http request","z":"af688d56.e4791","name":"","method":"POST","ret":"txt","url":"http://192.168.166.177:8086/write?db=se ... :80,"wires":[["6c213ca8.148ba4"]]},{"id":"6c213ca8.148ba4","type":"debug","z":"af688d56.e4791","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":890,"y":180,"wires":[]},{"id":"c768f51c.911118","type":"debug","z":"af688d56.e4791","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":490,"y":180,"wires":[]},{"id":"37e7f14c.10f7de","type":"debug","z":"af688d56.e4791","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":170,"y":180,"wires":[]},{"id":"48067769.7a5a58","type":"mqtt in","z":"af688d56.e4791","name":"","topic":"/esp08test/bme280/Humidity","qos":"2","broker":"18ae8bba.64bfd4","x":160,"y":260,"wires":[["64bbab1d.3e0de4","de866f74.c3523"]]},{"id":"64bbab1d.3e0de4","type":"function","z":"af688d56.e4791","name":"MQTT to InfluxDB","func":"var tokens = msg.topic.split(\"/\");\nvar dest = tokens[tokens.length-1];\nmsg.url =\"http://192.168.166.177:8086/write?db=se ... sg.payload = \"bme280humidity,device=\" + tokens[1] + \" value=\" + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":260,"wires":[["fa5600a.c6a72","66a0de5a.5ac64"]]},{"id":"fa5600a.c6a72","type":"http request","z":"af688d56.e4791","name":"","method":"POST","ret":"txt","url":"http://192.168.166.177:8086/write?db=se ... 260,"wires":[["c620b24e.af1da"]]},{"id":"c620b24e.af1da","type":"debug","z":"af688d56.e4791","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":890,"y":360,"wires":[]},{"id":"66a0de5a.5ac64","type":"debug","z":"af688d56.e4791","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":490,"y":360,"wires":[]},{"id":"de866f74.c3523","type":"debug","z":"af688d56.e4791","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":170,"y":360,"wires":[]},{"id":"3b1395d.39aea6a","type":"mqtt in","z":"af688d56.e4791","name":"","topic":"/esp08test/bme280/Pressure","qos":"2","broker":"18ae8bba.64bfd4","x":160,"y":440,"wires":[["e14eea83.ed7178","864f30fb.6892c"]]},{"id":"e14eea83.ed7178","type":"function","z":"af688d56.e4791","name":"MQTT to InfluxDB","func":"var tokens = msg.topic.split(\"/\");\nvar dest = tokens[tokens.length-1];\nmsg.url =\"http://192.168.166.177:8086/write?db=se ... sg.payload = \"bme280pressure,device=\" + tokens[1] + \" value=\" + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":440,"wires":[["be503ac2.a5e488","6f28768f.87a598"]]},{"id":"be503ac2.a5e488","type":"http request","z":"af688d56.e4791","name":"","method":"POST","ret":"txt","url":"http://192.168.166.177:8086/write?db=se ... 440,"wires":[["69de5be3.e22d44"]]},{"id":"69de5be3.e22d44","type":"debug","z":"af688d56.e4791","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":890,"y":540,"wires":[]},{"id":"6f28768f.87a598","type":"debug","z":"af688d56.e4791","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":490,"y":540,"wires":[]},{"id":"864f30fb.6892c","type":"debug","z":"af688d56.e4791","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":170,"y":540,"wires":[]},{"id":"18ae8bba.64bfd4","type":"mqtt-broker","z":"","name":"","broker":"192.168.166.177","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
Please excuse my English, thanks!

Drum
Normal user
Posts: 260
Joined: 07 Feb 2016, 11:56

Re: Writing to InfluxDB from HTTP Advanced controller?

#9 Post by Drum » 09 Aug 2018, 12:23

I use a function to split the MQTT (openhab) message and post to SQlite I assume you can do something similar with any db
The DB has a auto number key field, datatime, unit, sensor, valname,value

var tokens = msg.topic.split("/");
var dest = tokens[tokens.length-1];
msg.topic = "INSERT INTO esptest2 (unit,sensor,valname,value) VALUES (?,?,?,?)";
msg.payload = [tokens[1],tokens[2],tokens[3],msg.payload];
return msg;

The MQTT msg is split on the "/"
8/9/2018, 11:49:54 AMf36e8624.e90148
/ESP-WiFiMod2/voltage/Voltage : msg.payload : string [4]
0.59

NodeRed also has nodes call "Switch" and "aggregator" which I use to split the msg by msg.topic and post hourly and daily Min and Max values to a separate table. It is an incredibly flexible system so there are always multiple ways to get the same result, based on what works best for you.
I also use a rule to post IP addresses on boot for units using deep sleep and switch to direct that msg to a table of IP addresses
Yeah, it is a bit of a mess, but it is a work in progress. The really nice thing is I can post to multiple databases at the same time. Eventually I will get it to post on a database on a NAS as well as a server.
The blue nodes are for a dashboard.....
The attachment Capture.JPG is no longer available
Capture.JPG
Capture.JPG (117.53 KiB) Viewed 980 times

Drum
Normal user
Posts: 260
Joined: 07 Feb 2016, 11:56

Re: Writing to InfluxDB from HTTP Advanced controller?

#10 Post by Drum » 09 Aug 2018, 12:25

This is the default test db table where everything gets posted. There are other tables for more specific data
db.JPG
db.JPG (82.75 KiB) Viewed 979 times

moebius
Normal user
Posts: 33
Joined: 22 May 2017, 19:36

Re: Writing to InfluxDB from HTTP Advanced controller?

#11 Post by moebius » 09 Aug 2018, 13:23

@drum: for more data, i would vote for influxdb (the built-in downsampling ability is really nice) in combination with grafana.
Also, it's not common to save everything in one table or to store aggregated/min/max values (usually done with queries).

@spachal: Nice sample for beginners.
Consider that, if you have more sensors, it will soon get confusing and hard to maintain (eg: if the ip address changes, you have to edit all request nodes).
A more efficient way would be, to derive the required data from the mqtt topic. So you would be able to store an unlimited number of bme sensors with only 3 nodes.

Here is an example - looks a little weird, cause i extracted it from a bigger flow (you need to have the node "node-red-contrib-influxdb" installed):

Code: Select all

[{"id":"101caa2c.161c66","type":"mqtt in","z":"c421dfeb.3e752","name":"","topic":"red/event/#","qos":"0","broker":"e36a332b.c61f3","x":243,"y":2214,"wires":[["b3315bcf.c85c88"]]},{"id":"b3315bcf.c85c88","type":"json","z":"c421dfeb.3e752","name":"","x":376,"y":2223,"wires":[["fbd0ec8.0bb921"]]},{"id":"fbd0ec8.0bb921","type":"change","z":"c421dfeb.3e752","name":"prep","rules":[{"t":"set","p":"payload.id","pt":"msg","to":"undefined","tot":"jsonata"},{"t":"set","p":"payload.name","pt":"msg","to":"undefined","tot":"jsonata"},{"t":"set","p":"device","pt":"msg","to":"$split(msg.topic, \"/\")[4]","tot":"jsonata"},{"t":"set","p":"measurement","pt":"msg","to":"event","tot":"str"},{"t":"set","p":"system","pt":"msg","to":"$split(msg.topic, \"/\")[3]","tot":"jsonata"},{"t":"set","p":"payload.system","pt":"msg","to":"undefined","tot":"jsonata"},{"t":"set","p":"type","pt":"msg","to":"$split(msg.topic, \"/\")[2]","tot":"jsonata"},{"t":"set","p":"payload.label","pt":"msg","to":"undefined","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":517,"y":2247,"wires":[["a9693cdf.3db24"]]},{"id":"a9693cdf.3db24","type":"function","z":"c421dfeb.3e752","name":"prepare data","func":"newmsg = {}\nnewmsg.payload = {}\nnewmsg.measurement = msg.measurement;\n\nif (typeof msg.payload === \"object\") {\n    for (var key in msg.payload) {\n        if (isNumeric(msg.payload[key]) && msg.measurement != \"event\") {\n             newmsg.payload[key] = parseFloat(msg.payload[key]);\n        } else {\n            newmsg.payload[key] = msg.payload[key];\n        }\n    }\n} else {\n    if (isNumeric(msg.payload[key]) && msg.measurement != \"event\") {\n         newmsg.payload.value = parseFloat(msg.payload);\n    } else {\n        newmsg.payload.value = msg.payload;\n    }\n}\n\n//add tag \"Device\"\nnewmsg.payload = [ newmsg.payload, { \"Device\": msg.device} ];\n//add tag \"Beacon\"\nif (msg.beacon !== undefined)\n    newmsg.payload[1].Beacon = msg.beacon;\n//add tag \"Location\"    \nif (msg.location !== undefined)\n    newmsg.payload[1].Location = msg.location;\n//add tag \"function\"    \nif (msg.function !== undefined)\n    newmsg.payload[1].Function = msg.function;\n//add tag \"system\"    \nif (msg.system !== undefined)\n    newmsg.payload[1].system = msg.system;\n//add tag \"type\"    \nif (msg.type !== undefined)\n    newmsg.payload[1].type = msg.type;    \n    \nreturn newmsg;\n\nfunction isNumeric(n) {\n  return !isNaN(parseFloat(n)) && isFinite(n);\n}\n","outputs":"1","noerr":0,"x":694,"y":2275,"wires":[["4e0f7466.7ef02c"]]},{"id":"4e0f7466.7ef02c","type":"influxdb out","z":"c421dfeb.3e752","influxdb":"970191b.79d187","name":"","measurement":"","precision":"","retentionPolicy":"","x":872,"y":2300,"wires":[]},{"id":"e36a332b.c61f3","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"15","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"970191b.79d187","type":"influxdb","z":"","hostname":"192.168.4.240","port":"8086","protocol":"http","database":"infra","name":"opi_infra","usetls":false,"tls":""}]
Attachments
Clipboard02.jpg
Almost whole flow
Clipboard02.jpg (163.33 KiB) Viewed 1060 times
Clipboard01.jpg
Example
Clipboard01.jpg (12.35 KiB) Viewed 1060 times

water
Normal user
Posts: 10
Joined: 29 Jul 2018, 19:42

Re: Writing to InfluxDB from HTTP Advanced controller?

#12 Post by water » 11 Aug 2018, 19:53

spachal wrote:
09 Aug 2018, 11:12
water wrote:
07 Aug 2018, 13:12
Can you tell me how you used node-red mqtt and influxdb ? HTTP Advanced is indeed to unstable :)
Hi, here is sample float of my solution, for BME280. In espeasy I send mqtt message to broker (rasppi+mosquito, IP 192.168.166.177), node-red reads these payloads and writes them to DB.
For some reason I can't import this flow?

moebius
Normal user
Posts: 33
Joined: 22 May 2017, 19:36

Re: Writing to InfluxDB from HTTP Advanced controller?

#13 Post by moebius » 12 Aug 2018, 12:53

@water: the flow from @spachal is in quotes instead of code tags and the forum modifies such strings somehow.

You could also try to reconstruct his flow - only the 3 nodes: mqtt -> function -> request. Code and settings you can see in his export.

water
Normal user
Posts: 10
Joined: 29 Jul 2018, 19:42

Re: Writing to InfluxDB from HTTP Advanced controller?

#14 Post by water » 12 Aug 2018, 13:03

moebius wrote:
09 Aug 2018, 13:23
@drum: for more data, i would vote for influxdb (the built-in downsampling ability is really nice) in combination with grafana.
Also, it's not common to save everything in one table or to store aggregated/min/max values (usually done with queries).

@spachal: Nice sample for beginners.
Consider that, if you have more sensors, it will soon get confusing and hard to maintain (eg: if the ip address changes, you have to edit all request nodes).
A more efficient way would be, to derive the required data from the mqtt topic. So you would be able to store an unlimited number of bme sensors with only 3 nodes.

Here is an example
Cool, this works in my case. But I want to sort the data a bit. How can I adjust your settings so I can use this in grafana SELECT mean("value") FROM "dust sensor" WHERE ("DHT22" = 'Humidity') AND $timeFilter GROUP BY time($__interval) fill(null)

moebius
Normal user
Posts: 33
Joined: 22 May 2017, 19:36

Re: Writing to InfluxDB from HTTP Advanced controller?

#15 Post by moebius » 12 Aug 2018, 13:44

@water: there is nothing to sort, when you store data in the database
Also your sql select is a little confusing, cause you have the humidity data from a dht22 in the table "dust sensor".

In order to help you, you should export your current flow and describe exactly what you want to achieve.

water
Normal user
Posts: 10
Joined: 29 Jul 2018, 19:42

Re: Writing to InfluxDB from HTTP Advanced controller?

#16 Post by water » 12 Aug 2018, 13:50

moebius wrote:
12 Aug 2018, 13:44
@water: there is nothing to sort, when you store data in the database
Also your sql select is a little confusing, cause you have the humidity data from a dht22 in the table "dust sensor".

In order to help you, you should export your current flow and describe exactly what you want to achieve.
Well, in grafana I want to get data from 'device 1' which has 2 sensors. The DHT22 and SDS011. SELECT mean("value") FROM "Device1" WHERE ("DHT22" = 'Humidity') AND $timeFilter GROUP BY time($__interval) fill(null)

maybe this is a little less confusing. From Device1 I want to make a graph from DHT22 to show the humidity. And in an other graph I want to select the temperature from DHT22 from device1

when I use your flow I can only use this in Grafana SELECT mean("value") FROM "Device1" WHERE ("system" = 'Temperature') AND $timeFilter GROUP BY time($__interval) fill(none)
What I want to achieve is that 'system' will change to the sensorname like DHT22, SDS011

moebius
Normal user
Posts: 33
Joined: 22 May 2017, 19:36

Re: Writing to InfluxDB from HTTP Advanced controller?

#17 Post by moebius » 12 Aug 2018, 14:09

If you use my flow to store the data without modification, you have to adjust the mqtt topic (cause this defines most parameters for the influxdb insert statement).
If you cannot change the mqtt topic, you have to adapt the change node to your needs...

Maybe you can you provide a sample message...

spachal
Normal user
Posts: 38
Joined: 22 Feb 2018, 22:11

Re: Writing to InfluxDB from HTTP Advanced controller?

#18 Post by spachal » 12 Aug 2018, 14:22

moebius wrote:
12 Aug 2018, 12:53
@water: the flow from @spachal is in quotes instead of code tags and the forum modifies such strings somehow.

You could also try to reconstruct his flow - only the 3 nodes: mqtt -> function -> request. Code and settings you can see in his export.
My bed, sorry for that, this is export of temperarure part only, in code:

Code: Select all

[{"id":"c854d5dd.78c568","type":"mqtt in","z":"a458e657.149bd8","name":"","topic":"/esp08test/bme280/Temperature","qos":"2","broker":"18ae8bba.64bfd4","x":210,"y":60,"wires":[["caef4d9b.7a6de"]]},{"id":"caef4d9b.7a6de","type":"function","z":"a458e657.149bd8","name":"MQTT to InfluxDB","func":"var tokens = msg.topic.split(\"/\");\nvar dest = tokens[tokens.length-1];\nmsg.url =\"http://192.168.166.177:8086/write?db=senzory\";\nmsg.payload = \"bme280temperature,device=\" + tokens[1] + \" value=\" + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":60,"wires":[["b8b60563.7da688"]]},{"id":"b8b60563.7da688","type":"http request","z":"a458e657.149bd8","name":"","method":"POST","ret":"txt","url":"http://192.168.166.177:8086/write?db=senzory","tls":"","x":890,"y":60,"wires":[[]]},{"id":"18ae8bba.64bfd4","type":"mqtt-broker","z":"","name":"","broker":"192.168.166.177","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
I know that this is only very simple example, but I don't need any pro solution, I'm the beginner and my project is pretty simple too :] ..

In Grafana you can define data source and use data stored in ifluxdb for your graphs. Here is my example of metioned BME280 sensor:
Image

Great post about grafana ans inluxdb (for openhab) is here: https://community.openhab.org/t/influxd ... hing/13761
Please excuse my English, thanks!

water
Normal user
Posts: 10
Joined: 29 Jul 2018, 19:42

Re: Writing to InfluxDB from HTTP Advanced controller?

#19 Post by water » 12 Aug 2018, 15:47

spachal wrote:
12 Aug 2018, 14:22
moebius wrote:
12 Aug 2018, 12:53
@water: the flow from @spachal is in quotes instead of code tags and the forum modifies such strings somehow.

You could also try to reconstruct his flow - only the 3 nodes: mqtt -> function -> request. Code and settings you can see in his export.
Great post about grafana ans inluxdb (for openhab) is here: https://community.openhab.org/t/influxd ... hing/13761
Thanks. Im almost there
Do you know how I can replace make the next line
msg.payload = tokens[2] + ",measurement=" + tokens[3] + ",device=" + tokens[1] + " value=" + msg.payload;
to
msg.payload = tokens[1] + ",tokens[2]=" + tokens[3] + " value=" + msg.payload; <-- this one doesn't work but I haven't figured out how I can use tokens between quotes
Got it. I´ve used msg.payload = tokens[1] + "," + tokens[2] + "=" + tokens[3] + " value=" + msg.payload;

This is my flow and all works :) thanks

Code: Select all

[{"id":"2b0d8d3b.42b4b2","type":"mosca in","z":"56cdfe17.c0006","mqtt_port":1883,"mqtt_ws_port":8080,"name":"","username":"","password":"","dburl":"","x":670,"y":1280,"wires":[["8103799d.e68a78"]]},{"id":"8103799d.e68a78","type":"debug","z":"56cdfe17.c0006","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":870,"y":1280,"wires":[]},{"id":"1ba5a1e.79e5b5e","type":"mqtt in","z":"56cdfe17.c0006","name":"DHT22","topic":"/Stofzuiger/#","qos":"2","broker":"c807f5b7.930c28","x":630,"y":1340,"wires":[["2a67beee.8d3eb2"]]},{"id":"1bba56f2.6a8bf9","type":"debug","z":"56cdfe17.c0006","name":"debuginfo","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1040,"y":1420,"wires":[]},{"id":"2a67beee.8d3eb2","type":"function","z":"56cdfe17.c0006","name":"MQTT to InfluxDB","func":"var tokens = msg.topic.split(\"/\");\nvar dest = tokens[tokens.length-1];\nmsg.url =\"http://xxx.xx.18.133:8086/write?db=test\";\nmsg.payload = tokens[1] + \",\" + tokens[2] + \"=\" + tokens[3] + \" value=\" + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":830,"y":1340,"wires":[["3d87de37.627cd2","1bba56f2.6a8bf9"]]},{"id":"3d87de37.627cd2","type":"http request","z":"56cdfe17.c0006","name":"","method":"POST","ret":"txt","url":"http://xxx.xx.18.133:8086/write?db=test","tls":"","x":1050,"y":1340,"wires":[[]]},{"id":"c807f5b7.930c28","type":"mqtt-broker","z":"","name":"","broker":"xxx.xx.18.133","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests