Send dynamic topic mqtt data to mysql

Hello, i have a flow that 16 different sensor values recieve from mqtt.

  1. node as id
msg.topic : "SENS/12532/ID"
msg.payload : 12532
  1. node as temp
msg.topic : "SENS/12532/TEMP"
msg.payload : 24
  1. node as humidity
msg.topic : "SENS/12532/HUM"
msg.payload : 86
  1. node as light
msg.topic : "SENS/12532/LIGHT"
msg.payload : 2356

i get 16 different measurments for one sensor. and there is lots of sensor. "SENS/" and "/TEMP, /HUM, /LIGHT etc." are fixed values but 12532 is change for each sensor.
According to the scenario, i how to call msg.payload data at FUNCTION node for all measurements at each sensor. I want to make node to send measurements to MYSQL by using function.

Without knowing the schema of your table, it is hard to guess at what you need.
If all those readings need to be in one row of the database, you will need to join the together (use a join node) into one msg.

You can also use the mysql node to issue the insert command,

Pe
Are you sure that the sensor does not have a mode where it will send all the values in one message? What sensor is it?
Otherwise, if you are stuck with that data format then I think I might have a table for each measurement (temp, hum etc), with timestamp, value, and sensor id in each.

If you do need to get them all into one table then you can use a Join node as @zenofmud suggests. See this article in the cookbook for an example of how to join messages into one object.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.