1
0
mirror of https://github.com/revspace/operame synced 2024-12-04 13:47:29 +00:00

Deal with weird MH-Z19(B?) version

This one, with version number 0436, has a magic "I'm still booting" value
of 436 PPM instead of 410 PPM.

Interestingly, another sensor with version 0430 returns 430 for an instant,
but then goes to 410. During the short 430-phase the clamped CO2 value is
actually 0, so it doesn't require checking.
This commit is contained in:
Juerd Waalboer 2020-11-27 05:33:15 +01:00
parent 5c7bb23f80
commit 6c7bb2c4a3

View File

@ -20,6 +20,8 @@ int co2_warning;
int co2_critical;
int co2_blink;
int co2_init = 410; // magic value reported while initializing
MQTTClient mqtt;
HardwareSerial hwserial1(1);
TFT_eSPI display;
@ -157,8 +159,14 @@ void setup() {
delay(2000);
check_sensor();
mhz.setFilter(true, true);
mhz.autoCalibration();
// mhz.setFilter(true, true); Library filter doesn't handle 0436
mhz.autoCalibration(true);
char v[5];
mhz.getVersion(v);
v[4] = '\0';
if (strcmp("0436", v) == 0) co2_init = 436;
Serial.printf("MH-Z19 firmware version %s\n", v);
WiFiSettings.hostname = "operame-";
wifi_enabled = WiFiSettings.checkbox("operame_wifi", false, "WiFi-verbinding gebruiken");
@ -205,6 +213,7 @@ void setup() {
if (ota_enabled) setup_ota();
display_big(":-)");
}
void connect_mqtt() {
@ -235,12 +244,24 @@ void loop() {
if (mqtt_enabled) mqtt.loop();
int CO2 = mhz.getCO2();
int CO2 = mhz.getCO2();
int unclamped = mhz.getCO2(false);
// reimplement filter from library, but also checking for 436 because our
// sensors (firmware 0436, coincidence?) return that instead of 410...
if (unclamped == co2_init && CO2 - unclamped >= 10) CO2 = 0;
// No known sensors support >10k PPM (library filter tests for >32767)
if (CO2 > 10000 || unclamped > 10000) CO2 = 0;
check_sensor();
Serial.println(CO2);
if (CO2) {
// some MH-Z19's go to 10000 but the display has space for 4 digits
if (CO2 > 9999) CO2 = 9999;
display_ppm(CO2);
if (mqtt_enabled && millis() - previous_mqtt >= mqtt_interval) {