Inporting data into InfluxDB database

Hi everyone. Im new to IOT and node-red and everything. Im currently working on my final thesis and one part of the thesis is monitoring the temperature and humidity in labs at university and storing that data in Influx.
I use M5Stickc Plus as a mqtt data publisher. The data comes to node-red like this:
"izba"=room where is the sensor located
"23.97192"= temperature
I then used split function to split that message into 2 separate messages. As far as i know, i need with change function change that data into field and tags. But i cant figure it out how to change that data and write it into database.
i know its probably really easy step, but i spent a lot of time on this and im lost

Welcome to the forum @danco

Do you have control over the data coming in? If you have it would be better if the data were a json string something like
{"izba": 23.7192}
or even better
{"room": "izba", "temperature": 23.7192}

Sticking with what you have for the moment though, you don't want to split it into two messages. Keep it in one message.

Have a look at the help text for the influx out node and see if you can work out how the message you send to it needs to be structured. I presume that you want a tag called "room" and a field called "temperature".

Have you watched the recommended playlist for newcomers? Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Pay particular attention to the section Working with Messages which will give you ideas on how to restructure the data.

1 Like

Thanks for your quick answer Colin!
I dont know if you are familiar with uiflow or M5Flow, but this is how looks my mqtt output.

I probably cant add "temperature" in front of measurement.
I watched few of the videos, but im going to watch them all now.

No I am not familiar with that.
If you want humidity and pressure too can you get them all in one MQTT message? That would make it much easier as I imagine you want them all together in the db.

if you construct your M5flow msg section like below, you could send all 3 reading in a JSON string
{"room":"izba", "temperature": + get env3_0 temperature +
, "humidity": + get env3_0 humidity + , "pressure": +
get env3_0 pressure + }

Do i need to construct it via Python or can be this done in Blockly too ?

Ahh that's Blocky. confused by name in text above image.

You should be able to do it in blocky then, but best place would be where ever published from.

This is the best what i was able to create.
If its not ok, it would be ok for me to have 3 different databases in influx for each measurement.
I just dont know how to change the message to the format i need for influx.

My example had { at beginning and a } at end and you replace or removed the commas.

Best to learn to do things correctly, @Colin advise about putting all 3 readings together, is good advise.
ps. It's easier to split the reading if needed, rather than trying to join them later.

I dont know if you have experience with m5flow or blockly, its really hard to send it in one message :smiley:

You have it in one message, you just need to put commas between the individual components, and if possible add {} round it.
Having done that the MQTT node will automatically generate a javascript object, and the rest is easy.

is this right ?

Looks ok. Is that coming from an MQTT node? if so then tell it to automatically detect JSON. If not then feed it through a JSON node.

I have seen them . You just sent it in one message, just missing important {,} missing.

Once you have the input correct, here are some recent topics that show how the data should look Search results for 'sending json data influxdb order:latest_topic' - Node-RED Forum .
There should also be examples in the help text and flow examples in the import library.
[edi] The new image looks correct.
You coould also get blocky to construct the message in the correct format for inflxdb if so inclined.

1 Like

Yes, it comes from MQTT node. I changed the output to JSON.

it was seriously this simple ?

Did you tag the room?
scratch that i'm blind

Tag for a room is "izba". Its in my native language. Im just testing everything, in the future there will be tag with the number of the room at university.

In the help text for the node it says
If msg.payload is an array containing two objects, the first object will be written as the set of named fields, the second is the set of named tags.

So if you want the room as a tag and the rest as fields, which I guess you do, then in a function node you can do

msg.payload = [
    Temperature: msg.payload.Temperature,
    Humidity: msg.payload.Humidity,
    Pressure: msg.payload.Pressure