# How to retrieve individual parts of data from Serial port (arduino) and insert into InfluxDB

**URL:** <https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624>\
**Category:** General\
**Created:** [21 October 2020 09:47 UTC](https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624 "2020-10-21T09:47:34Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![alyx99](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@alyx99](https://discourse.nodered.org/u/alyx99)\
**Post date:** [21 October 2020 09:47 UTC](https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624/1 "2020-10-21T09:47:34Z")

</div>

hi, i am meeting issue when trying to insert data retrieved from the Serial port into InfluxDB, can anyone help me on splitting up the retrieved data into individual parts before inserting them into InfluxDB?

---

<div class="post-metadata">

**Author:** ![alyx99](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@alyx99](https://discourse.nodered.org/u/alyx99)\
**Post date:** [21 October 2020 09:50 UTC](https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624/2 "2020-10-21T09:50:33Z")

</div>

as of now, i am receiving 2 components of information from the arduino through serial  
29.79 (actual reading of the temperature sensor) 31 (preset threshold)  
1 (the lightbulb is on) 250 (the reading from the LDR)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/3/33fa51b0c3ccd133109291f17fad1739152ad500.png)

---

<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:** [21 October 2020 10:06 UTC](https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624/3 "2020-10-21T10:06:41Z")

</div>

Are you in control of the data from the arduino, if so then it would be easier if you formatted it as a json string, something like  
`{"temperature": 29.79, "threshold": 31}`  
Then in node red you could feed it through a JSON node and it the values would be accessible as `msg.payload.temperature` and `msg.payload.threshold`.

---

<div class="post-metadata">

**Author:** ![alyx99](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@alyx99](https://discourse.nodered.org/u/alyx99)\
**Post date:** [21 October 2020 10:13 UTC](https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624/4 "2020-10-21T10:13:23Z")

</div>

hi, i have managed to change the obtained fields  
how do i configure the potential JSON node to feed values into the DB?  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/e/fe63edb8983ce65a8e48c98b3b635ecf187b7f65.png)

---

<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:** [21 October 2020 10:17 UTC](https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624/5 "2020-10-21T10:17:29Z")

</div>

You haven't got the quotes right, and you haven't got the {}. Once that is fixed feed it through a JSON node and check it looks right. Also use simple names for things not long strings with special chars and spaces. Otherwise it is a lot of tedious typing to get the data. For example you would have to use  
`msg.payload["Light is (1,on;2,off)"]`  
instead of something like  
`msg.payload.light_state`

---

<div class="post-metadata">

**Author:** ![alyx99](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@alyx99](https://discourse.nodered.org/u/alyx99)\
**Post date:** [21 October 2020 10:28 UTC](https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624/6 "2020-10-21T10:28:57Z")

</div>

hi, have i got it right?  
it seems that i am having difficulties quoting individual names such as "Temperature"  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/6/36e55c77663cf78f5c2987b5bb4cff06dd162d4a.png)

---

<div class="post-metadata">

**Author:** ![alyx99](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@alyx99](https://discourse.nodered.org/u/alyx99)\
**Post date:** [21 October 2020 10:31 UTC](https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624/7 "2020-10-21T10:31:46Z")

</div>

i dont think i am able to unquote ("") the entire string because that is the automatic output from the Arduino

---

<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:** [21 October 2020 10:52 UTC](https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624/8 "2020-10-21T10:52:17Z")

</div>

The quotes round the outside are not part of the string they are just the debug node showing that it is a string. Probably in the arduino code you need to escape the double quotes, so something like `\"` in the text generated where you want them, so in the arduino code (which I don't know) you might have something like  
`"\"temperature\": ..."`  
Also you don't want the new line on the end (but that might be being added in node red if you have told it to add new line each message in the input node).

---

<div class="post-metadata">

**Author:** ![alyx99](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@alyx99](https://discourse.nodered.org/u/alyx99)\
**Post date:** [21 October 2020 10:58 UTC](https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624/9 "2020-10-21T10:58:47Z")

</div>

This is what i have obtained after adding "  
I managed to put it through a json node  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/a/1a9219cde16319840a741d4a7ed8a5d1f6369c77.png)

---

<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:** [21 October 2020 11:01 UTC](https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624/10 "2020-10-21T11:01:42Z")

</div>

Excellent. Now the next question is what is the structure of the influx database that you want? So what measurements, fields and tags do you want?

---

<div class="post-metadata">

**Author:** ![alyx99](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@alyx99](https://discourse.nodered.org/u/alyx99)\
**Post date:** [21 October 2020 11:03 UTC](https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624/11 "2020-10-21T11:03:21Z")

</div>

it can just be inserted according to the fields (temperature, threshold) (light, LDR\_value) into two seperate Influx DB with name temp and light

---

<div class="post-metadata">

**Author:** ![alyx99](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@alyx99](https://discourse.nodered.org/u/alyx99)\
**Post date:** [21 October 2020 11:08 UTC](https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624/12 "2020-10-21T11:08:13Z")

</div>

both with location set as "office" so i will be able to filter through the database easier when using grafana

---

<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:** [21 October 2020 11:21 UTC](https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624/13 "2020-10-21T11:21:26Z")

</div>

I advise not using separate influx databases, just use separate measurements within one database. Otherwise you are just adding complexity. If you look at the influxdb out node it tells you how to format the data for the fields and tags in the help text.  
" If **msg.payload** is an array containing two objects, the first object will be written as the set of named fields, the second is the set of named tags."  
So you will want an array with the first element (the fields) containing the temperature and threshold object that is currently in the payload and the second element (the tags) will be something like  
`{location: "office"}`  
You can do that in a change node but I would probably do it in a change node, something like

```auto
msg.payload = [msg.payload, {location: "office"}]

```

and a similar thing for the other one, though that needs to go to a different measurement, which you can either do by using two influxdb nodes or by setting msg.measurement.

---

<div class="post-metadata">

**Author:** ![alyx99](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@alyx99](https://discourse.nodered.org/u/alyx99)\
**Post date:** [21 October 2020 15:01 UTC](https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624/14 "2020-10-21T15:01:58Z")

</div>

thank you so much i have accomplished my objective

---

<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:** [21 October 2020 15:08 UTC](https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624/15 "2020-10-21T15:08:43Z")

</div>

Excellent, could you mark the thread as Solved so it is clear it is sorted. Click the three dots at the bottom of the post that best represents a fix.

---

<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:** [4 November 2020 15:08 UTC](https://discourse.nodered.org/t/how-to-retrieve-individual-parts-of-data-from-serial-port-arduino-and-insert-into-influxdb/34624/16 "2020-11-04T15:08:57Z")

</div>

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