diff --git a/OpenCO2_Sensor.ino b/OpenCO2_Sensor.ino index 144db85..25b2dcb 100644 --- a/OpenCO2_Sensor.ino +++ b/OpenCO2_Sensor.ino @@ -10,7 +10,7 @@ - WiFiManager: https://github.com/tzapu/WiFiManager - ArduinoMqttClient (if MQTT is defined) */ -#define VERSION "v5.0" +#define VERSION "v5.1" #define HEIGHT_ABOVE_SEA_LEVEL 50 // Berlin #define TZ_DATA "CET-1CEST,M3.5.0,M10.5.0/3" // Europe/Berlin time zone from https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv @@ -166,7 +166,10 @@ String getHexColors(uint16_t co2) { return String(hexString); } -String GenerateHtml() { +void HandleRootClient() { + server.setContentLength(CONTENT_LENGTH_UNKNOWN); + server.send(200, "text/html", ""); + String message = "\n \n"; message += "\n OpenCO2 Sensor\n \n \n"; message += ""; @@ -180,73 +183,100 @@ String GenerateHtml() { if (useFahrenheit) sprintf(tempString, "%.1f",(temperature * 1.8f) + 32.0f); // convert to °F else sprintf(tempString, "%.1f", temperature); message += "
Temperature
" + String(tempString) + "
"; - if (useFahrenheit) message += "*F"; - else message += "*C"; - message += "
\n"; + message += String(useFahrenheit? "*F": "*C") + "\n"; message += "
Humidity
" + String((int)humidity) + "
%
\n"; message += "
\n"; message += "
\n"; message += "\n \n \n"; - return message; + message += "\n\n\n"; + server.sendContent(message); + server.client().stop(); } -void HandleRootClient() { - server.send(200, "text/html", GenerateHtml()); -} void HandleRoot() { server.send(200, "text/plain", GenerateMetrics()); } @@ -648,7 +678,14 @@ void toggleWiFi() { bool ip_shown = false; while (digitalRead(BUTTON) != 0) { // wait for button press delay(100); - wifiManager.process(); + + if (useWiFi && !BatteryMode) { + if (WiFi.status() != WL_CONNECTED) wifiManager.process(); +#ifdef airgradient + if (WiFi.status() == WL_CONNECTED) server.handleClient(); +#endif /* airgradient */ + } + if (!ip_shown && WiFi.status() == WL_CONNECTED) { delay(100); ip_shown = true; @@ -657,6 +694,7 @@ void toggleWiFi() { if (BatteryMode && (digitalRead(USB_PRESENT) == HIGH)) { // power got connected BatteryMode = false; handleWiFiChange(); + displayWiFi(useWiFi); } } } diff --git a/README.md b/README.md index a384e7f..c684e00 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,23 @@ Press the Menu button on the backside of the OpenCO2 Sensor. Select an option vi Enable Wi-Fi via the Menu button. When power is connected, an access point `OpenCO2 Sensor` is enabled. Connect to it and navigate to http://192.168.4.1 (it will open automatically on modern Smartphones). Insert your home Wi-Fi credentials under `Configure WiFi`. Choose your network name from the list in the top and insert the password. Click `Save`. The sensor will now be automatically connected. Navigate to IP:9925 to see current co2/temperature/humidity measurements. ![alt text](https://github.com/davidkreidler/OpenCO2_Sensor/raw/main/pictures/setup.jpg) +# Machine-readable Measurements over WiFi +Connect the sensor to your Wi-Fi network and find out the IP of the sensor in your home network via the ui of your router or on the sensor itself via the button under Menu -> Info . +`curl [IP]:9925/metrics` + +Result: +``` +# HELP rco2 CO2 value, in ppm +# TYPE rco2 gauge +rco2{id="Open CO2 Sensor",mac="7C:DF:A1:96:B9:72"}571 +# HELP atmp Temperature, in degrees Celsius +# TYPE atmp gauge +atmp{id="Open CO2 Sensor",mac="7C:DF:A1:96:B9:72"}25.37 +# HELP rhum Relative humidity, in percent +# TYPE rhum gauge +rhum{id="Open CO2 Sensor",mac="7C:DF:A1:96:B9:72"}55.15 +``` + # AirGradient / Grafana Use [internet-pi](https://github.com/geerlingguy/internet-pi) to store the CO2 / Temperature / Humidity data on your Pi. First connect the OpenCO2 Sensor to your Wi-Fi network and follow the instructions https://www.youtube.com/watch?v=Cmr5VNALRAg Then download the https://raw.githubusercontent.com/davidkreidler/OpenCO2_Sensor/main/grafana_OpenCO2_Sensor.json and import it into Grafana. @@ -68,7 +85,7 @@ Use [internet-pi](https://github.com/geerlingguy/internet-pi) to store the CO2 / # OTA Update Download `FIRMWARE.BIN` from the latest [release](https://github.com/davidkreidler/OpenCO2_Sensor/releases). -Enable Wi-Fi via the Menu button, in an area where no previously known network is active. Connect power. Then connect to `OpenCO2 Sensor` and navigate to http://192.168.4.1 . Under `Update` select the `OpenCO2_Sensor.ino.bin` file and click `Update`. The Sensor will restart. +Enable Wi-Fi via the Menu button, in an area where no previously known network is active. Connect power. Then connect to `OpenCO2 Sensor` and navigate to http://192.168.4.1 . Under `Update` select the `FIRMWARE.BIN` file and click `Update`. The Sensor will restart. ![alt text](https://github.com/davidkreidler/OpenCO2_Sensor/raw/main/pictures/OTA.jpg) # Update via USB (from an old release) diff --git a/epd_abstraction.ino b/epd_abstraction.ino index 63e5d73..8bb13d6 100644 --- a/epd_abstraction.ino +++ b/epd_abstraction.ino @@ -94,6 +94,7 @@ void handleButtonPress() { case RAINBOW: rainbowMode(); setLED(co2); + refreshes = 1; break; } clearMenu(); @@ -372,7 +373,7 @@ void displayWriteMeasuerments(uint16_t co2, float temperature, float humidity) { if (temperature < 10.0f) Paint_DrawNum(30, 5, temperature, &mid, BLACK, WHITE); else Paint_DrawNum( 1, 5, temperature, &mid, BLACK, WHITE); int offset = 0; - if (temperature >= 100) offset = 29; // for Fahrenheit + if (temperature >= 100) offset = 29; // for Fahrenheit > 37,7 °C Paint_DrawString_EN(60+offset, 4, useFahrenheit? "*F" : "*C", &bahn_sml, WHITE, BLACK); Paint_DrawString_EN(60+offset, 32, ",", &sml, WHITE, BLACK); @@ -646,20 +647,18 @@ void displayHistory(uint8_t qrcodeNumber) { void history() { // DEMO DATA: /* - hour = 2; + hour = 23; halfminute = 120; for (int i=0; i<120; i++) { - co2measurements[0][i] = 400+i; - co2measurements[1][i] = 520+i; - co2measurements[2][i] = 1000+i; + for (int j=0; j<24; j++) { + co2measurements[j][i] = 400+i; + } } for (int i=0; i<40; i++) { - tempHumMeasurements[0][i].temperature = 200+i; - tempHumMeasurements[1][i].temperature = 320-i; - tempHumMeasurements[2][i].temperature = 10+i; - tempHumMeasurements[0][i].humidity = 20+i/2; - tempHumMeasurements[1][i].humidity = 80-i/2; - tempHumMeasurements[2][i].humidity = 10+i/2; + for (int j=0; j<24; j++) { + tempHumMeasurements[j][i].temperature = 200+i; + tempHumMeasurements[j][i].humidity = 20+i/2; + } } */ uint16_t mspressed;