# Tag a value for influxdb

**URL:** https://discourse.nodered.org/t/tag-a-value-for-influxdb/66179
**Category:** General
**Created:** [8 August 2022 15:18 UTC](https://discourse.nodered.org/t/tag-a-value-for-influxdb/66179 "2022-08-08T15:18:04Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![chris35](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@chris35](https://discourse.nodered.org/u/chris35)
#### Post date: [8 August 2022 15:18 UTC](https://discourse.nodered.org/t/tag-a-value-for-influxdb/66179/1 "2022-08-08T15:18:04Z")

</div>

Hi  
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 ?  
Thanks

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

```

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [8 August 2022 16:38 UTC](https://discourse.nodered.org/t/tag-a-value-for-influxdb/66179/2 "2022-08-08T16:38:49Z")

</div>

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.

---

<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: [8 August 2022 16:54 UTC](https://discourse.nodered.org/t/tag-a-value-for-influxdb/66179/3 "2022-08-08T16:54:33Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![chris35](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@chris35](https://discourse.nodered.org/u/chris35)
#### Post date: [9 August 2022 11:50 UTC](https://discourse.nodered.org/t/tag-a-value-for-influxdb/66179/4 "2022-08-09T11:50:46Z")

</div>

Ok  
Thanks a lot

---

<div class="post-metadata">

### Author: ![chris35](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@chris35](https://discourse.nodered.org/u/chris35)
#### Post date: [9 August 2022 14:29 UTC](https://discourse.nodered.org/t/tag-a-value-for-influxdb/66179/5 "2022-08-09T14:29:02Z")

</div>

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

```auto
[{"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

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [9 August 2022 16:20 UTC](https://discourse.nodered.org/t/tag-a-value-for-influxdb/66179/6 "2022-08-09T16:20:02Z")

</div>

what's the error?

---

<div class="post-metadata">

### Author: ![chris35](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@chris35](https://discourse.nodered.org/u/chris35)
#### Post date: [10 August 2022 06:25 UTC](https://discourse.nodered.org/t/tag-a-value-for-influxdb/66179/7 "2022-08-10T06:25:22Z")

</div>

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?  
Thanks

---

<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 August 2022 08:43 UTC](https://discourse.nodered.org/t/tag-a-value-for-influxdb/66179/8 "2022-08-10T08:43:45Z")

</div>

> [@chris35](#):
>
> I transform it in string : lat: 48.10, long: -1.79

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.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [10 August 2022 08:59 UTC](https://discourse.nodered.org/t/tag-a-value-for-influxdb/66179/9 "2022-08-10T08:59:14Z")

</div>

You could just split the string and build the object

```auto
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;

```

---

<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 August 2022 09:03 UTC](https://discourse.nodered.org/t/tag-a-value-for-influxdb/66179/10 "2022-08-10T09:03:54Z")

</div>

Even better 🙂

---

<div class="post-metadata">

### Author: ![chris35](https://avatars.discourse-cdn.com/v4/letter/c/898d66/32.png) [@chris35](https://discourse.nodered.org/u/chris35)
#### Post date: [10 August 2022 09:40 UTC](https://discourse.nodered.org/t/tag-a-value-for-influxdb/66179/11 "2022-08-10T09:40:00Z")

</div>

awesome it works great 👌  
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 😀

---

<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: [9 October 2022 09:40 UTC](https://discourse.nodered.org/t/tag-a-value-for-influxdb/66179/12 "2022-10-09T09:40:43Z")

</div>

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