# NRD to Influxdb-strings

**URL:** <https://discourse.nodered.org/t/nrd-to-influxdb-strings/53315>\
**Category:** General\
**Created:** [6 November 2021 23:40 UTC](https://discourse.nodered.org/t/nrd-to-influxdb-strings/53315 "2021-11-06T23:40:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fishy](https://avatars.discourse-cdn.com/v4/letter/f/da6949/32.png) [@Fishy](https://discourse.nodered.org/u/Fishy)\
**Post date:** [6 November 2021 23:40 UTC](https://discourse.nodered.org/t/nrd-to-influxdb-strings/53315/1 "2021-11-06T23:40:37Z")

</div>

Having the same trouble as many others have from my research, my data from NRD labelled as value is being sent as a string to influxdb and hence not recognised by Grafana.  
The set up is Atlas Scientific water sensors sending MQTT data to Mosquitto, then into Node Red, onto influxdb for storage and extracted by Grafana for display. Sensors with multiple outputs are ok as the label is a name extracted in the parser, ie percentage 89, are sent as a number, but single output sensors are labeled as value, and sent as a string.  
The same data sent to influxdb displays fine on the Node Red GUI.  
Sorry but i am a newbie, yet to work out how to cut and paste from Node Red flow workspace into here.

This sensor works

```auto
Sys4/DO/add97/DOsys4 : msg.payload : Object
object
PercentOxygen: 86.1
MGPerL: 7.83
created_at: "2021-11-06T23:13:55.8728987Z"
ModuleType: "DO"
value: "7.83"
Address: 97
Name: "DOsys4"
CompensationTemperature: 25

```

Multiple values with name labels.  
This is what is in the parser:

```auto
payload.PercentOxygen

```

This is what comes out.

```auto
07/11/2021, 10:20:02node: 8127b9f1260f2605
Sys4/DO/add97/DOsys4 : msg.payload : number
86.2

```

This doesn't work:

```auto
Sys4/ORP/add98/ORPsys4 : msg.payload : Object
object
created_at: "2021-11-06T23:24:06.425076Z"
ModuleType: "ORP"
value: "78"
Address: 98
Name: "ORPsys4"

```

A single value labeled value.  
Parser

```auto
payload.value

```

Parser output:

```auto
07/11/2021, 10:33:16node: 8127b9f1260f2605
Sys4/ORP/add98/ORPsys4 : msg.payload : string[2]
"77"

```

Have tried various "solutions" to output the value as a number but nothing seems to work.

PeterN "fishy"

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [7 November 2021 11:11 UTC](https://discourse.nodered.org/t/nrd-to-influxdb-strings/53315/2 "2021-11-07T11:11:33Z")

</div>

```auto
07/11/2021, 10:33:16node: 8127b9f1260f2605
Sys4/ORP/add98/ORPsys4 : msg.payload : string[2]
"77"

```

As I understand it, you just want the "77" from the above output, which as you noted is a string. I had a similar question and I learned you can use a change node, regex, or match to 'extract' the value you want. See [here](https://discourse.nodered.org/t/split-string-into-text-and-integers/49889/8).

---

<div class="post-metadata">

**Author:** ![Fishy](https://avatars.discourse-cdn.com/v4/letter/f/da6949/32.png) [@Fishy](https://discourse.nodered.org/u/Fishy)\
**Post date:** [8 November 2021 09:30 UTC](https://discourse.nodered.org/t/nrd-to-influxdb-strings/53315/3 "2021-11-08T09:30:08Z")

</div>

Thanks Grant!  
Was super simple, changed "payload.value" to "$number(payload.value)" in my change node and was then getting a number output instead of a string.  
I was still getting error messages in the debug window and then realised they where actually coming back from influxdb. I dropped the measurement which deleted the "String" key in the field and the next measurent loaded up as "Float" in the field key, which made Grafana happy! (and me!)

---

<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 November 2021 09:42 UTC](https://discourse.nodered.org/t/nrd-to-influxdb-strings/53315/4 "2021-11-08T09:42:04Z")

</div>

> [@Fishy](#):
>
> This sensor works
> 
> ```auto
> Sys4/DO/add97/DOsys4 : msg.payload : Object
> object
> PercentOxygen: 86.1
> MGPerL: 7.83
> created_at: "2021-11-06T23:13:55.8728987Z"
> ModuleType: "DO"
> value: "7.83"
> Address: 97
> Name: "DOsys4"
> CompensationTemperature: 25
> 
> ```

Notice that you are writing the field `value` as a string here too. That is very inneficient in grafana and will give you problems if you want to put it on a graph, for example. Also the module type, address, and name should almost certainly be in influx tags not fields, so you can efficiently use them in WHERE clauses.  
The created\_at field should almost certainly be a timestamp, not a string. Again it is inefficient to store a long string when a number would do. Is created\_at effectively the time of the measurment? If so then that should be in the influx time, or you can possibly let influx use the current time when you write the sample, and remove the created\_at from the data.

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [8 November 2021 10:50 UTC](https://discourse.nodered.org/t/nrd-to-influxdb-strings/53315/5 "2021-11-08T10:50:03Z")

</div>

Just to add my $0.02, I found [this webinar from Influxdb about Schema Design for IoT](https://www.youtube.com/watch?v=d99oCnOyA4k) to be extremely helpful.

---

<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:** [7 January 2022 10:50 UTC](https://discourse.nodered.org/t/nrd-to-influxdb-strings/53315/6 "2022-01-07T10:50:18Z")

</div>

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