# SeeeD SenseCAP LoRaWAN CO2 Sensor function to emoncms

**URL:** https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014
**Category:** General
**Created:** [19 November 2021 22:40 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014 "2021-11-19T22:40:54Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![bgrattan3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bgrattan3/32/47488_2.png) [@bgrattan3](https://discourse.nodered.org/u/bgrattan3)
#### Post date: [19 November 2021 22:40 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/1 "2021-11-19T22:40:54Z")

</div>

Hello,  
I am not a programmer and am having lots of problems getting this sensor data into my emoncms server. The sensor seems to be working correctly and sending LoRa data to my RAK7244 server/gateway. I have four LoRa temp/hum (LHT65) sensors doing this (MQTT) and are working correctly (I had much help in setting up the function on node-red).  
I'm sure the problem must be my "function" syntax and construction as I'm getting errors of CO2\_Value\_PPM "undefined."  
I have attached what I think will give you enough information but will be happy to send more. Thanks in advance.  
Bob

```auto
> Data From LoRa gateway
> 
> Applications/CO2app/Devices/CO2device
> 
> applicationID:"18"
> applicationName:"CO2app"
> deviceName:"CO2device"
> devEUI:"2cf7f12122500013"
> rxInfo:
> frequency:904700000
> modulation:"LORA"
> bandwidth:125
> spreadingFactor:10
> codeRate:"4/5"
> polarizationInversion:false
> adr:true
> dr:0
> fCnt:44
> fPort:2
> data:"AQQQeMIGAFZv"
> 
> err:0
> CO2_Value_PPM:443 <<--this is the data I need sent
> measurementId:4100
> type:"report_telemetry"
> payload:"01041078C20600566F"
> valid:true
> tags:
> confirmedUplink:true
> devAddr:"01686a36"
> publishedAt:"2021-11-14T21:56:48.345702362Z"
> 
> =======================================================
> 
> debug message
> 
> 11/14/2021, 4:56:48 PMnode: 64d043922a280e22
> msg.payload : Object
> object
> CO2_Value_PPM: undefined
> 
> =======================================================
> 
> emoncms node
> 
> 
> Emoncms server emonpi
> Node CO2
> Data Type valid JSON object
> Name CO2
> 
> =======================================================
> 
> From Node-Red Function Node
> 
> On Message
> input = msg.payload
> var CO2_Value_PPM = input.object.CO2_Value_PPM
> msg2 = {payload:{"CO2_Value_PPM":realDataValue}};
> return msg2;
> 
> =====================================================
> 
> From Json Node
> 
> 
> Action Always convery to JavaScript Object
> Property msg payload
> Name CO2
> 
> ====================================================
> 
> MQTT in node
> 
> 
> Server RAK7244
> Topic application/18/device/2cf7f12122500013/rx
> QoS 1
> Output auto-detect (string or buffer)
> Name CO2
> 
> ==================================================

```

---

<div class="post-metadata">

### Author: ![ScheepersJohan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scheepersjohan/32/39556_2.png) [@ScheepersJohan](https://discourse.nodered.org/u/ScheepersJohan)
#### Post date: [20 November 2021 06:07 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/2 "2021-11-20T06:07:42Z")

</div>

Welcome Bob to the Node-red forum.

What LORAWAN server are you using?

Put a debug node and connect it to the MQTT node, what do you see there? Post that json please.

---

<div class="post-metadata">

### Author: ![iiLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iilaw/32/14782_2.png) [@iiLaw](https://discourse.nodered.org/u/iiLaw)
#### Post date: [20 November 2021 11:11 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/3 "2021-11-20T11:11:50Z")

</div>

The first part looks like the "Live Device Data" view from RAK GW  
So your setup

> [end-device] -- [RAK GW] -- [MQTT] -- [Node-RED -- { Function Node} -- (emoncms)] ?

Could you share your flow as it's not clear where you are doing your decode  
in RAK GW using CayenneLPP ?  
in Node-RED using javascript for Dragaino payload decoder??

---

<div class="post-metadata">

### Author: ![bgrattan3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bgrattan3/32/47488_2.png) [@bgrattan3](https://discourse.nodered.org/u/bgrattan3)
#### Post date: [20 November 2021 15:35 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/4 "2021-11-20T15:35:23Z")

</div>

First of all, thanks to @ScheepersJohan and @iiLaw for answering my plea for help.  
Here is some additional information you requested. Much appreciated.  
Cheers,  
Bob (Ashland, VA)

My system is a RAK7244 LoRa server/gateway on an RPI4 (buster) running chirpstack.  
I have another RPI4 running emoncms (an energy monitoring system) which can receive MQTT data from other brokers to post on its web page (locally on the RPI4).  
I already have 4 LHT65 temp/hum sensors configured with a node-red flow which are  
working and sending data through the LoRa server to the emoncms server.

The problem is that my new Seeed CO2 sensor is sending data through the LoRa  
system but my node-red configuration isn't getting the data to the emoncms server.  
The path seems to be connected (a node has been created on emoncms) but the  
data isn't beeing parsed correctly and sent to emoncms. I need to extract the  
portion "CO2\_Value\_PPM" with data and send it to emoncms.

**My error:**

```auto
> 11/20/2021, 10:07:41 AM node: CO2 
> function : (error)
> "TypeError: Cannot read property 
> 
> 'CO2_Value_PPM' of undefined"

**My function which isn't working:**

> input = msg.payload
> var CO2_Value_PPM = input.object.CO2_Value_PPM
> msg2 = {payload:{"CO2_Value_PPM":realDataValue}};
> return msg2;

```

**Data being sent from sensor to LoRa server and decoded:**

```auto
> ChirpStack.io
> Applications/CO2app/Devices/CO2device
> 
> applicationID:"18"
> applicationName:"CO2app"
> deviceName:"CO2device"
> devEUI:"2cf7f12122500013"
> rxInfo:
> frequency:903900000
> modulation:"LORA"
> bandwidth:125
> spreadingFactor:10
> codeRate:"4/5"
> polarizationInversion:false
> adr:true
> dr:0
> fCnt:33
> fPort:2
> data:"AQQQqLoGADTR"
> err:0
> CO2_Value_PPM:441 <--[the data I need]
> measurementId:4100
> type:"report_telemetry"
> payload:"010410A8BA060034D1"
> valid:true
> tags:
> confirmedUplink:true
> devAddr:"00d0e7c1"
> publishedAt:"2021-11-20T14:06:28.062161582Z"

```

**My node-red flow:**

 ![flow2_IMG_1366](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/2/f2c12276933380e1ac467eb1a4d2d35d3fe86cb7.jpeg)

**Section from CO2 sensor decoder on chirpstack server:**

```auto
> if (checkDataIdIsMeasureUpload(dataID)) {
> // if telemetry.
> decoded.messages.push({
> type: "report_telemetry",
> measurementId: dataID,
> // measurementValue: realDataValue
> CO2_Value_PPM: realDataValue
> });

```

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [20 November 2021 16:00 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/5 "2021-11-20T16:00:08Z")

</div>

make sure the MQTT node is set to output a parsed JSON object.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/9/d9f63b3f2e24c6e0a43eb5e1bbe744540036c382.png)

