I have a small problem and I am turning in round without solution. I am receiving MQTT topic and I have to divided them by 10 before to sent them to an influxdb database.
Simple but ...it is not working .Probably a problem of type of variable.
Here the function that I am trying to adapt
var msg2 = null;
var value = Number(msg.payload)/10; // convert it to a number in case it is a string
if (!isNaN(value)) {
msg2 = {payload: {"OT_item24": value}};
}
return msg2;
Thanks for your reply but when I do like that I have a debug after function : Error: A 400 Bad Request error occurred: {"error":"partial write: field type conflict: input field "value" on measurement "OT_item24" is type float, already exists as type string dropped=1"}
Thanks , I have tried your method but with it , I obtained the debug message :Error: A 400 Bad Request error occurred: {"error":"unable to parse 'OT_item24 device=undefined,value=18.8': invalid boolean"}
The clue is in the error message. By previously connecting the mqtt node directly the influx node, and without telling the mqtt node to parse the string it receives as a JSON string, you have sent a string to that field instead of a number. Now you can only send it strings. To fix that you will have to delete (drop) that measurement from the database. Or change the measurement name to a new name.