>>> Join Us in the Fight Against Air Pollution

AirGradient Forum

S8 CO2 reading of -1

That is really strange. I can only say that the -1, which is a return value, does not occur anymore. I have never experienced the 65xxx error.

What you can do, is to change to code in the library AirGradient.cpp and monitor the responses on the serial port. The first byte in the CO2Response array should be 254 decimal or FE hex for a correct read.

int AirGradient::getCO2_Raw(){
  const byte CO2Command[] = {0xFE, 0X44, 0X00, 0X08, 0X02, 0X9F, 0X25};
  byte CO2Response[] = {0,0,0,0,0,0,0};
  
  _SoftSerial_CO2->write(CO2Command, 7);
  delay(100);
  
  if (_SoftSerial_CO2->available()){
	for (int i=0; i < 7; i++) {
      int byte = _SoftSerial_CO2->read();
      CO2Response[i] = byte;
	  if (CO2Response[0] != 254) {
		  Serial.println("Invalid serial read"); //added for debugging
	      Serial.print (CO2Response[i],HEX);     //added for debugging 
	      Serial.print (":");                    //added for debugging
		  return -1;
	  }
		  Serial.print (CO2Response[i],HEX);     //added for debugging
	      Serial.print (":"); 	                 //added for debugging
	} 
    unsigned long val = CO2Response[3]*256 + CO2Response[4];  
    return val;	
  }	
  else
  {
    return -2;
  }
}

@ttielemans

well the values are not 65XXX, but 65432 and the last three digits changes randomly, thats why i wrote XXX at the end, because this value is not constant.

With 1.4.1 it works great for me, no more -1 or other implausible valuesā€¦

Maybe the CO2 sensor version (HW or FW) has some affect on serial communication?

@Robert_Pogacar Yes, I understood that you meant the last 3 digits changing randomly. I was investigating another sources on github and came accross a function able show the S8 firmware. Another factor that I did not look into, is the version of the Wemos D1. No clue if this has an influence.

Also the timing between the write and the read request, which is in the code I use is set to 100ms.

There are too many factors ā€¦ :roll_eyes:

I wonder if there could also be an issue because we use Software Serial.

When I first came upon the -1 issue I knocked up a quick hysteresis algorithm, so any deviation from the last value greater than plus/minus x would cause it to resample, continuing to do so until a valid value was obtained. I still got the -1 coming through so I thought it could be something to with network timing instead, with the database receiving garbage packets and setting them to -1 which would then show on the graph.

For what itā€™s worth Iā€™ve also seen the PM drop out to zero at random times too so these spikes are not specific to CO2.

@Znook I can also confirm the drops of the PM to zero.

I am pretty confident it is a serial timing issue and as suggested an issue with softserial could be the case. Since about 72 hours I do not see invalid CO2 readings.

The PMS zero spikes increased when I added PM1.0 and PM10 readings. By code change I fixed it by reading the serial data into an array in a single line of code.
My airgradient is reading PM1.0m PM2.5 and PM10 without any issues. at this moment.

I still want to do some more testing with different code.

This are my readings of the last 24 hrs. Nice to recognize when the window was opened and my neighbor started a wood fire in his garden this evening,


As you can see, no invalid CO2 or PMS readings.

1 Like

I have the exact same issue with 1.4.2.

Not only I get spike of 65XXX and -1 but also other spikes at around 17XXX.

Disclaimer: Just build it yesterday. Still need to give it a proper case and placing. So for now, Iā€™m taking the reading with a grain of salt.
Also I bought the kit directly from AirGradient.

@ttielemans Iā€™d be very interested in trying your code that also get the PM 1.0 and PM 10

@Nimrodus

Because I want to pass 5 values (PM1, PM2,5, PM10, temperature and humidity) from my PMS5003 T (which can also measure temperature and humidity), I passs the values by reference.

Code added to Airgradient.cpp

