Writing HTTP request values to InfluxDB

As a newbie I discover problems writing measurements to my InfluxDB. The flow writes msg.payload.latest.data to the debug frame but I did not succeed writing msg.payload.latest.data to the database. When I connect InfluxDB Out node (image) errors are generated after deploy was pressed. Can someone give me some advice how to do this?

[{"id":"ef1759b1.fd5458","type":"tab","label":"NAP Rivieren","disabled":false,"info":""},{"id":"deb83872.9cb878","type":"inject","z":"ef1759b1.fd5458","name":"240'","topic":"","payload":"","payloadType":"date","repeat":"14400","crontab":"","once":true,"onceDelay":0.1,"x":130,"y":120,"wires":[["6ea47c05.07f344"]]},{"id":"6ea47c05.07f344","type":"http request","z":"ef1759b1.fd5458","name":"HTTP Request TL","method":"GET","ret":"obj","url":"https://waterinfo.rws.nl/api/detail?expertParameter=Waterhoogte___20Oppervlaktewater___20t.o.v.___20Normaal___20Amsterdams___20Peil___20in___20cm&locationSlug=Tiel-Waal%28TIEW%29&user=publiek","tls":"","x":346,"y":120,"wires":[["9a26b8fe.0268f8"]]},{"id":"898effc4.20b8b","type":"debug","z":"ef1759b1.fd5458","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.latest.data","x":630,"y":220,"wires":[]},{"id":"be5a1a94.89d3b8","type":"inject","z":"ef1759b1.fd5458","name":"240'","topic":"","payload":"","payloadType":"date","repeat":"14400","crontab":"","once":true,"onceDelay":0.1,"x":130,"y":220,"wires":[["5ab297d7.54e4e8"]]},{"id":"5ab297d7.54e4e8","type":"http request","z":"ef1759b1.fd5458","name":"HTTP Request RH","method":"GET","ret":"obj","url":"https://waterinfo.rws.nl/api/detail?expertParameter=Waterhoogte___20Oppervlaktewater___20t.o.v.___20Normaal___20Amsterdams___20Peil___20in___20cm&locationSlug=Grebbe%28GREB%29&user=publiek","tls":"","x":346,"y":220,"wires":[["898effc4.20b8b"]]},{"id":"9a26b8fe.0268f8","type":"debug","z":"ef1759b1.fd5458","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.latest.data","x":630,"y":120,"wires":[]}]

Would be helpful to see the errors as well otherwise it is hard to see what is going on.

Hi. Below the error message in the debug frame.

Error: A 400 Bad Request error occurred: {"error":"unable to parse 'naprhenen explanation=\"Waterhoogte t.o.v. NAP\",latest=[object Object],location=\"Grebbe\",range=[object Object],[object Object],[object Object],[object Object],related=[object Object],title=\"Waterhoogte Oppervlaktewater t.o.v. Normaal Amsterdams Peil in cm\"': invalid boolean"}

The debug output does not match with your flow.
You cannot send the http request output directly to influx without giving it some properties.

Can you post the full flow ?

Thanks (again) for your help! Below the flow.

[{"id":"84366ae3.ae6af8","type":"tab","label":"Forum","disabled":false,"info":""},{"id":"2afe8879.31fad8","type":"debug","z":"84366ae3.ae6af8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.latest.data","x":690,"y":120,"wires":[]},{"id":"997c8c6f.6b3cc","type":"inject","z":"84366ae3.ae6af8","name":"240'","topic":"","payload":"","payloadType":"date","repeat":"14400","crontab":"","once":true,"onceDelay":0.1,"x":210,"y":160,"wires":[["86f0906b.5eaaa"]]},{"id":"86f0906b.5eaaa","type":"http request","z":"84366ae3.ae6af8","name":"HTTP Request RH","method":"GET","ret":"obj","url":"https://waterinfo.rws.nl/api/detail?expertParameter=Waterhoogte___20Oppervlaktewater___20t.o.v.___20Normaal___20Amsterdams___20Peil___20in___20cm&locationSlug=Grebbe%28GREB%29&user=publiek","tls":"","x":426,"y":160,"wires":[["2afe8879.31fad8","283d7e14.bb5192"]]},{"id":"283d7e14.bb5192","type":"influxdb out","z":"84366ae3.ae6af8","influxdb":"e0390dc7.802ec","name":"naprhenen (192.168.2.185)","measurement":"number","precision":"","retentionPolicy":"","x":700,"y":200,"wires":[]},{"id":"e0390dc7.802ec","type":"influxdb","z":"","hostname":"192.168.2.185","port":"8086","protocol":"http","database":"naprhenen","name":"naprhenen","usetls":false,"tls":""}]

It looks to me as though you've passed the data to the http-request in the wrong way. It is the request that has failed, not InfluxDB?

You are trying to insert the full msg.payload, while you only want to insert 1 number, correct?

