NRD to Influxdb-strings

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

Sys4/DO/add97/DOsys4 : msg.payload : 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:


This is what comes out.

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

This doesn't work:

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

A single value labeled value.


Parser output:

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

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

PeterN "fishy"

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

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.

1 Like

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!)

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.

Just to add my $0.02, I found this webinar from Influxdb about Schema Design for IoT to be extremely helpful.

1 Like

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