# Mqtt -\> Node-Red -\> InfluxDB

**URL:** <https://discourse.nodered.org/t/mqtt-node-red-influxdb/25439>\
**Category:** General\
**Created:** [24 April 2020 18:08 UTC](https://discourse.nodered.org/t/mqtt-node-red-influxdb/25439 "2020-04-24T18:08:34Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [25 April 2020 12:17 UTC](https://discourse.nodered.org/t/mqtt-node-red-influxdb/25439/6 "2020-04-25T12:17:30Z")

</div>

> [@URBANsUNITED](#):
>
> Yes, I understand that I can split that message

Rather than splitting the message, have you thought about accessing the parts directly? Once split, each of those is a different message, and if you insert those parts into influx, they get inserted as different measurements, rather than one single measurement. Again, go back to the link Steve gave you, working with messages. From the original message you get out of MQTT, you have an object with the following payload:

```auto
{
  "Time": "2020-04-24T19:59:42",
  "Gas": {
    "Count": 4624.38
  },
  "Wasser": {
    "Count": 771.473
  },
  "gas_day": 0.87,
  "gas_month": 59.65,
  "gas_year": 1.84,
  "water_day": 0.32,
  "water_month": 12.7,
  "water_year": 0.9
}

```

From a function node directly behind that mqtt-in node, you can access the values as `msg.payload.gas_day`, `msg.payload.gas_month`, and so on. To get the object you have described in `msg7.payload` in your original post, you can try the following:

```auto
msg.payload = [
    {
        "gas_day": msg.payload.gas_day, 
        "gas_month": msg.payload.gas_month, 
        "gas_year": msg.payload.gas_year, 
        "water_day": msg.payload.water_day, 
        "water_month": msg.payload.water_month, 
        "water_year": msg.payload.water_year
     }
];
return msg;

```

![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/5/d5681bec02d178e0f7f91839c69d3573fa0a617c.png)

What's going wrong in the above image is that once you've split the object, the keys turn into topics, and the payload differs per type. For the `Time` key, your payload is a string. For `Gas`, it's an object, `gas_year` for example, is a number. If you did split it, then pass all those messages to a function node and have it operate on `msg.payload.???`, the contents of msg.payload, and especially the type of each payload, is different.

Can you explain what the format is that you need?

> [@Steve-Mcl](#):
>
> see comments above to understand this problem
> 
> Answer...
> 
> ```auto
> var t = msg.payload.Time
> var gasCount = msg.payload.Gas.Count;
> msg.payload = { payload: gasCount };
> return msg;
> 
> ```
> 
> or...
> 
> ```auto
> var t = msg.payload.Time
> var gasCount = msg.payload.Gas.Count;
> node.send({ topic: "time", payload: t});
> node.send({ topic: "gas/count", payload: gasCount });
> return null;// already sent
> 
> ```

What is for your use case the format of your messages that you need? See the influx node's builtin documentation for a description, and work it out for your use case. If you pass us back that information, we can give more detailed information on how to continue.

Edit: this topic is worth a read too, and might allow you to figure it out as well: [Help needed with MQTT to influx](https://discourse.nodered.org/t/help-needed-with-mqtt-to-influx/25421)

---

_[View the full topic](https://discourse.nodered.org/t/mqtt-node-red-influxdb/25439)._