[{"id":"dddf8f83.722368","type":"debug","z":"74695533.ac3f94","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.latest.data","x":690,"y":120,"wires":[]},{"id":"f10d7bad.54f5f8","type":"inject","z":"74695533.ac3f94","name":"240'","topic":"","payload":"","payloadType":"date","repeat":"14400","crontab":"","once":true,"onceDelay":0.1,"x":210,"y":160,"wires":[["6e09bb46.0df33c"]]},{"id":"6e09bb46.0df33c","type":"http request","z":"74695533.ac3f94","name":"HTTP Request RH","method":"GET","ret":"obj","url":"https://waterinfo.rws.nl/api/detail?expertParameter=Waterhoogte___20Oppervlaktewater___20t.o.v.___20Normaal___20Amsterdams___20Peil___20in___20cm&locationSlug=Grebbe%28GREB%29&user=publiek","tls":"","x":426,"y":160,"wires":[["dddf8f83.722368","7db54950.5f3548"]]},{"id":"4573f40f.73fa1c","type":"influxdb out","z":"74695533.ac3f94","influxdb":"f3388bfa.998be","name":"naprhenen (192.168.2.185)","measurement":"number","precision":"","retentionPolicy":"","x":780,"y":242,"wires":[]},{"id":"7db54950.5f3548","type":"change","z":"74695533.ac3f94","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.latest.data","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":542,"y":220,"wires":[["4573f40f.73fa1c"]]},{"id":"f3388bfa.998be","type":"influxdb","z":"","hostname":"192.168.2.185","port":"8086","protocol":"http","database":"naprhenen","name":"naprhenen","usetls":false,"tls":""}]

@ TotallyInformation:
I'm afraid you're right :wink:

Hi Bakman2. Still no "overstroming" here and thanks for helping. Your flow runs without errors. You're right, I only want to use one number (waterhoogte in cm) and now struggling to write this value to the DB :frowning:

Hi Bakman2, can you tell me what I have to fill in the field below? I did several tries so far but none writes the value in the database.

What are you using in influx, telegraf ?

I use InfluxDB and write only that value (waterhoogte) in the database, nothing else. The same as in another database I use, below the Influx output of "select * from dbname" of that database.

One issue with InfluxDB is that, once you've written a certain data type to a measurement, you can't then change the type. So if you wrote the text of the error message and then try to write a number, that will fail.

Either way, assuming you now have the request working, we need to see the actual error that InfluxDB is generating.

Hi Julian. To prevent the problem you describe I now have created a new Influx database and tried to write to the DB (with the text below in the Influx DB Out Node measurement field) without succes:

number
.msg.payload.latest.data
.payload.latest.data
.latest.data

None of them worked, The NodeRED debug screen show the right value 601.

debug

That is the output from the request, it doesn't show us what is happening with InfluxDB. You need to share some kind of output from it otherwise we can't know what is going on.

No problem to post that info but I really don't know how the get it out of InfluxDB. I've installed Telegraf but so far no success viewing any errorlog.

Point is, is that you will have to specify the database, table and the field(s).

Example for telegraf.

Function node:

lux = msg.payload.CurrentAmbientLightLevel

msg.payload = [
    {
        measurement:"homeautomation",
        fields: {
           lux:lux
        },
        tags:{
            homeautomation:"light_sensor1"
        },
        timestamp: new Date()
    }];

return msg

Connect this to a influx batch node.
tags are optional.

Then you can select lux from homeautomation

Thanks for helping!

I think that the log should be accessible from something like (I'm not at my Pi's) journalctl influxdb. But I would expect the InfluxDB node to produce some output as well.

For now most seems to work and the payload contains what I need as shown in the NodeRED debugger. Only writing the payload to the Influx database is still not working, no errors are reported after deploying the flow and Chronograf also does not show errors. The Influx command "select * from Test" does not show errors but also no values. Any suggestions to write the payload to the database are welcome.

[{"id":"e01e747b.b23d98","type":"tab","label":"Alleen waarde","disabled":false,"info":""},{"id":"be5d4c7.8bd90b","type":"debug","z":"e01e747b.b23d98","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":670,"y":200,"wires":[]},{"id":"792d7094.7136b","type":"inject","z":"e01e747b.b23d98","name":"240'","topic":"","payload":"","payloadType":"date","repeat":"14400","crontab":"","once":true,"onceDelay":0.1,"x":130,"y":220,"wires":[["82b59b92.ef6288"]]},{"id":"82b59b92.ef6288","type":"http request","z":"e01e747b.b23d98","name":"HTTP Request RH","method":"GET","ret":"obj","url":"https://waterinfo.rws.nl/api/detail?expertParameter=Waterhoogte___20Oppervlaktewater___20t.o.v.___20Normaal___20Amsterdams___20Peil___20in___20cm&locationSlug=Grebbe%28GREB%29&user=publiek","tls":"","x":346,"y":220,"wires":[["d14b8d0e.6af22"]]},{"id":"d14b8d0e.6af22","type":"function","z":"e01e747b.b23d98","name":"rhenen","func":"msg.payload = {\n    rhenen: msg.payload.latest.data\n}\nreturn msg;","outputs":1,"noerr":0,"x":460,"y":300,"wires":[["be5d4c7.8bd90b","71f67ffa.a3d96"]]},{"id":"71f67ffa.a3d96","type":"influxdb out","z":"e01e747b.b23d98","influxdb":"5d261c0f.e93024","name":"Test (192.168.2.185)","measurement":"msg.payload","precision":"","retentionPolicy":"","x":660,"y":360,"wires":[]},{"id":"5d261c0f.e93024","type":"influxdb","z":"","hostname":"192.168.2.185","port":"8086","protocol":"http","database":"Test","name":"Test","usetls":false,"tls":""}]