---

<div class="post-metadata">

### Author: ![bgrattan3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bgrattan3/32/47488_2.png) [@bgrattan3](https://discourse.nodered.org/u/bgrattan3)
#### Post date: [20 November 2021 17:16 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/6 "2021-11-20T17:16:56Z")

</div>

Thanks @dceejay, I made the change but nothing seemed to change. See below:

 ![CO22021-11-20](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/d/2de214cd9e3fe9845b9e448a40c97da8f2fd8c02.png)

---

<div class="post-metadata">

### Author: ![iiLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iilaw/32/14782_2.png) [@iiLaw](https://discourse.nodered.org/u/iiLaw)
#### Post date: [20 November 2021 18:40 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/7 "2021-11-20T18:40:49Z")

</div>

Ok Dave is pointing you the right direction your issue I believe your still passing a string to the function node. Can you try wiring from MQTT-in to {CO2} function node pls.  
Can you copy the debgug output from each debug node pls an post to this thread.

It would help if name your debug nodes so we can see what is emitted as it's not clear from your screen shots "MQTT-uplink" for example for LoRaWAN uplinks.

---

<div class="post-metadata">

### Author: ![bgrattan3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bgrattan3/32/47488_2.png) [@bgrattan3](https://discourse.nodered.org/u/bgrattan3)
#### Post date: [20 November 2021 19:54 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/8 "2021-11-20T19:54:57Z")

</div>

Ok, hope I have done what you need. Flow 2 has been relabeled for clarity:

 ![flow2-2021-11-20-230](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/af8f0a2a663bcea54d0c2f1668c42f97aa98aa8b.png)

I created flow3 and connected the MQTT uplink directly to function. There was no connection success to emoncms:

 ![flow32021-11-20](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f6c28f13004e5a38f910af71acf5796b4da18c9d.png)

---

<div class="post-metadata">

