MQTT to Influx: getting error [node: Influxdb out] msg : string[24]

Hello all! I have probably very easy issue to solve but I do not know how to do it.

I have created the flow where data is sent to MQTT server. That works fine, but I would like to use same values in MQTT in and send the same values to Influxdb. My issue is that I do not know how to parse string to number.

This is my function that sends the data to the MQTT server node

let room= msg.payload;
msg.payload = '{"loc":"' + room.loc + '", "device":"' + room.device + '", "value":' + room.temperature.toFixed(2) + '}';
msg.topic = 'room/basement';
return msg;

My function from MQTT in node to Influxdb node:

let t = { payload: temperature, measurement: "temperature"};
return [t];

Error is:

[node: Make temp measurement]
msg.payload : undefined

I have tried just random values, and data flows to Influxdb as it should but values are not from the MQTT server, example:

let t = { payload: Math.random() * 15 + 20, measurement: "temperature"};

I do not know how should I retrieve the values from a previous function? I know that value supposed to be number, not string or object.

Issue is here:

image

> node: debug 206
> room/basement : msg.payload : Object
> object
> loc: "room"
> device: "sensor"
> value: "34.94"

Error is:

> node: Influxdb out
> msg : string[24]
> 
> "No measurement specified"

Appreciate all the help!

UPDATE:
Function node is now:

const room = msg.payload;
msg.payload = {
    loc: room.loc, 
    device: room.device,
    value: Number(room.temperature)
}
msg.topic = 'room/basement';
msg.measurement = 'temperature';
return msg;

Same error:
image

My advice is dont build JSON in strings, make an object (then convert to JSON but ONLY if it is actually required)

const room = msg.payload;
msg.payload = {
    loc: room.loc, 
    device: room.device,
    value: Number(room.temperature).toFixed(2)
}
msg.topic = 'room/basement';
return msg;

Hello! Thank you for your advice. I still have the same issue because it is an object, not a number value.
I tried to add a change node and set the msg.payload to JSONata Expression with $number(payload)

Error is:
msg : string[144]
"Invalid JSONata expression: Unable to cast value to a number: "

Or if I try to use parser JSON error is:

[node: Influxdb out]msg : string[24]
"No measurement specified"

So I was hoping to find "easy" solution for this, since at least then data goes to Influxdb as expected but just need to find out how to get a value for temperature from another function what sends the value to MQTT server.

let t = { payload: Math.random() * 15 + 20, measurement: "temperature"};

Did you try the function I posted?

Did it not work?

I did try and it does send data to MQTT server as it did already. My issue is when I try to send same values/data from MQTT in node to Influxdb out node.

image

error is:
[node: Influxdb out] msg : string[24]

"No measurement specified"

Put a debug on the output of the MQTT node - what is in payload (my guess is a string)?

And what does the InfluxDB node expect? (my guess NOT a string)

It is object:

[node: debug 206]
room/basement: msg.payload : Object

object

But for some reason when I try to send it to Influxdb out node it is string again.

[node: Influxdb out]msg : string[24]

"No measurement specified"

Sorry I dont know the influx stuff as well as some users.

You should probably start a new thread & be certain you mention infuxdb in the title to attract the right users. Alternatively, rename this thread to something like "MQTT to Influx: getting error [node: Influxdb out] msg : string[24]"

When you create the thread - include a small screenshot that shows the payload coming out of the MQTT node and the error in the debug sidebar.

Lastly, please use the copy value button on the debug message INSTEAD of selecting text with the mouse because vital info is lost. E.g. "room/basement: msg.payload : Object" is not enough information!

Yes, thank you anyway for your help and tips!

First check that you have either specified a measurement in the influx node or in the message you are passing.
Also, you generally shouldn't be truncating the value to 2 decimal places before you write it to influx, so throwing away resolution. Truncate at the point of display if necessary, not before.

Yes, I have specified a measurement in the node and this one does works fine but issue is that it creates new values/data and do not bring values from room/basement. That is my issue actually that I do not know how I supposed to get data from my previous node.

This works and data goes to Influxdb (measurement specified):

let t = { payload: Math.random() * 15 + 20, measurement: "temperature"};

Function node (where I would like to get values from):

let room = msg.payload;
msg.payload = '{"loc":"' + room.loc + '", "device":"' + room.device + '", "value":' + room.temperature.toFixed(2) + '}';
msg.topic = 'room/basement';
return msg;

Those values are saved to MQTT out node and MQTT in node.

If you are still using that function node and not using the function node I provided for you, your problem is because you are sending a string in the payload. The function I wrote for you sends an object.

As I suggested earlier, show us exactly what comes out of the MQTT node before it goes into the influx DB node.

And show us exactly what the error is.

Yes, I am using your way but I keep all the options open because I have been struggling with this issue few days.
I am so sorry but even I use copy value, whole error is: No measurement specified.
image

I'll try once more...

Hopefully this helps!

Those are not showing any error message

ok, so should value be a number or a string?

Remember what colin said...

So what happens if you change the function to...

const room = msg.payload;
msg.payload = {
    loc: room.loc, 
    device: room.device,
    value: Number(room.temperature)
}
msg.topic = 'room/basement';
return msg;

Then pass that to the influx node?

LASTLY - if you pass this via MQTT, be certain to add a debug node BEFORE the Influx node to ensure the payload is an object.

Hello! Yes, that works fine but issue comes when I try to get data to Influxdb.

I know the issue is that for some reason even data is object it changes the data to string.

Even I took off that toFixed(2) same error occurs.

image
image

I already tried that, same issue:

And Influxdb expects number value.

When I use this it works but value is not correct, just random:

let t = { payload: temperature, measurement: "temperature"};
return [t];

ok, now I understand.

Add a function between MQTT and Influx

image

Put this in the function node...

const data = msg.payload;
msg.payload = data.temperature
msg.measurement = data.loc
return msg;