# MQTT not passed correctly to InfluxDB

**URL:** <https://discourse.nodered.org/t/mqtt-not-passed-correctly-to-influxdb/94492>\
**Category:** General\
**Created:** [9 January 2025 19:00 UTC](https://discourse.nodered.org/t/mqtt-not-passed-correctly-to-influxdb/94492 "2025-01-09T19:00:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![joselitoo](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@joselitoo](https://discourse.nodered.org/u/joselitoo)\
**Post date:** [9 January 2025 19:00 UTC](https://discourse.nodered.org/t/mqtt-not-passed-correctly-to-influxdb/94492/1 "2025-01-09T19:00:16Z")

</div>

Hello,

i need some help with Node Red. I´m want to migrate to the newest versions of InfluxDB MQTT Broker Mosquitto and Node RED. Everything went smooth more or less.  
The Problem is I cannot get the nodes correctly so the data is written into the influxDB

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

It creates in the Bucket "Sensors" the correct measurement but when reading it i get this error message:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/1/e1c0ca9ac6c9534e6683e4794b54a438dae1f4b2.png)

These are the version jumps i did:  
NodeRed 1.2.9 --\> 4.0.2  
InfluxDB 1.8.x --\> 2.x

I´m building this in parallel. So my old enviroment still works like a charm.

Can anyone help me to locate the issue why the values are not written into the database?

---

<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:** [9 January 2025 19:58 UTC](https://discourse.nodered.org/t/mqtt-not-passed-correctly-to-influxdb/94492/2 "2025-01-09T19:58:20Z")

</div>

I don't know how far you have got but are you sure you want to go to influxdb 2? Many think that V2 has problems, Flux in particular, and are waiting for v3.

---

<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:** [9 January 2025 20:30 UTC](https://discourse.nodered.org/t/mqtt-not-passed-correctly-to-influxdb/94492/3 "2025-01-09T20:30:40Z")

</div>

However, putting that aside, your msg.payload is not valid for sending to the database. Look at the influxdb help text, and the more detailed description and example [here](https://flows.nodered.org/node/@rcomanne/node-red-contrib-influxdb) for how it should be formatted.

---

<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:** [10 January 2025 15:03 UTC](https://discourse.nodered.org/t/mqtt-not-passed-correctly-to-influxdb/94492/7 "2025-01-10T15:03:47Z")

</div>

I do not see how the msg.payload that you posted agrees with any of the formats defined in help text.  
The fields and tags to write are in **msg.payload**. If **msg.payload** is a string, number, or boolean, it will be written as a single value to the specified measurement (called _value_).

If **msg.payload** is an object containing multiple properties, the fields will be written to the measurement.

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.

Finally, if **msg.payload** is an array of arrays, it will be written as a series of points containing fields and tags.

Given the payload you show, what fields and tags do you expect to be written to the database?

---

<div class="post-metadata">

**Author:** ![joselitoo](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@joselitoo](https://discourse.nodered.org/u/joselitoo)\
**Post date:** [10 January 2025 15:07 UTC](https://discourse.nodered.org/t/mqtt-not-passed-correctly-to-influxdb/94492/8 "2025-01-10T15:07:10Z")

</div>

I´ve deleted previous posts as it might be confusing. I worked on following:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/8/982eb77d2f0109f317f8998184c48f394ef34e05.png)

So the number 230 should be written into the DB. But it does not. My question is now why?  
If InfluxDB expects String but i´m writting a value...

---

<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:** [10 January 2025 15:10 UTC](https://discourse.nodered.org/t/mqtt-not-passed-correctly-to-influxdb/94492/9 "2025-01-10T15:10:47Z")

</div>

OK, that is because (as the error says) you have previously written a string to that measurement. You will have to delete that measurement from the DB before writing it as a float.

---

<div class="post-metadata">

**Author:** ![joselitoo](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@joselitoo](https://discourse.nodered.org/u/joselitoo)\
**Post date:** [10 January 2025 15:26 UTC](https://discourse.nodered.org/t/mqtt-not-passed-correctly-to-influxdb/94492/10 "2025-01-10T15:26:33Z")

</div>

Thank you! I got it working now on a new Bucket.  
My question is, as this was a migrated 1.8 DB is there any way to keep it as it has a lot of my old solar panel data?  
Is it possible to change the value back to a string? (sorry if this is a dumb question)

---

<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:** [10 January 2025 16:01 UTC](https://discourse.nodered.org/t/mqtt-not-passed-correctly-to-influxdb/94492/11 "2025-01-10T16:01:27Z")

</div>

Are you sure it Is stored as a string in the original? That is horribly inefficient. There is no change to the influxdb node, so if you sent that payload in the original it would have written it as a number not a string.

If you do want to write it as a string then in a function node you can pu

```auto
msg.payload = msg.payload.toString()
return msg

```

Feed it into a debug node to make sure it is what you want before connecting to the db node, so you don't accidentally write incorrect data.

---

<div class="post-metadata">

**Author:** ![joselitoo](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@joselitoo](https://discourse.nodered.org/u/joselitoo)\
**Post date:** [10 January 2025 16:25 UTC](https://discourse.nodered.org/t/mqtt-not-passed-correctly-to-influxdb/94492/12 "2025-01-10T16:25:15Z")

</div>

I would say yes. Here is the scenario.

1. When writing to the migrated DB I get following error message in NodeRed

> HttpError: failure writing points to database: partial write: field type conflict: input field "value" on measurement "tele/Tasmota\_Homeserver/Homeserver\_Voltage" is type float, already exists as type string dropped=1

1. When writing to an empty and new bucket no error message and values show in the data explorer

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

If it is not efficient what scenario would work to keep the old data? Can i convert the DB?

---

<div class="post-metadata">

**Author:** ![joselitoo](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@joselitoo](https://discourse.nodered.org/u/joselitoo)\
**Post date:** [10 January 2025 19:05 UTC](https://discourse.nodered.org/t/mqtt-not-passed-correctly-to-influxdb/94492/13 "2025-01-10T19:05:32Z")

</div>

The script to convert the database so it does work again looks like:

```auto
from(bucket: "sensors")
  |> range(start: 0) // Start from the beginning of the bucket
  |> filter(fn: (r) => r._measurement == "tele/Tasmota_Dehumidifier/Dehumidifier_ApparentPower" and r._field == "value") //needs to be done for every Measurement in the Bucket
  |> map(fn: (r) => ({
      _time: r._time,
      _measurement: r._measurement,
      _field: r._field,
      _value: float(v: r._value), // Convert the value from string to float
      _tags: r._tags
  }))
  |> to(bucket: "sensorsDB", org: "Homelab") //This is the new Bucket which needs to be created

```

I hope this helps someone in case they have the same issue

---

<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:** [10 April 2025 19:06 UTC](https://discourse.nodered.org/t/mqtt-not-passed-correctly-to-influxdb/94492/14 "2025-04-10T19:06:22Z")

</div>

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