# Send dynamic topic mqtt data to mysql

**URL:** <https://discourse.nodered.org/t/send-dynamic-topic-mqtt-data-to-mysql/74751>\
**Category:** General\
**Tags:** mqtt\
**Created:** [5 February 2023 20:27 UTC](https://discourse.nodered.org/t/send-dynamic-topic-mqtt-data-to-mysql/74751 "2023-02-05T20:27:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![atugrul](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@atugrul](https://discourse.nodered.org/u/atugrul)\
**Post date:** [5 February 2023 20:27 UTC](https://discourse.nodered.org/t/send-dynamic-topic-mqtt-data-to-mysql/74751/1 "2023-02-05T20:27:37Z")

</div>

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

1. node as id

```auto
msg.topic : "SENS/12532/ID"
msg.payload : 12532

```

1. node as temp

```auto
msg.topic : "SENS/12532/TEMP"
msg.payload : 24

```

1. node as humidity

```auto
msg.topic : "SENS/12532/HUM"
msg.payload : 86

```

1. node as light

```auto
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.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [5 February 2023 21:34 UTC](https://discourse.nodered.org/t/send-dynamic-topic-mqtt-data-to-mysql/74751/2 "2023-02-05T21:34:06Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 February 2023 21:55 UTC](https://discourse.nodered.org/t/send-dynamic-topic-mqtt-data-to-mysql/74751/3 "2023-02-05T21:55:59Z")

</div>

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](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 April 2023 21:56 UTC](https://discourse.nodered.org/t/send-dynamic-topic-mqtt-data-to-mysql/74751/4 "2023-04-06T21:56:36Z")

</div>

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