# Store serial data to influx

**URL:** https://discourse.nodered.org/t/store-serial-data-to-influx/64220
**Category:** General
**Created:** [22 June 2022 00:44 UTC](https://discourse.nodered.org/t/store-serial-data-to-influx/64220 "2022-06-22T00:44:00Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![martijnspaan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/martijnspaan/32/102819_2.png) [@martijnspaan](https://discourse.nodered.org/u/martijnspaan)
#### Post date: [22 June 2022 00:44 UTC](https://discourse.nodered.org/t/store-serial-data-to-influx/64220/1 "2022-06-22T00:44:01Z")

</div>

Hi,

im new to Nodered as I think it can do what Im trying to accomplish: process incoming serial data into influx. The serial port input and the influx output is working fine. I can't seem to figure out how to process the incoming data.  
Hopefully somebody can tell me how to do this:

$DL799,Air\_Volume\_Flow,35.7\*1D

I would like to strip of the first part of the sentence: $DL799,  
then, the Air\_Volume\_Flow I would like to get outputted to Influx as an individual tag, with the value 35,7.  
strip of the \*1D part.  
there is a continuous stream of serial data in this format, with multiple different tag names.  
Ive tried, split, function, change and filter, but I can't work it out.

This should be very easy right?  
can somebody please tell me how to do this?

thank you very much

Martijn

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [22 June 2022 02:34 UTC](https://discourse.nodered.org/t/store-serial-data-to-influx/64220/2 "2022-06-22T02:34:51Z")

</div>

Here is a demo flow using a Function node to split() based on the comma seperated values and prepare the msg for influx .. im not sure about the end structure of your db so the msg may need some corrections but at least it'll give you some ideas for what you are trying to do.

```auto
[{"id":"7d3363de65139b00","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$DL799,Air_Volume_Flow,35.7*1D","payloadType":"str","x":390,"y":1260,"wires":[["1badcd7e92724e51","d75fa0d4e0283599"]]},{"id":"1badcd7e92724e51","type":"function","z":"54efb553244c241f","name":"prepare msg","func":"let arr = msg.payload.split(\",\")\n\nlet device = arr[0]\nlet measurement = arr[1]\nlet value = parseFloat(arr[2])\n\n// prepare msg for influx Batch Output Node\nmsg.payload = [\n {\n measurement: measurement,\n fields: {\n device: device,\n value: value,\n },\n tags: {\n tag: device\n },\n timestamp: new Date()\n }\n];\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":590,"y":1260,"wires":[["a8e0829c4bac856d"]]},{"id":"a8e0829c4bac856d","type":"debug","z":"54efb553244c241f","name":"to db","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":1260,"wires":[]},{"id":"d75fa0d4e0283599","type":"debug","z":"54efb553244c241f","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":520,"y":1180,"wires":[]}]

```

---

<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: [22 June 2022 06:06 UTC](https://discourse.nodered.org/t/store-serial-data-to-influx/64220/3 "2022-06-22T06:06:43Z")

</div>

> [@martijnspaan](#):
>
> I would like to get outputted to Influx as an individual tag, with the value 35,7.

Do you mean an individual measurement rather than tag?

---

<div class="post-metadata">

### Author: ![Jean-Luc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jean-luc/32/89996_2.png) [@Jean-Luc](https://discourse.nodered.org/u/Jean-Luc)
#### Post date: [22 June 2022 06:19 UTC](https://discourse.nodered.org/t/store-serial-data-to-influx/64220/4 "2022-06-22T06:19:21Z")

</div>

You can also use this **node-red-contrib-string** which allows you to manipulate a string in all directions without knowing the programming.  
For example:

- separate a string with a comma as a delimiter.
- Remove one or more characters at the beginning or at the end.
- Change a string into a number. Useful for your database.
- There are many more possibilities in this node

This node is just great for people like me who are not programmers  
The link to the [explanation of this node](https://flows.nodered.org/node/node-red-contrib-string)

---

<div class="post-metadata">

### Author: ![martijnspaan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/martijnspaan/32/102819_2.png) [@martijnspaan](https://discourse.nodered.org/u/martijnspaan)
#### Post date: [22 June 2022 06:55 UTC](https://discourse.nodered.org/t/store-serial-data-to-influx/64220/5 "2022-06-22T06:55:35Z")

</div>

Hi, yes, I meant an individual measurement stored with their value that comes after the comma

---

<div class="post-metadata">

### Author: ![martijnspaan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/martijnspaan/32/102819_2.png) [@martijnspaan](https://discourse.nodered.org/u/martijnspaan)
#### Post date: [22 June 2022 06:56 UTC](https://discourse.nodered.org/t/store-serial-data-to-influx/64220/6 "2022-06-22T06:56:13Z")

</div>

interesting, just installed this node and see what I can make it do

---

<div class="post-metadata">

### Author: ![martijnspaan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/martijnspaan/32/102819_2.png) [@martijnspaan](https://discourse.nodered.org/u/martijnspaan)
#### Post date: [22 June 2022 08:08 UTC](https://discourse.nodered.org/t/store-serial-data-to-influx/64220/7 "2022-06-22T08:08:26Z")

</div>

So,

ive tried to play around a bit, the simple code from UnborN seems to be quite effective. Im almost there. Influx is expecting me to output msg.measurement with the measurement name.

```auto
let arr = msg.payload.split(",")

let device = arr[0]
let measurement = arr[1]
let value = parseFloat(arr[2])

// prepare msg for influx Batch Output Node
msg.payload = [
    {
        value: value,
        
            }
];

return msg;

```

In my first post I mentioned tags, that should have been, measurements.  
Influx. The influx node is showing: **Tip:** If no measurement is specified, ensure **msg.measurement** contains the measurement name.

so, the separated part of the string, that is Air\_Volume\_Flow is already named: measurement and now the influx node is expecting this name back.

can you please tell me to pass the measurement name, in this case: Air\_Volume\_Flow back to msg.measurement?

thanks!

---

<div class="post-metadata">

### Author: ![martijnspaan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/martijnspaan/32/102819_2.png) [@martijnspaan](https://discourse.nodered.org/u/martijnspaan)
#### Post date: [22 June 2022 08:20 UTC](https://discourse.nodered.org/t/store-serial-data-to-influx/64220/8 "2022-06-22T08:20:27Z")

</div>

```auto
let arr = msg.payload.split(",")

let device = arr[0]
let measurement = arr[1]
let value = parseFloat(arr[2])

// prepare msg for influx Batch Output Node
msg.payload = [
    {
        value: value,
        
            }
];

msg.measurement = measurement;

return msg;

```

this does the trick, easy. thanks Unborn... really clean, short and effective code

---

<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: [21 August 2022 08:21 UTC](https://discourse.nodered.org/t/store-serial-data-to-influx/64220/9 "2022-08-21T08:21:02Z")

</div>

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