void AirGradient::getPM_Raw(float *pmdata){
  DATA data;
  requestRead();
  if (readUntil(data)) {
    pmdata[0] = data.PM_AE_UG_1_0;
	pmdata[1] = data.PM_AE_UG_2_5;
	pmdata[2] = data.PM_AE_UG_10_0;
	pmdata[3] = data.PM_TMP;
	pmdata[4] = data.PM_HMD;
    return;
  } 
  else {
	pmdata[0] = -99;  // just a value for debugging
	pmdata[1] = -99;
	pmdata[2] = -99;
	pmdata[3] = -99;
	pmdata[4] = -99;
	return;
  }
}

code added to airgradient.h
void getPM_Raw(float *pmdata);

I am using the Jeff Geerling approach so I use the AirGradient-DIY.ino and made the following changes in GenerateMetrics()

String GenerateMetrics() {
...

float statPMS[5];
  if (hasPM) {
    statPMS[0] = -99;
    while (statPMS[0] == -99){
      ag.getPM_Raw(statPMS);
    }
    message += "# HELP Particulate Matter PM1.0 value\n";
    message += "# TYPE pm01 gauge\n";
    message += prefix;
    message += deviceId;
    message += "_pm01";
    message += idString;
    message += String(statPMS[0]);
    message += "\n";

    message += "# HELP Particulate Matter PM2.5 value\n";
    message += "# TYPE pm02 gauge\n";
    message += prefix;
    message += deviceId;
    message += "_pm02";
    message += idString;
    message += String(statPMS[1]);
    message += "\n";
      
    message += "# HELP Particulate Matter PM10 value\n";
    message += "# TYPE pm10 gauge\n";
    message += prefix;
    message += deviceId;
    message += "_pm10";
    message += idString;
    message += String(statPMS[2]);
    message += "\n";
 }

Do you know how does the reading of the PMS5003 T for TĀ° and rhum compare to the SHT30/31 ?

Thanks for the code, Iā€™m also using Jeff Geerling sketch.

I came accros this on the the pjrc.com site

Serial Port Options

  1. HardwareSerial - Best performance. Always use this first, if available! Teensy and Teensy++ have one HardwareSerial port which is available (not used for uploading or the Arduino Serial Monitor). Arduino Mega has 3 extra HardwareSerial ports. Arduino Uno has none.
  2. AltSoftSerial - Can simultaneously transmit and receive. Minimal interference with simultaneous use of HardwareSerial and other libraries. Consumes a 16 bit timer (and will not work with any libraries which need that timer) and disables some PWM pins. Can be sensitive to interrupt usage by other libraries.
  3. SoftwareSerial(formerly ā€œNewSoftSerialā€) - Can have multiple instances on almost any pins, but only 1 can be active at a time. Can not simultaneously transmit and receive. Can interfere with other libraries or HardwareSerial if used at slower baud rates. Can be sensitive to interrupt usage by other libraries.
  4. Old SoftwareSerial (SoftwareSerial in Arduino 0023 & earlier) - Very poor performance.

Maybe the source of the issue is indeed in SoftSerial.

Although I do not have any problem at this moment, https://github.com/plerup/espsoftwareserial is also a potential alternative.

Same thing here, also using Jeff Geerlingā€™s sketch. The obviously wrong values donā€™t actually change all that often: Iā€™m mostly seeing -1, 65092, 65278, and 17410. (Incidentally I havenā€™t worked out if itā€™s possible to do the equivalent of SELECT COUNT(*) GROUP BY value in PromQL)

Itā€™s entirely possible I made a soldering mistake, but power cycling the board fixes it for a few hours, so I am beginning to suspect the software serial as well

If youā€™re interested, Iā€™ve complety rebuild the AirGradient lib and the sketch from the gound up.

I donā€™t get any bad reading, neither from the S8 neither from the PMS anymore:

You need Visual Studio Code with the Platform IO plugin, it will take care of pulling all the dependencies needed.

Big change too: I rename the pm2 metric to particle_count because I provide the PM2.5, PM1.0, PM10.0 metrics too as label for the particle_count (using the label type).

2 Likes

Iā€™m also having -1 and similar issues as described in this thread.
@Nimrodus, I have some time to try your code, but after compiling it in Visual Studio Code, I am struggling to import it into Arduino using the Include Library via ZIP or folder. Iā€™m a novice in using Arduino. A few tips or pointers would be appreciated.

When you have the project imported in Visual Studio Code with the Platform IO plugin installed, you can directly use it to compile and upload the firmware.

CTRL+SHIFT+P will show you the action menu, type upload:

You can also directly use the shortcut: CTRL+ALT+U in Visual Studio Code to upload the firmware directly.

1 Like

I forgot to add, you also need to update the file in Configuration/user.cpp with the different settings you have (like your wifi ssid etc ā€¦)

@Nimrodus, thank you. Your code is working well, and so far I donā€™t see any ā€œbadā€ data as described in this thread, though it has been only a few hours.
Iā€™ll report back within a day or two to share my feedback.

P.S. I love PlatformIO, never heared of it before, so thanks :slight_smile:

With the latest version of the code (of yesterday) Iā€™ve added calculation on the board of the AQI (PM 2.5):

Here is the JSON code of the dashboard :slight_smile:

{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "target": {
          "limit": 100,
          "matchAny": false,
          "tags": [],
          "type": "dashboard"
        },
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 0,
  "id": 3,
  "iteration": 1643579374048,
  "links": [],
  "liveNow": false,
  "panels": [
    {
      "datasource": {
        "type": "prometheus",
        "uid": "P1809F7CD0C75ACF3"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "#EAB839",
                "value": 1000
              },
              {
                "color": "red",
                "value": 2000
              }
            ]
          },
          "unit": "ppm"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 6,
        "x": 0,
        "y": 0
      },
      "id": 5,
      "options": {
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showThresholdLabels": false,
        "showThresholdMarkers": true,
        "text": {}
      },
      "pluginVersion": "8.3.4",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "P1809F7CD0C75ACF3"
          },
          "exemplar": true,
          "expr": "rco2{id=\"$DeviceId\"}",
          "interval": "",
          "legendFormat": "",
          "queryType": "randomWalk",
          "refId": "A"
        }
      ],
      "title": "CO2 (Latest)",
      "type": "gauge"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "P1809F7CD0C75ACF3"
      },
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "#EAB839",
                "value": 10
              },
              {
                "color": "red",
                "value": 20
              }
            ]
          },
          "unit": "conĪ¼gm3"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 6,
        "x": 6,
        "y": 0
      },
      "id": 6,
      "options": {
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showThresholdLabels": false,
        "showThresholdMarkers": true,
        "text": {}
      },
      "pluginVersion": "8.3.4",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "P1809F7CD0C75ACF3"
          },
          "exemplar": true,
          "expr": "particle_count{id=\"$DeviceId\", type=\"PM2.5\"}",
          "interval": "",
          "legendFormat": "",
          "queryType": "randomWalk",
          "refId": "A"
        }
      ],
      "title": "PM2.5 (Latest)",
      "type": "gauge"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "P1809F7CD0C75ACF3"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "max": 500,
          "min": 0,
          "noValue": "Calculating ... (Takes 24h of data)",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "#EAB839",
                "value": 51
              },
              {
                "color": "orange",
                "value": 101
              },
              {
                "color": "red",
                "value": 151
              },
              {
                "color": "semi-dark-red",
                "value": 201
              },
              {
                "color": "dark-red",
                "value": 301
              }
            ]
          },
          "unit": "AQI"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 7,
        "w": 5,
        "x": 12,
        "y": 0
      },
      "id": 12,
      "options": {
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showThresholdLabels": true,
        "showThresholdMarkers": true
      },
      "pluginVersion": "8.3.4",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "P1809F7CD0C75ACF3"
          },
          "exemplar": true,
          "expr": "air_quality_index{id=\"$DeviceId\", type=\"PM2.5\"}",
          "interval": "",
          "legendFormat": "",
          "refId": "A"
        }
      ],
      "title": "AQI (PM2.5)",
      "type": "gauge"
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": {
        "type": "prometheus",
        "uid": "P1809F7CD0C75ACF3"
      },
      "description": "",
      "fieldConfig": {
        "defaults": {
          "unit": "ppm"
        },
        "overrides": []
      },
      "fill": 1,
      "fillGradient": 0,
      "gridPos": {
        "h": 7,
        "w": 12,
        "x": 0,
        "y": 6
      },
      "hiddenSeries": false,
      "id": 2,
      "legend": {
        "alignAsTable": false,
        "avg": false,
        "current": false,
        "max": false,
        "min": false,
        "rightSide": false,
        "show": false,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "nullPointMode": "null",
      "options": {
        "alertThreshold": true
      },
      "percentage": false,
      "pluginVersion": "8.3.4",
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "P1809F7CD0C75ACF3"
          },
          "exemplar": true,
          "expr": "rco2{id=\"$DeviceId\"}",
          "interval": "",
          "legendFormat": "CO2",
          "queryType": "randomWalk",
          "refId": "A"
        }
      ],
      "thresholds": [
        {
          "$$hashKey": "object:279",
          "colorMode": "warning",
          "fill": true,
          "line": false,
          "op": "gt",
          "value": 1000,
          "yaxis": "left"
        },
        {
          "$$hashKey": "object:285",
          "colorMode": "critical",
          "fill": true,
          "line": false,
          "op": "gt",
          "value": 2000,
          "yaxis": "left"
        }
      ],
      "timeRegions": [],
      "title": "CO2 Over Time",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "mode": "time",
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "$$hashKey": "object:48",
          "format": "ppm",
          "label": "",
          "logBase": 1,
          "show": true
        },
        {
          "$$hashKey": "object:49",
          "format": "short",
          "logBase": 1,
          "show": true
        }
      ],
      "yaxis": {
        "align": false
      }
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "P1809F7CD0C75ACF3"
      },
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "#6ED0E0",
                "value": 0
              },
              {
                "color": "green",
                "value": 18
              },
              {
                "color": "#EAB839",
                "value": 25
              },
              {
                "color": "red",
                "value": 30
              }
            ]
          },
          "unit": "celsius"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 5,
        "w": 5,
        "x": 12,
        "y": 7
      },
      "id": 7,
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "text": {},
        "textMode": "auto"
      },
      "pluginVersion": "8.3.4",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "P1809F7CD0C75ACF3"
          },
          "exemplar": true,
          "expr": "atmp{id=\"$DeviceId\"}",
          "hide": false,
          "interval": "",
          "legendFormat": "",
          "queryType": "randomWalk",
          "refId": "A"
        }
      ],
      "title": "Temperature",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "P1809F7CD0C75ACF3"
      },
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "max": 100,
          "min": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "#6ED0E0",
                "value": 0
              },
              {
                "color": "green",
                "value": 28
              },
              {
                "color": "#EAB839",
                "value": 40
              },
              {
                "color": "red",
                "value": 50
              }
            ]
          },
          "unit": "percent"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 5,
        "w": 5,
        "x": 12,
        "y": 12
      },
      "id": 8,
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "text": {},
        "textMode": "auto"
      },
      "pluginVersion": "8.3.4",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "P1809F7CD0C75ACF3"
          },
          "exemplar": true,
          "expr": "rhum{id=\"$DeviceId\"}",
          "interval": "",
          "legendFormat": "",
          "queryType": "randomWalk",
          "refId": "A"
        }
      ],
      "title": "Relative Humidity",
      "type": "stat"
    },
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": {
        "type": "prometheus",
        "uid": "P1809F7CD0C75ACF3"
      },
      "description": "",
      "fill": 1,
      "fillGradient": 0,
      "gridPos": {
        "h": 6,
        "w": 12,
        "x": 0,
        "y": 13
      },
      "hiddenSeries": false,
      "id": 3,
      "legend": {
        "alignAsTable": false,
        "avg": false,
        "current": false,
        "max": false,
        "min": false,
        "rightSide": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "nullPointMode": "null",
      "options": {
        "alertThreshold": true
      },
      "percentage": false,
      "pluginVersion": "8.3.4",
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "P1809F7CD0C75ACF3"
          },
          "exemplar": true,
          "expr": "particle_count{id=\"$DeviceId\"}",
          "interval": "",
          "legendFormat": "{{type}}",
          "queryType": "randomWalk",
          "refId": "A"
        }
      ],
      "thresholds": [
        {
          "$$hashKey": "object:188",
          "colorMode": "warning",
          "fill": true,
          "line": false,
          "op": "gt",
          "value": 10,
          "yaxis": "left"
        },
        {
          "$$hashKey": "object:194",
          "colorMode": "critical",
          "fill": true,
          "line": false,
          "op": "gt",
          "value": 50,
          "yaxis": "left"
        }
      ],
      "timeRegions": [],
      "title": "Particle over Time",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "mode": "time",
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "$$hashKey": "object:48",
          "format": "conĪ¼gm3",
          "label": "",
          "logBase": 1,
          "show": true
        },
        {
          "$$hashKey": "object:49",
          "format": "short",
          "logBase": 1,
          "show": true
        }
      ],
      "yaxis": {
        "align": false
      }
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "P1809F7CD0C75ACF3"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              }
            ]
          },
          "unit": "dtdhms"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 6,
        "w": 5,
        "x": 12,
        "y": 17
      },
      "id": 10,
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "8.3.4",
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "P1809F7CD0C75ACF3"
          },
          "exemplar": false,
          "expr": "time() - sensors_boot_time{id=\"$DeviceId\"}",
          "instant": true,
          "interval": "",
          "legendFormat": "",
          "refId": "A"
        }
      ],
      "title": "UpTime",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "P1809F7CD0C75ACF3"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineInterpolation": "linear",
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "auto",
            "spanNulls": false,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 5,
        "w": 12,
        "x": 0,
        "y": 19
      },
      "id": 14,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "single"
        }
      },
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "P1809F7CD0C75ACF3"
          },
          "exemplar": true,
          "expr": "air_quality_index{id=\"$DeviceId\", type=\"PM2.5\"}",
          "interval": "",
          "legendFormat": "AQI",
          "refId": "A"
        }
      ],
      "title": "AQI (PM2.5) over time",
      "type": "timeseries"
    }
  ],
  "refresh": "1m",
  "schemaVersion": 34,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": [
      {
        "current": {
          "selected": false,
          "text": "livingroom",
          "value": "livingroom"
        },
        "datasource": {
          "type": "prometheus",
          "uid": "P1809F7CD0C75ACF3"
        },
        "definition": "label_values(rco2, id)",
        "hide": 0,
        "includeAll": false,
        "label": "Device",
        "multi": false,
        "name": "DeviceId",
        "options": [],
        "query": {
          "query": "label_values(rco2, id)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "type": "query"
      }
    ]
  },
  "time": {
    "from": "now-12h",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "AirGradient Uptime",
  "uid": "Tvl1xTmRz",
  "version": 12,
  "weekStart": ""
}
2 Likes

Hi all, just a quick follow up to note that in the past 36 hours, since I started using @Nimrodusā€™ code, i have not experienced any of the issues described in this thread. Iā€™ll post again if issues do start to appear.

I had some occurence of ā€œ514ā€ CO2 values at fixed intervals using the adapted airgradient.cpp. Still suspecting timing issue. By reducing the delay from 100 to 25 ms, the issue seems to be gone (again).
Seem to be a timing issue. At this moment running the code on 3 units for 24 hrs without issue. I keep monitoring and posting.

int AirGradient::getCO2_Raw(){
  // CO2_READ_RESULT result;
  const byte CO2Command[] = {0xFE, 0X44, 0X00, 0X08, 0X02, 0X9F, 0X25};
  byte CO2Response[] = {0,0,0,0,0,0,0};
  
  _SoftSerial_CO2->write(CO2Command, 7);
  delay(25);