# NodeRED and InfluxDB - One Measurement more fields

**URL:** https://discourse.nodered.org/t/nodered-and-influxdb-one-measurement-more-fields/72536
**Category:** General
**Created:** [21 December 2022 15:24 UTC](https://discourse.nodered.org/t/nodered-and-influxdb-one-measurement-more-fields/72536 "2022-12-21T15:24:35Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Egnos](https://avatars.discourse-cdn.com/v4/letter/e/bbe5ce/32.png) [@Egnos](https://discourse.nodered.org/u/Egnos)
#### Post date: [21 December 2022 15:24 UTC](https://discourse.nodered.org/t/nodered-and-influxdb-one-measurement-more-fields/72536/1 "2022-12-21T15:24:35Z")

</div>

Hi all, I'm new to the Forum and also to NodeRED. I hope you can help me:  
I created a container with NodeRED Ver. 1.3.4 and I'm doing various experiments.  
One of them is to extrapolate the payload of this request from this message [https://api.waqi.info/feed/A144943/?token=8f3999b079d169a52edadec8124708c605e63e90](https://api.waqi.info/feed/A144943/?token=8f3999b079d169a52edadec8124708c605e63e90)

I managed to identify the fields I need and they are:

- payload.data.aqi
- payload.data.iaqi.pm10.v
- payload.data.iaqi.pm25.v

I managed to write these values in InfluxDB but each with a different "measurement".  
I would like these values to be written under one "measurement" with 3 fields (Time, AQI, PM10 and PM25).

To write to InfluxDB I use "node-red-contrib-influxdb".

I've read a lot on the net (discussion and official guides...) and I've managed to do a lot of things but I'm missing the last piece that I couldn't understand... could you help me?

Thank you all.

---

<div class="post-metadata">

### Author: ![jodelkoenig](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jodelkoenig/32/44645_2.png) [@jodelkoenig](https://discourse.nodered.org/u/jodelkoenig)
#### Post date: [21 December 2022 15:40 UTC](https://discourse.nodered.org/t/nodered-and-influxdb-one-measurement-more-fields/72536/2 "2022-12-21T15:40:19Z")

</div>

Just send the data to the same influxdb out node. create on entry and assign your assignment there.

---

<div class="post-metadata">

### Author: ![Egnos](https://avatars.discourse-cdn.com/v4/letter/e/bbe5ce/32.png) [@Egnos](https://discourse.nodered.org/u/Egnos)
#### Post date: [21 December 2022 15:45 UTC](https://discourse.nodered.org/t/nodered-and-influxdb-one-measurement-more-fields/72536/3 "2022-12-21T15:45:05Z")

</div>

Hi @jodelkoenig, could you show me how to do it?  
Which nodes should I use?  
What code should I write to isolate these fields and tell InfluxDB to create a "Measurement" with 4 fields (Time, AQI, PM10 and PM25)?

Thanks!

---

<div class="post-metadata">

### Author: ![jodelkoenig](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jodelkoenig/32/44645_2.png) [@jodelkoenig](https://discourse.nodered.org/u/jodelkoenig)
#### Post date: [21 December 2022 15:55 UTC](https://discourse.nodered.org/t/nodered-and-influxdb-one-measurement-more-fields/72536/4 "2022-12-21T15:55:58Z")

</div>

![Bildschirm­foto 2022-12-21 um 16.51.53](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/3/13fe4e0c51a6b4d15484022db5d979fef15f5783.png)

This I send to the one influxdb out node via different function nodes:

```auto
msg.payload = [{
    light: state
},
{
    room: flow.get("name"),
    category:"Beleuchtung",
    device:"Decke"
}];
return msg;

```

light could be Time, AQI, PM10 and PM25  
room, category, device could be any tag you like

---

<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 December 2022 16:06 UTC](https://discourse.nodered.org/t/nodered-and-influxdb-one-measurement-more-fields/72536/5 "2022-12-21T16:06:04Z")

</div>

Or, if you don't have any tags then you just need the payload to be a simple object containing the fields. Something like this in a function node

```auto
msg.payload = {
  PM10: msg.payload.data.iaqi.pm10.v,
  PM25: msg.payload.data.iaqi.pm25.v,
  etc...
}
return msg

```

Or you can do the same in a Change node.

---

<div class="post-metadata">

### Author: ![Egnos](https://avatars.discourse-cdn.com/v4/letter/e/bbe5ce/32.png) [@Egnos](https://discourse.nodered.org/u/Egnos)
#### Post date: [21 December 2022 16:08 UTC](https://discourse.nodered.org/t/nodered-and-influxdb-one-measurement-more-fields/72536/6 "2022-12-21T16:08:19Z")

</div>

I try to write what I understand.  
I have:

- an "INJECT" node that acts as a trigger;
- an "HTTP REQUEST" node to capture the msg (return: a parsed JSON object)
- an "FUNCTION" node to tell InfluxDB how to save the data;

```auto
msg.payload = [{
    aqi: state,
    pm10: state,
    pm25: state
},
{
    room: flow.get("name"),
    category:"Beleuchtung",
    device:"Decke"
}];
return msg;

```

- finally an "INFLUXDB OUT" node to save the data in a certain DB with a certain "Measurement"

Is the flow correct?  
Is the code in the "FUNCTION" node correct?

Thank you very much!

---

<div class="post-metadata">

### Author: ![jodelkoenig](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jodelkoenig/32/44645_2.png) [@jodelkoenig](https://discourse.nodered.org/u/jodelkoenig)
#### Post date: [21 December 2022 16:48 UTC](https://discourse.nodered.org/t/nodered-and-influxdb-one-measurement-more-fields/72536/7 "2022-12-21T16:48:53Z")

</div>

You should skip:

```auto
,
{
    room: flow.get("name"),
    category:"Beleuchtung",
    device:"Decke"
}

```

or adopt correspondingly if you would like to use tags. You might not need it, then just delete it from your code.

EDIT:

Or ... just take Colin's example 😄

---

<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 December 2022 17:26 UTC](https://discourse.nodered.org/t/nodered-and-influxdb-one-measurement-more-fields/72536/8 "2022-12-21T17:26:38Z")

</div>

I didn't say previously, but you don't need to provide a time to influx, if the data is for the current time. Influx will add it automatically.

In addition, I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

### Author: ![Egnos](https://avatars.discourse-cdn.com/v4/letter/e/bbe5ce/32.png) [@Egnos](https://discourse.nodered.org/u/Egnos)
#### Post date: [21 December 2022 19:35 UTC](https://discourse.nodered.org/t/nodered-and-influxdb-one-measurement-more-fields/72536/9 "2022-12-21T19:35:15Z")

</div>

I tried to put the code you suggested in the "FUNCTION" node:

```auto
msg.payload = {
  PM10: msg.payload.data.iaqi.pm10.v,
  PM25: msg.payload.data.iaqi.pm25.v,
  AQI: payload.data.aqi
}
return msg

```

...but i have this error:

```auto
21/12/2022, 20:32:16node: Formatting
function : (error)
"ReferenceError: payload is not defined (line 4, col 10)"

```

---

<div class="post-metadata">

### Author: ![jodelkoenig](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jodelkoenig/32/44645_2.png) [@jodelkoenig](https://discourse.nodered.org/u/jodelkoenig)
#### Post date: [21 December 2022 19:39 UTC](https://discourse.nodered.org/t/nodered-and-influxdb-one-measurement-more-fields/72536/10 "2022-12-21T19:39:39Z")

</div>

Check line 4 and compare it to line 3 and 2. I assume you want to refer to msg.payload.data.aqi, right?

---

<div class="post-metadata">

### Author: ![Egnos](https://avatars.discourse-cdn.com/v4/letter/e/bbe5ce/32.png) [@Egnos](https://discourse.nodered.org/u/Egnos)
#### Post date: [21 December 2022 19:50 UTC](https://discourse.nodered.org/t/nodered-and-influxdb-one-measurement-more-fields/72536/11 "2022-12-21T19:50:38Z")

</div>

Thanks, now work!!  
I added` msg.` before `payload.data.aqi`  
It's very strange because if I copy the path from the original message payload printed by NodeRED (I followed the official guide...) I have this: `payload.data.aqi`, without `msg.` front!

---

<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 December 2022 20:22 UTC](https://discourse.nodered.org/t/nodered-and-influxdb-one-measurement-more-fields/72536/12 "2022-12-21T20:22:25Z")

</div>

It gives you the path within the message.

---

<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 January 2023 20:22 UTC](https://discourse.nodered.org/t/nodered-and-influxdb-one-measurement-more-fields/72536/13 "2023-01-04T20:22:58Z")

</div>

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