Mqtt #-message split and write to database

Hi together,

I would like to get data via MQTT to Node-Red.
I use the Node 'mqtt in' with the topic 'Speicher/t_day_min/#'.
Via debug node I get
15.7.2022, 10:36:04node: DB
Speicher/t_day_min/Wert : msg.payload : string[6]
" 30.7"
and
same for date/time.
Now I don't know how to get the 2 values splited so that I can "Insert ... into ..."
How do I get for e. g.
let temp = variable1;
let datetime_var = variable2;

Thank you very much in advance.
Greetings
Martin

I assume the 2 values arrive at separate times & have different topics?

If so, then you need to join them together into 1 msg so that you can access them both at the same time.

Then you can use them as parameters for your SQL INSERT (or if you enjoy taking risks you can concatenate them into a SQL INSERT string)

How to join separate messages into 1...

See this article in the cookbook for an example of how to join messages into one object.

If you have control of the mqtt messages, and the timestamp is not the current time, then, if possible, put the time and value in one mqtt message. If it is the current time then you don't need to get it via MQTT.

Hi Steve-Mci and Colin,

I use now the measured value from BME280-Esp8266 via MQTT to a function-node in Node-Red.
In Node-Red I store the coresponding datetime.
I have also a trigger, when day changes. When day changes I write the min. and max. values of the temperature and datetime into MYSQL.

It works fine so far.
Thank you both for your ideas / input.

Kind regards

Martin

1 Like