### Author: ![bgrattan3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bgrattan3/32/47488_2.png) [@bgrattan3](https://discourse.nodered.org/u/bgrattan3)
#### Post date: [20 November 2021 20:07 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/9 "2021-11-20T20:07:18Z")

</div>

One thing I did notice was that the sensor doesn't always send CO2 data with each upload. Normally it sends data every 60 minutes which always includes the CO2 information "CO2\_Value\_PPM" However, the last screen shots resulted in me resetting the device to make it send something before the hour was up. Anyway, flow 3 never seemed to make it to the emoncms server.

---

<div class="post-metadata">

### Author: ![ScheepersJohan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scheepersjohan/32/39556_2.png) [@ScheepersJohan](https://discourse.nodered.org/u/ScheepersJohan)
#### Post date: [20 November 2021 21:04 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/10 "2021-11-20T21:04:35Z")

</div>

Copy each debugs payload and past in between 3 ```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/d/9d7f1925c47dfe9cb8571e54957ea1ccc8bff9cb.png)

![copy payload](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/f/4f37e17adb2e4b1c9cf83056d2f846cdf68f455c.gif)

---

<div class="post-metadata">

### Author: ![iiLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iilaw/32/14782_2.png) [@iiLaw](https://discourse.nodered.org/u/iiLaw)
#### Post date: [20 November 2021 21:28 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/11 "2021-11-20T21:28:06Z")

</div>

Hi think until you give us what we've asked for,  
there is not much we can do more at the moment to help.

BTW what is the make & model of your CO2 sensor.

---

<div class="post-metadata">

### Author: ![bgrattan3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bgrattan3/32/47488_2.png) [@bgrattan3](https://discourse.nodered.org/u/bgrattan3)
#### Post date: [20 November 2021 21:42 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/12 "2021-11-20T21:42:08Z")

</div>

```auto
11/20/2021, 3:51:38 PMnode: RAK7244-MQTTup
application/18/device/2cf7f12122500013/rx : msg.payload : Object
object
applicationID: "18"
applicationName: "CO2app"
deviceName: "CO2device"
devEUI: "2cf7f12122500013"
txInfo: object
frequency: 905300000
dr: 0
adr: true
fCnt: 16
fPort: 2
data: "AQQQOCYGACET"
object: object
err: 0
messages: array[1]
0: object
CO2_Value_PPM: 403
measurementId: 4100
type: "report_telemetry"
payload: "010410382606002113"
valid: true

```

```auto
11/20/2021, 3:51:39 PMnode: CO2function : (error)
"TypeError: Cannot read property 'CO2_Value_PPM' of undefined"

```

```auto
11/20/2021, 3:51:39 PMnode: JSON parser
application/18/device/2cf7f12122500013/rx : msg.payload : string[560]
string[560]

{
    "applicationID": "18",
    "applicationName": "CO2app",
    "deviceName": "CO2device",
    "devEUI": "2cf7f12122500013",
    "txInfo": {
        "frequency": 905300000,
        "dr": 0
    },
    "adr": true,
    "fCnt": 16,
    "fPort": 2,
    "data": "AQQQOCYGACET",
    "object": {
        "err": 0,
        "messages": [
            {
                "CO2_Value_PPM": 403,
                "measurementId": 4100,
                "type": "report_telemetry"
            }
        ],
        "payload": "010410382606002113",
        "valid": true
    }
}

```

Sorry, I'm new at this.  
Seeed SenseCAP SOLO CO2 5000

---

<div class="post-metadata">

### Author: ![bgrattan3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bgrattan3/32/47488_2.png) [@bgrattan3](https://discourse.nodered.org/u/bgrattan3)
#### Post date: [20 November 2021 21:57 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/13 "2021-11-20T21:57:46Z")

</div>

From flow 3 where MQTTin is connected directly to function:

```auto
11/20/2021, 4:52:52 PMnode: CO2function : (error)
"ReferenceError: realDataValue is not defined (line 3, col 34)"

```

```auto
11/20/2021, 4:52:52 PMnode: RAK7244-MQTTin
application/18/device/2cf7f12122500013/rx : msg.payload : Object
object
applicationID: "18"
applicationName: "CO2app"
deviceName: "CO2device"
devEUI: "2cf7f12122500013"
txInfo: object
frequency: 904100000
dr: 0
adr: true
fCnt: 17
fPort: 2
data: "AQQQWHQGAJ68"
object: object
err: 0
messages: array[1]
0: object
CO2_Value_PPM: 423
measurementId: 4100
type: "report_telemetry"
payload: "010410587406009EBC"
valid: true

