Tag a value for influxdb

I have a latitude number and a longitude ;
i want to store them in Influxdb in the same server and measurement
But before I would like to tag them with "Lat" and "Long"
How can i do this ?

msg.payload = Number(msg.payload);
msg.payload = Number(msg.payload.toFixed(7));
return msg;

In InfluxDB, tags are for text metadata, numbers should be in values.

You can have multiple values and tags in a single entry. So just send lat and log value names.

If you have both values available then something like
msg.payload = {lat: 23.1, long: 2.5}
and feed it to the influx node. This is described in the help text for the node, and in greater detail on the nodes home page.

1 Like

Thanks a lot

in fact I receive this message in hexa : 6c61743a2034382e31302c206c6f6e673a202d312e3739
I transform it in string : lat: 48.10, long: -1.79
and this is this message that I want to store in Influxdb
but I've an error message to convert it in the good format

[{"id":"57ceba4f.ff52b4","type":"function","z":"a1fb6147.ca4bd8","name":"to string","func":"msg.payload = Buffer.from(msg.payload, 'hex').toString();\nreturn msg;","outputs":1,"noerr":0,"x":800,"y":400,"wires":[["420fa9f9.c2ff58"]]},{"id":"bb8e3a5e.acfa78","type":"inject","z":"a1fb6147.ca4bd8","name":"","topic":"","payload":"6c61743a2034382e31302c206c6f6e673a202d312e3739","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":630,"y":400,"wires":[["57ceba4f.ff52b4"]]},{"id":"74595e3b.21e598","type":"debug","z":"a1fb6147.ca4bd8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1150,"y":400,"wires":[]},{"id":"420fa9f9.c2ff58","type":"json","z":"a1fb6147.ca4bd8","name":"","property":"payload","action":"","pretty":true,"x":950,"y":400,"wires":[["74595e3b.21e598"]]}]

an idea for help

what's the error?

in fact i would like to get an expression like this :
{"lat": 48.10, "long": -1.79}
to put in influxdb from this message :
6C61743A2034382E313039363033392C206C6F6E673A202D312E37393339333739 -->lat: 48.10, long: -1.79
and I don't know how to transformwith a node?

If you have a string of that format then, in a function node, you can use msg.payload.split(",")
to split it into two parts, then on each of those split it on the ":" and pick up the send part as the value, then build the object using that data.

You could just split the string and build the object

const parts =  Buffer.from(msg.payload, 'hex').toString().split(/:|,/);
msg.payload = {
    [parts[0].trim()]: Number(parts[1].trim()), 
    [parts[2].trim()]: Number(parts[3].trim())
return msg;

Even better :slight_smile:

awesome it works great :ok_hand:
thanks a lot for the help
indeed I did not understand how I could reconstruct the message after having cut it
I understand better now :grinning:

1 Like