Node-red influxdb json insert

#1

Hello friends,

I'm sending a json line as follows. mqtt broker takes this line and translates as json.
Then I want to save the line that I translated into influxdb but don't save it?

Json string: { "nodename": "cihaz1", "nodeabone": "123456", "endeks": "210" }

node:

[{"id":"555092b5.57397c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"ed2ad8b1.8df8e8","type":"mqtt in","z":"555092b5.57397c","name":"","topic":"/deneme/#","qos":"0","broker":"f35383e5.cc1d5","x":80,"y":100,"wires":[["1db520db.022daf"]]},{"id":"8b88bdbb.c410c","type":"influxdb out","z":"555092b5.57397c","influxdb":"41b4c349.309a4c","name":"","measurement":"sistem","precision":"","retentionPolicy":"","x":720,"y":80,"wires":[]},{"id":"1db520db.022daf","type":"json","z":"555092b5.57397c","name":"","property":"payload","action":"","pretty":false,"x":240,"y":100,"wires":[["79f3bb2e.9dbb34","8ea62c9b.6de7d"]]},{"id":"79f3bb2e.9dbb34","type":"debug","z":"555092b5.57397c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":390,"y":120,"wires":[]},{"id":"8ea62c9b.6de7d","type":"function","z":"555092b5.57397c","name":"MQTT to InfluxDB","func":"var topic = msg.topic.split("/");\nvar dest = tokens[tokens.length-1];\n\nmsg.payload = topic[2] + \n",nodename=" + msg.payload.nodename + \n",nodeabone=" + msg.payload.nodeabone + \n" endeks=" + msg.payload.endeks;\n\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":80,"wires":[["2498d973.882296","8b88bdbb.c410c"]]},{"id":"2498d973.882296","type":"debug","z":"555092b5.57397c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":610,"y":120,"wires":[]},{"id":"f35383e5.cc1d5","type":"mqtt-broker","z":"555092b5.57397c","name":"centos","broker":"192.168.241.132","port":"1883","clientid":"node-red","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""},{"id":"41b4c349.309a4c","type":"influxdb","z":"","hostname":"192.168.241.132","port":"8086","protocol":"http","database":"SAYACSISTEMI","name":"","usetls":false,"tls":""}]

0 Likes

#2

I’m guessing english isn’t your first language. But this doesn’t make sense.

Also please read the post on how to add a flow to the forum, currently your flow can’t be imported.

0 Likes

#3

yes.
my english bad.
i am using google translate

0 Likes

#4

In case you can't find it the formatting post is How to import a flow into the editor
You can go back and edit your the flow you have posted.

0 Likes

#5

no no.
does not save data in influxdb.
How can I register json data into influxdb.

0 Likes

#6

Edit your original post so we can import your flow and see what you are doing

Colin

0 Likes

#7

json with mqtt.fx
does not save the json object I sent to influxdb.

my function code:
var topic = msg.topic.split("/");
var dest = tokens[tokens.length-1];

msg.payload = topic[2] +
",nodename=" + msg.payload.nodename +
",nodeabone=" + msg.payload.nodeabone +
" endeks=" + msg.payload.endeks;

return msg;

0 Likes

#8

Edit your earlier post as described in the link I posted so we can import your flow.

0 Likes

#9

okay managed to save.
how to update if same registration

0 Likes

#10

Since you haven't exported and pasted you current flow here it is not clear exactly what you are doing.
If you post your current flow so we can see what you are doing then it might be easier to understand the question. Normally with influx you send new values and it gets appended to the existing data.

0 Likes

#11

as an example: I want to update from device1 if any.
I want to update when I send a few identical records

{ "nodename": "cihaz1", "nodeabone": "144", "endeks": "655477" }

mqttfx

0 Likes

#12

Sorry, I don't understand what you mean.

0 Likes

#13

Let me explain.
I want the registration to be updated if the same record is available.
update if same nodename. don't make new record

cihaz1

0 Likes

#14

Sorry, still don't understand. Possibly if you posted a typical sequence of data coming in and explain what you want to do with it.

0 Likes

#15

0 Likes

#16

UPDATE nodes
SET endeks = endeks, (Data received with json)
nodeabone = nodeabone (Data received with json)
WHERE nodename = 'cihaz1';

What should I do to update a record with node-red in influxdb?
Updating in SQL Server this way

0 Likes

#17

I believe I outlined what you needed to do in the other thread.

0 Likes

#18

Influxdb is a time series database, so every record is unique based on its timestamp -- in your example you are describing the typical behavior of sql databases, where records are stored based on "keys" like your nodename. Then incoming records can do either the insert or update for you, depending upon whether that key exists.

Perhaps for something this simple, you should be using mysql or sqlite instead?

0 Likes

#19

Yeah @shrickus.
How to update by specifying the nodename property Is there an example?

0 Likes

#20

By "update" do you mean pass in a new value for the item being stored to be added to the series of data there already? If so then it is the word update that is confusing us, as it suggests changing existing data rather than adding to it.
If you are just adding to the data and if you are using node-red-contrib-influxdb then the Info tab for the node explains the various methods of specifying a particular field for the value being added.
If you are just trying to provide a new value for one field then the simplest way is to pass an object in the payload of the form

{fieldname: value}
0 Likes