```

Function code:

```auto
input = msg.payload
var CO2_Value_PPM = input.object.CO2_Value_PPM
msg2 = {payload:{"CO2_Value_PPM":realDataValue}};
return msg2;

```

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [20 November 2021 22:01 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/14 "2021-11-20T22:01:39Z")

</div>

Hi - have a look at [Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages) - especially the understanding the structure of a message section - It shows how to use the debug window to find the path to the property you want.  
If you follow that you should find it is in `msg.payload.object.messages[0].CO2_Value_PPM`

---

<div class="post-metadata">

### Author: ![iiLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iilaw/32/14782_2.png) [@iiLaw](https://discourse.nodered.org/u/iiLaw)
#### Post date: [20 November 2021 22:02 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/15 "2021-11-20T22:02:16Z")

</div>

ok what are the settings of the JSON node it's looking like payload is a string not a object.  
So from have you tried dropping the JSON node and wiring the MQTT to function node

I don't know that device but many devices send a "settings" msg after joining which is different form from a periodic measurement.

What would help is an export of your flow with that we can copy it on to our NR instances to take look.  
But your not far away from sorting it.

---

<div class="post-metadata">

### Author: ![bgrattan3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bgrattan3/32/47488_2.png) [@bgrattan3](https://discourse.nodered.org/u/bgrattan3)
#### Post date: [20 November 2021 22:13 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/16 "2021-11-20T22:13:37Z")

</div>

Ok, I'll work on an export. I'll need to read up how to do it.  
In the meantime here is some info from a sensor I have working on this system. It may give you a clue.

Maybe this will help

Example of an LHT65 temp/hum sensor which is working correctly:

```auto
11/20/2021, 4:56:45 PMnode: MQTTin from RAK7244
application/7/device/a84041ce918279c4/rx : msg.payload : string[316]
"{"applicationID":"7","applicationName":"LHT65","deviceName":"LHT65w","devEUI":"a84041ce918279c4","txInfo":{"frequency":904500000,"dr":0},"adr":true,"fCnt":2527,"fPort":2,"data":"y78H4gGYAQfDf/8=","object":{"BatV":3.007,"Ext_sensor":"Temperature Sensor LHT65","Hum_SHT":"40.8","TempF_DS":"67.77","TempF_SHT":"68.32"}}"

```

```auto
11/20/2021, 4:56:45 PMnode: 16fb5469bd0c1de1
application/7/device/a84041ce918279c4/rx : msg.payload : Object
object
applicationID: "7"
applicationName: "LHT65"
deviceName: "LHT65w"
devEUI: "a84041ce918279c4"
txInfo: object
frequency: 904500000
dr: 0
adr: true
fCnt: 2527
fPort: 2
data: "y78H4gGYAQfDf/8="
object: object
BatV: 3.007
Ext_sensor: "Temperature Sensor LHT65"
Hum_SHT: "40.8"
TempF_DS: "67.77"
TempF_SHT: "68.32"

```

```auto
11/20/2021, 4:56:45 PMnode: LHT65W
msg.payload : Object
object
BatV: 3.007
Hum_SHT: "40.8"
TempF_DS: "67.77"
TempF_SHT: "68.32"

```

function coding for LHT65

```auto
input = msg.payload
var BatV = input.object.BatV
var Hum_SHT = input.object.Hum_SHT
var TempF_DS= input.object.TempF_DS
var TempF_SHT= input.object.TempF_SHT
msg2 = {payload:{"BatV":BatV, "Hum_SHT":Hum_SHT, "TempF_DS":TempF_DS,"TempF_SHT":TempF_SHT}};
return msg2;

```

---

<div class="post-metadata">

### Author: ![bgrattan3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bgrattan3/32/47488_2.png) [@bgrattan3](https://discourse.nodered.org/u/bgrattan3)
#### Post date: [20 November 2021 22:22 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/17 "2021-11-20T22:22:25Z")

</div>

[flows.json](https://discourse.nodered.org/uploads/short-url/fjRKQDVNOorBgqc6tCQ9q2FJQRa.json) (3.8 KB)

Export of flow 2

Thanks for your patience and help.

---

<div class="post-metadata">

### Author: ![iiLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iilaw/32/14782_2.png) [@iiLaw](https://discourse.nodered.org/u/iiLaw)
#### Post date: [21 November 2021 09:24 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/18 "2021-11-21T09:24:30Z")

</div>

Ok it was your JS code in function node  
I've take the liberty of re-writing it

```auto
// Test to see if CO2 measurement is present in uplink
// Assumption is msg.payload.object.messages[] array is always present
// if not then we need to test in different way
// why do we do this to ensure we don't send rubbish to emoncms

