Wrong output to influxdb (Data as a string)

#1

Hi,
... please could someone help me how "correctly" write values (with tags) to influxdb.
The values in influxdb are not correctly writing (with " " symbol - like STRING)

Thanks

0 Likes

#2

What is coming out of mqtt?

0 Likes

#3

in node-red it looks like ..
image

0 Likes

#4

There is a fairly large issue with InfluxDB that, once you have written to a field, it takes the data type that you first wrote to it. So if you meant to send a float for example but the first time you outputted a string - you have an issue.

There are only two ways around this.

  • Wait for (or arrange) a new "shard" to be created for your database. At which point, your numbers will be taken as numbers for the new shard.
  • Drop the series and recreate it with the correct data.
1 Like

#5

.. nope .. new field (which is created after drop) is again like "string" ... the nodered send like string and not like value :frowning: ... I think nodered have issue with multiple value in payload. I see the value like Ts: "23441" and not Ts: 23441 in debug window (see
image ).

modul JSON make this, but only with one value - one msg.payload .. and also in influxdb is like value

0 Likes

#6

It looks like you're trying to save an entire JSON string as the value. I recommend looking at the influx batch node and moving those values into apropriate fields and tags for the same measurement.

Example:

1 Like

#7

I believe that the problem is that the values of Ts etc in the string from the MQTT node are already strings. Are they strings in the object you are sending to MQTT?
If you can't change it at that end then you will need to convert then to numbers after the JSON node. You can do that to each one in a function node using the JavaScript Number() function.

0 Likes

#8

so looks raw mqtt

the object is wrong defined in mqtt ...
right is Object - { "a": 1, "b": 2} and not Object - { "a": "1", "b": "2"}
its not like number but like string

... can somebody help write same script for correct this?

0 Likes

#9

take a look at this: https://cookbook.nodered.org/mqtt/receive-json

1 Like

#10

thanks for tips, but not working .. still same

0 Likes

#11

Put a debug nde after the JSON node and set it to display the complter msg object. What does it show?

0 Likes

#12


0 Likes

#13

Hi,
I had the same problem and fixed using a function node to cast all strings to int and float where possible:

function TryParseInt(str, defaultValue) { let v=parseInt(str); return v==str ? v : defaultValue; }
function TryParseFloat(str, defaultValue) { let v= parseFloat(str); return v==str ? v : defaultValue; }


var payload=msg.payload;
for (var key in payload) {
    if (payload.hasOwnProperty(key)) {
        payload[key]=TryParseInt(payload[key],payload[key]);
        payload[key]=TryParseFloat(payload[key],payload[key]);
    }
}


msg.payload=payload;
return msg;
0 Likes

#14

0 Likes