if ("CO2_Value_PPM" in msg.payload.object.messages[0]){
    msg = {payload:{"CO2_Value_PPM":msg.payload.object.messages[0].CO2_Value_PPM}};
    return msg;
}

```

Modified flow

```auto
[
    {
        "id": "e21fb0fe83c49f5b",
        "type": "mqtt in",
        "z": "7db6160ca3e53565",
        "name": "RAK7244",
        "topic": "application/18/device/2cf7f12122500013/rx",
        "qos": "1",
        "datatype": "json",
        "broker": "dc0cfbd7.ba7858",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 121,
        "y": 100,
        "wires": [
            [
                "3042098831fd60d9",
                "483e91506c5bcd77"
            ]
        ]
    },
    {
        "id": "64d043922a280e22",
        "type": "debug",
        "z": "7db6160ca3e53565",
        "name": "function-on message",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 600,
        "y": 160,
        "wires": []
    },
    {
        "id": "3042098831fd60d9",
        "type": "debug",
        "z": "7db6160ca3e53565",
        "name": "RAK7244-MQTTup",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 350,
        "y": 160,
        "wires": []
    },
    {
        "id": "721ea6847b236a6a",
        "type": "inject",
        "z": "7db6160ca3e53565",
        "name": "Test JSON",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"applicationID\":\"18\",\"applicationName\":\"CO2app\",\"deviceName\":\"CO2device\",\"devEUI\":\"2cf7f12122500013\",\"txInfo\":{\"frequency\":905300000,\"dr\":0},\"adr\":true,\"fCnt\":16,\"fPort\":2,\"data\":\"AQQQOCYGACET\",\"object\":{\"err\":0,\"messages\":[{\"CO2_Value_PPM\":403,\"measurementId\":4100,\"type\":\"report_telemetry\"}],\"payload\":\"010410382606002113\",\"valid\":true}}",
        "payloadType": "json",
        "x": 120,
        "y": 40,
        "wires": [
            [
                "483e91506c5bcd77"
            ]
        ]
    },
    {
        "id": "483e91506c5bcd77",
        "type": "function",
        "z": "7db6160ca3e53565",
        "name": "CO2 to emoncms",
        "func": "// Test to see if CO2 measurment is present in uplink\n// Assumtion is msg.payload.object.messages[] array is always present\n// if not then we need to test in diffrent way\n// why do we do this to ensure we don't send rubish to emoncms\n\nif (\"CO2_Value_PPM\" in msg.payload.object.messages[0]){\n msg = {payload:{\"CO2_Value_PPM\":msg.payload.object.messages[0].CO2_Value_PPM}};\n return msg;\n}",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 356,
        "y": 100,
        "wires": [
            [
                "64d043922a280e22"
            ]
        ]
    },
    {
        "id": "dc0cfbd7.ba7858",
        "type": "mqtt-broker",
        "name": "RAK7244",
        "broker": "192.168.1.10",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    }
]

```

---

<div class="post-metadata">

### Author: ![iiLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iilaw/32/14782_2.png) [@iiLaw](https://discourse.nodered.org/u/iiLaw)
#### Post date: [21 November 2021 09:55 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/19 "2021-11-21T09:55:48Z")

</div>

It's as I thought when sensor joins the LNS it sends an Initial packet. Then send what Seed calls "Measurement data packets" e.g. CO2 measurement

_Initial packets（no need to learn about these initial packets）_  
_- One packet with device info including hardware version, software version, battery level, sensor_  
_hardware & software version, sensor EUI, power, and sensor power time counter at each channel._

---

<div class="post-metadata">

### Author: ![bgrattan3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bgrattan3/32/47488_2.png) [@bgrattan3](https://discourse.nodered.org/u/bgrattan3)
#### Post date: [21 November 2021 16:09 UTC](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014/20 "2021-11-21T16:09:22Z")

</div>

Hi Lawrence,  
It seems to be working! I have dropped the JSON node and added your code to the function. I'll wait a day or so to be sure all is well. At least the first hour's data went to and was recorded in the emoncms database. My webpage is [N4MRV-1 --- Ashland, Virginia Current Weather Conditions](http://grattans.org/wx) where I plan to display CO2 PPM readings. I now will have a front row seat to watch our planet circling the drain...  
Thank you @iiLaw, @dceejay, and @ScheepersJohan -- very much appreciated!  
Cheers,  
Bob

[Next page](https://discourse.nodered.org/t/seeed-sensecap-lorawan-co2-sensor-function-to-emoncms/54014.md?page=2)
