From 2507170e49b38b8847a53c807b98b2a17336ca4d Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Tue, 20 Feb 2024 20:45:38 +0100 Subject: [PATCH 01/53] Update README.md to remove references to GPIO EN --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 7c780f27..2ab72f90 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,6 @@ These are the GPIOs used by each predefined board: - RX / TX: Pins (GPIO) used for sensors connected by serial port. - I2C: Pins (GPIO) corresponding to the I2C bus for connection of I2C sensors and displays. - UP / DWN: Pins (GPIO) to which to connect the "Up" and "Down" buttons. They are optional as CO2 Gadget is fully functional with no buttons attached. -- EN: Pin (GPIO) that supplies an ENABLE signal for switching the sensors on and off (reserved for future use). - GPIO Orange: Pin (GPIO) corresponding to the output when the orange level is reached (for relays, alarms, and RGB LED). - GPIO Red: Pin (GPIO) corresponding to the output when the orange level is reached (for relays, alarms, and RGB LED). - GPIO Battery: Pin for battery voltage measurement. From 54d4f481611b860eff8ebe24b795e63e5cc66450 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Wed, 21 Feb 2024 06:35:46 +0100 Subject: [PATCH 02/53] Fix T-Display S3 I2C GPIO in README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2ab72f90..be42de95 100644 --- a/README.md +++ b/README.md @@ -66,11 +66,11 @@ Supporting any other ESP32 board is very easy. Yoy just have to setup the pines These are the GPIOs used by each predefined board: -| Flavor | Display | RX/TX | I2C | UP/DWN | GPIO Orange | GPIO Red | GPIO Battery | GPIO Neopixel | GPIO Buzzer +| Flavor | Display | RX/TX | I2C SDA/SCL | UP/DWN | GPIO Orange | GPIO Red | GPIO Battery | GPIO Neopixel | GPIO Buzzer |:-----------------------|:----------------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:| | TTGO_TDISPLAY TFT | TFT 240×135 | 13/12 | 21/22 | 35/0 | 32 | 33 | 34 | 26 | 2 | TTGO_TDISPLAY_SANDWICH | TFT 240×135 | 13/12 | 22/21 | 35/0 | 32 | 33 | 34 | 26 | 2 -| TDISPLAY_S3 | TFT 320x170 | 18/17 | 42/43 | 14/0 | 03 | 01 | 04 | 16 | 2 +| TDISPLAY_S3 | TFT 320x170 | 18/17 | 43/44 | 14/0 | 03 | 01 | 04 | 16 | 2 | esp32dev_OLED SSH1106 | SSH1106 128×64 | 17/16 | 21/22 | 15/0 | 32 | 33 | 34 | 26 | 2 | esp32dev | No display | 17/16 | 21/22 | 15/0 | 32 | 33 | 34 | 26 | 2 | esp32dev-sandwich | No display | 17/16 | 22/21 | 15/0 | 32 | 33 | 34 | 26 | 2 From 5e0545af2b353c29b2f6a9007e61fe701a06c3bf Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:14:54 +0100 Subject: [PATCH 03/53] Refactor SCD4x sensor type output --- CO2_Gadget_Sensors.h | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/CO2_Gadget_Sensors.h b/CO2_Gadget_Sensors.h index 878b145f..d8dedf6f 100644 --- a/CO2_Gadget_Sensors.h +++ b/CO2_Gadget_Sensors.h @@ -65,17 +65,7 @@ uint16_t getSCD4xFeatureSet() { Serial.println("-->[SENS] SCD4x getFeatures error: " + String(error)); } else { uint8_t typeOfSensor = ((featureSet & 0x1000) >> 12); - switch (typeOfSensor) { - case 0: - Serial.println("-->[SENS] SCD4x Sensor Type: SCD40"); - break; - case 1: - Serial.println("-->[SENS] SCD4x Sensor Type: SCD41"); - break; - default: - Serial.println("-->[SENS] SCD4x Sensor Type: Unknown (probably unsupported SCD42 obsolete sensor)"); - break; - } + Serial.println("-->[SENS] SCD4x Sensor Type: SCD4" + String(typeOfSensor)); } sensors.scd4x.startPeriodicMeasurement(); return featureSet; From 800949e59c523c0c19f8a5264b99f6fbbde529cf Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Wed, 21 Feb 2024 20:10:35 +0100 Subject: [PATCH 04/53] Update battery functionality and preferences to fix #101 --- CO2_Gadget.ino | 41 +++++++++++++--------------------------- CO2_Gadget_Battery.h | 30 ++++++++++++++++++++++++++--- CO2_Gadget_Preferences.h | 2 +- platformio.ini | 2 +- 4 files changed, 42 insertions(+), 33 deletions(-) diff --git a/CO2_Gadget.ino b/CO2_Gadget.ino index 5e262cde..b80ca7bd 100644 --- a/CO2_Gadget.ino +++ b/CO2_Gadget.ino @@ -93,8 +93,9 @@ uint64_t timeInitializationCompleted = 0; // Variables for Battery reading float battery_voltage = 0; uint8_t battery_level = 0; -uint16_t timeBetweenBatteryRead = 15; -uint64_t lastTimeBatteryRead = 0; // Time of last battery reading +uint16_t vRef = 1100; +uint16_t batteryDischargedMillivolts = 3500; // Voltage of battery when we consider it discharged (0%). +uint16_t batteryFullyChargedMillivolts = 4200; // Voltage of battery when it is considered fully charged (100%). // Variables to control automatic display off to save power bool workingOnExternalPower = true; // True if working on external power (USB connected) @@ -177,9 +178,6 @@ bool displayNotification(String notificationText, notificationTypes notification /********* INCLUDE BATTERY FUNCTIONALITY *********/ /********* *********/ /*****************************************************************************************************/ -uint16_t vRef = 1100; -uint16_t batteryDischargedMillivolts = 3500; // Voltage of battery when we consider it discharged (0%). -uint16_t batteryFullyChargedMillivolts = 4200; // Voltage of battery when it is considered fully charged (100%). #include "CO2_Gadget_Battery.h" /*****************************************************************************************************/ @@ -323,10 +321,10 @@ void processPendingCommands() { } void initGPIO() { - #ifdef GREEN_PIN +#ifdef GREEN_PIN pinMode(GREEN_PIN, OUTPUT); digitalWrite(GREEN_PIN, LOW); - #endif +#endif pinMode(BLUE_PIN, OUTPUT); digitalWrite(BLUE_PIN, LOW); pinMode(RED_PIN, OUTPUT); @@ -335,14 +333,14 @@ void initGPIO() { void outputsRelays() { if ((!outputsModeRelay) || (co2 == 0)) return; // Don't turn on relays until there is CO2 Data - #ifdef GREEN_PIN +#ifdef GREEN_PIN if (co2 >= co2OrangeRange) { digitalWrite(GREEN_PIN, GREEN_PIN_LOW); } if (co2 < co2OrangeRange) { digitalWrite(GREEN_PIN, GREEN_PIN_HIGH); } - #endif +#endif if (co2 >= co2OrangeRange) { digitalWrite(BLUE_PIN, BLUE_PIN_HIGH); } @@ -360,24 +358,24 @@ void outputsRelays() { void outputsRGBLeds() { if ((outputsModeRelay) || (co2 == 0)) return; // Don't turn on led until there is CO2 Data if (co2 > co2RedRange) { - #ifdef GREEN_PIN +#ifdef GREEN_PIN digitalWrite(GREEN_PIN, GREEN_PIN_LOW); - #endif +#endif digitalWrite(RED_PIN, RED_PIN_HIGH); digitalWrite(BLUE_PIN, BLUE_PIN_LOW); return; } if (co2 >= co2OrangeRange) { - #ifdef GREEN_PIN +#ifdef GREEN_PIN digitalWrite(GREEN_PIN, GREEN_PIN_HIGH); - #endif +#endif digitalWrite(BLUE_PIN, BLUE_PIN_LOW); digitalWrite(RED_PIN, RED_PIN_HIGH); return; } - #ifdef GREEN_PIN +#ifdef GREEN_PIN digitalWrite(GREEN_PIN, GREEN_PIN_HIGH); - #endif +#endif digitalWrite(BLUE_PIN, BLUE_PIN_LOW); digitalWrite(RED_PIN, RED_PIN_LOW); } @@ -459,19 +457,6 @@ void adjustBrightnessLoop() { #endif } -void batteryLoop() { - const float lastBatteryVoltage = battery_voltage; - readBatteryVoltage(); - if (!inMenu) { - if (abs(lastBatteryVoltage - battery_voltage) >= 0.1) { // If battery voltage changed by at least 0.1, update battery level - battery_level = getBatteryPercentage(); - // Serial.printf("-->[BATT] Battery Level: %d%%\n", battery.level()); - } - } - // If battery voltage is more than 5% of the fully charged battery voltage, asume it's working on external power - workingOnExternalPower = (battery_voltage * 1000 > batteryFullyChargedMillivolts + (batteryFullyChargedMillivolts * 5 / 100)); -} - void setCpuFrequencyAndReinitSerial(int16_t newCpuFrequency) { while (Serial.available()) { Serial.read(); diff --git a/CO2_Gadget_Battery.h b/CO2_Gadget_Battery.h index 64bb45b9..033260b8 100644 --- a/CO2_Gadget_Battery.h +++ b/CO2_Gadget_Battery.h @@ -5,16 +5,20 @@ /*****************************************************************************************************/ /********* *********/ /********* SETUP BATTERY FUNCTIONALITY *********/ -/********* Uses Library https://github.com/rlogiacco/BatterySense/blob/master/Battery.cpp *********/ +/********* Uses Library https://github.com/rlogiacco/BatterySense *********/ /********* *********/ /*****************************************************************************************************/ // clang-format on +uint16_t timeBetweenBatteryRead = 5; +uint64_t lastTimeBatteryRead = 0; // Time of last battery reading +const uint8_t batterySamples = 3; // Number of samples to average for battery voltage. + // Battery info (percent charge). const uint32_t voltageDividerR1Ohms = 100000; // Resistance of "R1" for voltage divider. const uint32_t voltageDividerR2Ohms = 100000; // Resistance of "R2" for voltage divider. -// Voltage divider ratio for battery sense must be (R1 + R2) / R2 - see https://github.com/rlogiacco/BatterySense. +// Voltage divider ratio for battery sense must be (R1 + R2) / R2 const float voltageDividerRatio = (voltageDividerR1Ohms + voltageDividerR2Ohms) / voltageDividerR2Ohms; #include @@ -30,8 +34,14 @@ void initBattery() { } float readBatteryVoltage() { + float avrgBatteryVoltage = 0; if ((millis() - lastTimeBatteryRead >= timeBetweenBatteryRead * 1000) || (lastTimeBatteryRead == 0)) { - battery_voltage = (float)battery.voltage() / 1000; + for (uint8_t i = 0; i < batterySamples; i++) { + avrgBatteryVoltage += (float)battery.voltage() / 1000; + delay(10); + } + avrgBatteryVoltage /= 3; + battery_voltage = avrgBatteryVoltage; // Serial.print("-->[BATT] Battery read: "); // Serial.print(battery_voltage); // Serial.println("V"); @@ -44,4 +54,18 @@ uint8_t getBatteryPercentage() { return battery.level(); } +void batteryLoop() { + static float lastBatteryVoltage = readBatteryVoltage(); + readBatteryVoltage(); + if (!inMenu) { + if (abs(lastBatteryVoltage - battery_voltage) >= 0.1) { // If battery voltage changed by at least 0.1V, update battery level + battery_level = getBatteryPercentage(); + // Serial.printf("-->[BATT] Battery Level: %d%%. Battery voltage changed from: %.4fV to %.4fV\n", battery_level, lastBatteryVoltage, battery_voltage); + lastBatteryVoltage = battery_voltage; + } + } + // If battery voltage is more than 5% of the fully charged battery voltage, asume it's working on external power + workingOnExternalPower = (battery_voltage * 1000 > batteryFullyChargedMillivolts + (batteryFullyChargedMillivolts * 5 / 100)); +} + #endif // CO2_Gadget_Battery_h \ No newline at end of file diff --git a/CO2_Gadget_Preferences.h b/CO2_Gadget_Preferences.h index cd04b3f2..a838d2de 100644 --- a/CO2_Gadget_Preferences.h +++ b/CO2_Gadget_Preferences.h @@ -165,7 +165,7 @@ void initPreferences() { wifiPass.trim(); hostName.trim(); preferences.end(); -#define DEBUG_PREFERENCES +// #define DEBUG_PREFERENCES #ifdef DEBUG_PREFERENCES printPreferences(); #endif diff --git a/platformio.ini b/platformio.ini index 940cc6d4..bb8effc2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -61,7 +61,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"005"\" + -D CO2_GADGET_REV="\"006"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From fc74285d9f4916e480a545ce1bd564a6f44657e7 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Wed, 21 Feb 2024 20:13:46 +0100 Subject: [PATCH 05/53] Update battery voltage variable name --- CO2_Gadget.ino | 8 ++++---- CO2_Gadget_Battery.h | 14 +++++++------- CO2_Gadget_ESP-NOW.h | 2 +- CO2_Gadget_MQTT.h | 2 +- CO2_Gadget_Menu.h | 8 ++++---- CO2_Gadget_Preferences.h | 2 +- CO2_Gadget_TFT.h | 16 ++++++++-------- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/CO2_Gadget.ino b/CO2_Gadget.ino index b80ca7bd..64d6e93e 100644 --- a/CO2_Gadget.ino +++ b/CO2_Gadget.ino @@ -91,7 +91,7 @@ uint16_t boardIdESPNow = 0; uint64_t timeInitializationCompleted = 0; // Variables for Battery reading -float battery_voltage = 0; +float batteryVoltage = 0; uint8_t battery_level = 0; uint16_t vRef = 1100; uint16_t batteryDischargedMillivolts = 3500; // Voltage of battery when we consider it discharged (0%). @@ -420,7 +420,7 @@ void adjustBrightnessLoop() { } // If battery pin not connected, assume it's working on external power - if (battery_voltage < 1) { + if (batteryVoltage < 1) { workingOnExternalPower = true; } @@ -478,10 +478,10 @@ void utilityLoop() { const int16_t lowCpuFrequency = 80; if (workingOnExternalPower && actualCPUFrequency != highCpuFrequency) { - Serial.printf("-->[BATT] Battery voltage: %.2fV. Increasing CPU frequency to %dMHz\n", battery_voltage, highCpuFrequency); + Serial.printf("-->[BATT] Battery voltage: %.2fV. Increasing CPU frequency to %dMHz\n", batteryVoltage, highCpuFrequency); setCpuFrequencyAndReinitSerial(highCpuFrequency); } else if (!workingOnExternalPower && actualCPUFrequency != lowCpuFrequency) { - Serial.printf("-->[BATT] Battery voltage: %.2fV. Decreasing CPU frequency to %dMHz\n", battery_voltage, lowCpuFrequency); + Serial.printf("-->[BATT] Battery voltage: %.2fV. Decreasing CPU frequency to %dMHz\n", batteryVoltage, lowCpuFrequency); setCpuFrequencyAndReinitSerial(lowCpuFrequency); } } diff --git a/CO2_Gadget_Battery.h b/CO2_Gadget_Battery.h index 033260b8..8e9ce2b9 100644 --- a/CO2_Gadget_Battery.h +++ b/CO2_Gadget_Battery.h @@ -41,13 +41,13 @@ float readBatteryVoltage() { delay(10); } avrgBatteryVoltage /= 3; - battery_voltage = avrgBatteryVoltage; + batteryVoltage = avrgBatteryVoltage; // Serial.print("-->[BATT] Battery read: "); - // Serial.print(battery_voltage); + // Serial.print(batteryVoltage); // Serial.println("V"); lastTimeBatteryRead = millis(); } - return (battery_voltage); + return (batteryVoltage); } uint8_t getBatteryPercentage() { @@ -58,14 +58,14 @@ void batteryLoop() { static float lastBatteryVoltage = readBatteryVoltage(); readBatteryVoltage(); if (!inMenu) { - if (abs(lastBatteryVoltage - battery_voltage) >= 0.1) { // If battery voltage changed by at least 0.1V, update battery level + if (abs(lastBatteryVoltage - batteryVoltage) >= 0.1) { // If battery voltage changed by at least 0.1V, update battery level battery_level = getBatteryPercentage(); - // Serial.printf("-->[BATT] Battery Level: %d%%. Battery voltage changed from: %.4fV to %.4fV\n", battery_level, lastBatteryVoltage, battery_voltage); - lastBatteryVoltage = battery_voltage; + // Serial.printf("-->[BATT] Battery Level: %d%%. Battery voltage changed from: %.4fV to %.4fV\n", battery_level, lastBatteryVoltage, batteryVoltage); + lastBatteryVoltage = batteryVoltage; } } // If battery voltage is more than 5% of the fully charged battery voltage, asume it's working on external power - workingOnExternalPower = (battery_voltage * 1000 > batteryFullyChargedMillivolts + (batteryFullyChargedMillivolts * 5 / 100)); + workingOnExternalPower = (batteryVoltage * 1000 > batteryFullyChargedMillivolts + (batteryFullyChargedMillivolts * 5 / 100)); } #endif // CO2_Gadget_Battery_h \ No newline at end of file diff --git a/CO2_Gadget_ESP-NOW.h b/CO2_Gadget_ESP-NOW.h index 50bd90ad..f18c03c4 100644 --- a/CO2_Gadget_ESP-NOW.h +++ b/CO2_Gadget_ESP-NOW.h @@ -185,7 +185,7 @@ void publishESPNow() { outgoingReadings.co2 = co2; outgoingReadings.temp = temp; outgoingReadings.hum = hum; - outgoingReadings.battery = battery_voltage; + outgoingReadings.battery = batteryVoltage; outgoingReadings.readingId++; // Send message via ESP-NOW diff --git a/CO2_Gadget_MQTT.h b/CO2_Gadget_MQTT.h index d7606968..bcff135e 100644 --- a/CO2_Gadget_MQTT.h +++ b/CO2_Gadget_MQTT.h @@ -282,7 +282,7 @@ void publishMQTTAlarms() { void publishMQTTSystemData() { publishIntMQTT("/uptime", millis() / 1000); - publishFloatMQTT("/voltage", battery_voltage); + publishFloatMQTT("/voltage", batteryVoltage); publishIntMQTT("/battery", battery_level); publishIntMQTT("/freeMem", ESP.getFreeHeap()); publishIntMQTT("/wifiRSSI", WiFi.RSSI()); diff --git a/CO2_Gadget_Menu.h b/CO2_Gadget_Menu.h index 41a3af70..2947ec3e 100644 --- a/CO2_Gadget_Menu.h +++ b/CO2_Gadget_Menu.h @@ -592,13 +592,13 @@ MENU(espnowConfigMenu, "ESP-NOW Config", doNothing, noEvent, wrapStyle result doSetvRef(eventMask e, navNode &nav, prompt &item) { battery.begin(vRef, voltageDividerRatio, &sigmoidal); delay(10); - battery_voltage = (float)battery.voltage() / 1000; + batteryVoltage = (float)battery.voltage() / 1000; nav.target-> dirty = true; return proceed; } MENU(batteryConfigMenu, "Battery Config", doNothing, noEvent, wrapStyle - ,FIELD(battery_voltage, "Battery:", "V", 0, 9, 0, 0, doNothing, noEvent, noStyle) + ,FIELD(batteryVoltage, "Battery:", "V", 0, 9, 0, 0, doNothing, noEvent, noStyle) ,FIELD(vRef, "Voltage ref:", "", 0, 2000, 10, 10, doSetvRef, anyEvent, noStyle) ,FIELD(batteryFullyChargedMillivolts, "Bat Full (mV):", "", 0, 4200, 10, 10, doNothing, noEvent, noStyle) ,FIELD(batteryDischargedMillivolts, "Bat Empty (mV):", "", 2700, 3700, 10, 10, doNothing, noEvent, noStyle) @@ -817,7 +817,7 @@ class altPromptUptime:public prompt { MENU(informationMenu, "Information", doNothing, noEvent, wrapStyle - ,FIELD(battery_voltage, "Battery", "V", 0, 9, 0, 0, doNothing, noEvent, noStyle) + ,FIELD(batteryVoltage, "Battery", "V", 0, 9, 0, 0, doNothing, noEvent, noStyle) ,OP("Comp " BUILD_GIT, doNothing, noEvent) ,OP("Version " CO2_GADGET_VERSION CO2_GADGET_REV, doNothing, noEvent) ,OP("" FLAVOUR, doNothing, noEvent) @@ -834,7 +834,7 @@ result enterMainMenu(menuOut &o, idleEvent e) { return proceed; } -// ,FIELD(battery_voltage, "Battery", "Volts", 0, 9, 0, 0, doNothing, noEvent, noStyle) // It was removed from menu as updates avoids timeout to work +// ,FIELD(batteryVoltage, "Battery", "Volts", 0, 9, 0, 0, doNothing, noEvent, noStyle) // It was removed from menu as updates avoids timeout to work MENU(mainMenu, "CO2 Gadget", doNothing, noEvent, wrapStyle ,SUBMENU(informationMenu) ,SUBMENU(configMenu) diff --git a/CO2_Gadget_Preferences.h b/CO2_Gadget_Preferences.h index a838d2de..50f8132b 100644 --- a/CO2_Gadget_Preferences.h +++ b/CO2_Gadget_Preferences.h @@ -424,7 +424,7 @@ bool handleSavePreferencesfromJSON(String jsonPreferences) { vRef = JsonDocument["vRef"]; battery.begin(vRef, voltageDividerRatio, &sigmoidal); delay(10); - battery_voltage = (float)battery.voltage() / 1000; + batteryVoltage = (float)battery.voltage() / 1000; } mqttClientId = JsonDocument["mqttClientId"].as().c_str(); mqttBroker = JsonDocument["mqttBroker"].as().c_str(); diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index f5fcfaeb..9dcc68a3 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -356,13 +356,13 @@ bool displayNotification(String notificationText, String notificationText2, noti return true; } -uint16_t getBatteryColor(uint16_t battery_voltage) { +uint16_t getBatteryColor(uint16_t batteryVoltage) { uint16_t color; - if (battery_voltage <= 3.6) { + if (batteryVoltage <= 3.6) { color = TFT_RED; - } else if (battery_voltage <= 3.8) { + } else if (batteryVoltage <= 3.8) { color = TFT_ORANGE; - } else if (battery_voltage <= 4.5) { + } else if (batteryVoltage <= 4.5) { color = TFT_GREEN; } else { color = TFT_SKYBLUE; @@ -371,8 +371,8 @@ uint16_t getBatteryColor(uint16_t battery_voltage) { } void showBatteryVoltage(int32_t posX, int32_t posY) { - if ((!displayShowBattery) || (battery_voltage < 1)) return; - String batteryVoltageString = " " + String(battery_voltage, 1) + "V "; + if ((!displayShowBattery) || (batteryVoltage < 1)) return; + String batteryVoltageString = " " + String(batteryVoltage, 1) + "V "; tft.setTextDatum(TL_DATUM); tft.setCursor(posX, posY); spr.loadFont(SMALL_FONT); @@ -382,7 +382,7 @@ void showBatteryVoltage(int32_t posX, int32_t posY) { } void showBatteryIcon(int32_t posX, int32_t posY) { // For TTGO T-Display posX=tft.width() - 32, posY=4 - if ((!displayShowBattery) || (battery_voltage < 1)) return; + if ((!displayShowBattery) || (batteryVoltage < 1)) return; uint8_t batteryLevel = battery.level(); uint16_t color; if (batteryLevel < 20) { @@ -391,7 +391,7 @@ void showBatteryIcon(int32_t posX, int32_t posY) { // For TTGO T-Display posX=t color = TFT_SILVER; } - if (battery_voltage > 4.5) { // Charging... + if (batteryVoltage > 4.5) { // Charging... color = iconDefaultColor; } From d82b31dcb63694659a8fa08a04c58f17580f0f59 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:01:52 +0100 Subject: [PATCH 06/53] Update platformio.ini to remove unused ENABLE_PIN --- platformio.ini | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/platformio.ini b/platformio.ini index 940cc6d4..d1d957d9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,13 +1,3 @@ -; PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html - [platformio] src_dir = . data_dir = data @@ -61,14 +51,12 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"005"\" + -D CO2_GADGET_REV="\"006"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer -DNEOPIXEL_PIN=26 ; Pinnumber for button for down/next and back / exit actions -DNEOPIXEL_COUNT=16 ; How many neopixels to control - ; -DENABLE_PIN=27 ; Reserved for the future to enable the sensor - ; -DENABLE_PIN_HIGH=1 ; Should be ENABLE_PIN high or low to enable the sensor? -DADC_BATTERY_PIN=34 ; ADC GPIO PIN to read battery voltage -DBLUE_PIN=32 ; GPIO to go HIGH on orange color range -DBLUE_PIN_LOW=0 From 81f1f90c34232fedaaaadcf7a042383d6243ebd6 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:34:32 +0100 Subject: [PATCH 07/53] Add release3_beta.yml to create beta versions --- .github/workflows/release3_beta.yml | 178 ++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 .github/workflows/release3_beta.yml diff --git a/.github/workflows/release3_beta.yml b/.github/workflows/release3_beta.yml new file mode 100644 index 00000000..fb77da42 --- /dev/null +++ b/.github/workflows/release3_beta.yml @@ -0,0 +1,178 @@ +name: Beta Release V2.5 + +on: + # push: + # branches: + # - development + workflow_dispatch: + +jobs: + build_beta: + name: Create Beta Release + + runs-on: ubuntu-latest + + strategy: + matrix: + environment: + # - esp32dev_beta + # - esp32dev_OLED_beta + # - TTGO_TDISPLAY_beta + - TTGO_TDISPLAY_SANDWICH_beta + # - TDISPLAY_S3_beta + # - esp32dev_ST7789_240x320_beta + + env: + CHIP_FAMILY: ${{ matrix.environment == 'TDISPLAY_S3_beta' && 'ESP32-S3' || 'ESP32' }} + + timeout-minutes: 30 + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Show environments + run: | + echo + + - name: Determine chipFamily + id: determine_chip_family + run: | + case "${{ matrix.environment }}" in + "esp32dev_beta") + CHIP_FAMILY="ESP32";; + "TDISPLAY_S3_beta") + CHIP_FAMILY="ESP32-S3";; + # Add more cases for other environments as needed + *) + CHIP_FAMILY="UNKNOWN";; + esac + echo "::set-output name=chipFamily::${CHIP_FAMILY}" + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U platformio + platformio update + + - name: Get the version + id: get_version + run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/} + + - name: Show version + run: echo ${{ steps.get_version.outputs.VERSION }} + + - name: Get current date + id: date + run: | + echo "::set-output name=date::$(date +'%d-%m-%Y')" + echo "::set-output name=time::$(date +'%H:%M:%S')" + + - name: Create beta manifest file + id: create_betamanifest + run: | + # Define offset values based on env.CHIP_FAMILY + if [[ "${{ env.CHIP_FAMILY }}" == "ESP32-S3" ]]; then + bootloader_offset=0 + partitions_offset=32768 + app0_offset=57344 + firmware_offset=65536 + spiffs_offset=13172736 + else + # Default values for ESP32 or other environments + bootloader_offset=4096 + partitions_offset=32768 + app0_offset=57344 + firmware_offset=65536 + spiffs_offset=3997696 + fi + + # Create beta manifest + echo "{" > ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " \"name\": \"${{ github.event.repository.name }}-${{ matrix.environment }}\"," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " \"flavour\": \"${{ matrix.environment }}\"," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " \"version\": \"${{ steps.get_version.outputs.VERSION }}-beta\"," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " \"compilation_date\": \"${{ steps.date.outputs.date }}\"," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " \"compilation_time\": \"${{ steps.date.outputs.time }}\"," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " \"new_install_prompt_erase\": true," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " \"new_install_improv_wait_time\": 20," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " \"builds\": [" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " {" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " \"chipFamily\": \"${{ env.CHIP_FAMILY }}\"," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " \"improv\": true," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " \"parts\": [" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " { \"path\": \"${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-bootloader.bin\", \"offset\": $bootloader_offset }," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " { \"path\": \"${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-partitions.bin\", \"offset\": $partitions_offset }," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " { \"path\": \"${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-firmware.bin\", \"offset\": $firmware_offset }," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " { \"path\": \"${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-spiffs.bin\", \"offset\": $spiffs_offset }" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " ]" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " }" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " ]" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo "}" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo "::set-output name=betamanifest::$(cat ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json)" + + - name: Read beta manifest files + run: | + echo "Beta Manifest:" + echo ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo "Beta Manifest file contents read with cat:" + cat ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + + - name: Copy beta manifest files + if: startsWith(github.ref, 'refs/tags/') + run: | + mkdir ./beta_firmware + cp ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + + - name: Build beta firmware file + run: | + pio run -e ${{ matrix.environment }} + + - name: Copy beta firmware files + if: startsWith(github.ref, 'refs/tags/') + run: | + cp .pio/build/${{ matrix.environment }}/bootloader.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-bootloader.bin + cp .pio/build/${{ matrix.environment }}/partitions.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-partitions.bin + cp .pio/build/${{ matrix.environment }}/firmware.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-firmware.bin + + - name: Build beta spiffs file + run: | + pio run -e ${{ matrix.environment }} -t buildfs + + - name: Copy beta spiffs files + if: startsWith(github.ref, 'refs/tags/') + run: | + ls -la ./beta_firmware + cp .pio/build/${{ matrix.environment }}/spiffs.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-spiffs.bin + + - name: Create Beta Release + id: create_beta_release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + name: ${{ github.event.repository.name }}-${{ steps.get_version.outputs.VERSION }}-beta + files: | + ./beta_firmware/*.bin + ./beta_firmware/*.json + draft: false + prerelease: true + generate_release_notes: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_ACTION_TOKEN }} + + - name: 📂 Sync beta files - FTP-Deploy-Action + uses: SamKirkland/FTP-Deploy-Action@2.0.0 + env: + FTP_SERVER: ${{ secrets.FTP_SERVER }} + FTP_USERNAME: ${{ secrets.FTP_USER }} + FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }} + LOCAL_DIR: ./beta_firmware/ + REMOTE_DIR: /${{ github.event.repository.name }}/beta/ + METHOD: ftp + PORT: 21 + ARGS: --verbose From 6164e03446731540569346fddb7e735948db0268 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:37:38 +0100 Subject: [PATCH 08/53] Update release3_beta.yml for Beta Release V2.5 Beta --- .github/workflows/release3_beta.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release3_beta.yml b/.github/workflows/release3_beta.yml index fb77da42..4a6d0860 100644 --- a/.github/workflows/release3_beta.yml +++ b/.github/workflows/release3_beta.yml @@ -1,4 +1,4 @@ -name: Beta Release V2.5 +name: Beta Release V2.5 Beta on: # push: From 6e1a03bf01f420012161b72251239ceedc26338d Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:50:12 +0100 Subject: [PATCH 09/53] Update release3_beta.yml workflow file --- .github/workflows/release3_beta.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release3_beta.yml b/.github/workflows/release3_beta.yml index 4a6d0860..06a5461d 100644 --- a/.github/workflows/release3_beta.yml +++ b/.github/workflows/release3_beta.yml @@ -1,9 +1,11 @@ name: Beta Release V2.5 Beta on: - # push: - # branches: - # - development + push: + branches: + - development + paths-ignore: + - '!.github/workflows/release3_beta.yml' # Ignore changes in the workflow file itself workflow_dispatch: jobs: @@ -12,6 +14,8 @@ jobs: runs-on: ubuntu-latest + if: contains(github.event.head_commit.message, 'Beta') + strategy: matrix: environment: From d290e00da9620a619a261909f46363934396ce2a Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:50:57 +0100 Subject: [PATCH 10/53] Test to create Beta version --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index d1d957d9..621468e8 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"006"\" + -D CO2_GADGET_REV="\"007"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From 8830059703a5b191dfa850ae4c79c69d9cdb841f Mon Sep 17 00:00:00 2001 From: Mariete Date: Thu, 22 Feb 2024 07:21:05 +0100 Subject: [PATCH 11/53] Update release3_beta.yml --- .github/workflows/release3_beta.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release3_beta.yml b/.github/workflows/release3_beta.yml index 06a5461d..2d08638b 100644 --- a/.github/workflows/release3_beta.yml +++ b/.github/workflows/release3_beta.yml @@ -19,12 +19,12 @@ jobs: strategy: matrix: environment: - # - esp32dev_beta - # - esp32dev_OLED_beta - # - TTGO_TDISPLAY_beta - - TTGO_TDISPLAY_SANDWICH_beta - # - TDISPLAY_S3_beta - # - esp32dev_ST7789_240x320_beta + # - esp32dev + # - esp32dev_OLED + # - TTGO_TDISPLAY + - TTGO_TDISPLAY_SANDWICH + # - TDISPLAY_S3 + # - esp32dev_ST7789_240x320 env: CHIP_FAMILY: ${{ matrix.environment == 'TDISPLAY_S3_beta' && 'ESP32-S3' || 'ESP32' }} From d87737e640598f921d1e302e06027c1f082a4b85 Mon Sep 17 00:00:00 2001 From: Mariete Date: Thu, 22 Feb 2024 07:43:05 +0100 Subject: [PATCH 12/53] Update release3_beta.yml --- .github/workflows/release3_beta.yml | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release3_beta.yml b/.github/workflows/release3_beta.yml index 2d08638b..ce1b966c 100644 --- a/.github/workflows/release3_beta.yml +++ b/.github/workflows/release3_beta.yml @@ -14,8 +14,6 @@ jobs: runs-on: ubuntu-latest - if: contains(github.event.head_commit.message, 'Beta') - strategy: matrix: environment: @@ -66,7 +64,17 @@ jobs: - name: Get the version id: get_version - run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/} + run: | + # Get the version from the commit message + commit_message=$(git log --format=%B -n 1 $GITHUB_SHA) + version_regex="Beta v([0-9]+\.[0-9]+\.[0-9]+)" + if [[ $commit_message =~ $version_regex ]]; then + version=${BASH_REMATCH[1]} + echo "::set-output name=VERSION::${version}" + else + echo "Commit message does not contain version information." + exit 1 + fi - name: Show version run: echo ${{ steps.get_version.outputs.VERSION }} @@ -128,7 +136,6 @@ jobs: cat ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json - name: Copy beta manifest files - if: startsWith(github.ref, 'refs/tags/') run: | mkdir ./beta_firmware cp ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json @@ -138,7 +145,6 @@ jobs: pio run -e ${{ matrix.environment }} - name: Copy beta firmware files - if: startsWith(github.ref, 'refs/tags/') run: | cp .pio/build/${{ matrix.environment }}/bootloader.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-bootloader.bin cp .pio/build/${{ matrix.environment }}/partitions.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-partitions.bin @@ -149,7 +155,6 @@ jobs: pio run -e ${{ matrix.environment }} -t buildfs - name: Copy beta spiffs files - if: startsWith(github.ref, 'refs/tags/') run: | ls -la ./beta_firmware cp .pio/build/${{ matrix.environment }}/spiffs.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-spiffs.bin @@ -157,7 +162,6 @@ jobs: - name: Create Beta Release id: create_beta_release uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') with: name: ${{ github.event.repository.name }}-${{ steps.get_version.outputs.VERSION }}-beta files: | @@ -180,3 +184,8 @@ jobs: METHOD: ftp PORT: 21 ARGS: --verbose + + - name: Clean eMariete.com Cache + # run: curl https://emariete.com/clean_cache_wp_rocket.php + run: curl https://emariete.com/clean_cache_litespeed.php + From fba8ac233b123698cb95c73c55ecd272006d10b6 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Thu, 22 Feb 2024 07:46:07 +0100 Subject: [PATCH 13/53] Test building Beta v0.10.008 --- .github/workflows/release3_beta.yml | 2 +- platformio.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release3_beta.yml b/.github/workflows/release3_beta.yml index ce1b966c..a4c6e4e4 100644 --- a/.github/workflows/release3_beta.yml +++ b/.github/workflows/release3_beta.yml @@ -1,4 +1,4 @@ -name: Beta Release V2.5 Beta +name: Beta Release V2.6 on: push: diff --git a/platformio.ini b/platformio.ini index 621468e8..c96be973 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"007"\" + -D CO2_GADGET_REV="\"008"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From 7590926103c64470b0365ddf8dc024d69186a788 Mon Sep 17 00:00:00 2001 From: Mariete Date: Thu, 22 Feb 2024 08:05:59 +0100 Subject: [PATCH 14/53] Update release3_beta.yml --- .github/workflows/release3_beta.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release3_beta.yml b/.github/workflows/release3_beta.yml index a4c6e4e4..90cc8aa7 100644 --- a/.github/workflows/release3_beta.yml +++ b/.github/workflows/release3_beta.yml @@ -1,11 +1,11 @@ -name: Beta Release V2.6 +name: Beta Release V2.7 Beta on: push: branches: - development paths-ignore: - - '!.github/workflows/release3_beta.yml' # Ignore changes in the workflow file itself + - '.github/workflows/release3_beta.yml' # Ignore changes in the workflow file itself workflow_dispatch: jobs: @@ -76,6 +76,18 @@ jobs: exit 1 fi + - name: Create Git tag + if: success() + run: | + git config user.name "GitHub Actions" + git config user.email "<>" + git tag -a "v${{ steps.get_version.outputs.VERSION }}-beta" -m "Beta Release v${{ steps.get_version.outputs.VERSION }}" + + - name: Push Git tag + if: success() + run: | + git push origin "v${{ steps.get_version.outputs.VERSION }}-beta" + - name: Show version run: echo ${{ steps.get_version.outputs.VERSION }} @@ -170,8 +182,10 @@ jobs: draft: false prerelease: true generate_release_notes: true + token: ${{ secrets.GITHUB_TOKEN }} env: - GITHUB_TOKEN: ${{ secrets.GITHUB_ACTION_TOKEN }} + CHIP_FAMILY: ${{ env.CHIP_FAMILY }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: 📂 Sync beta files - FTP-Deploy-Action uses: SamKirkland/FTP-Deploy-Action@2.0.0 From 2de88a0ba11cace29c271cd6e620652fb607dbed Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Thu, 22 Feb 2024 08:08:49 +0100 Subject: [PATCH 15/53] Test building Beta v0.10.009 --- .github/workflows/release3_beta.yml | 2 +- platformio.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release3_beta.yml b/.github/workflows/release3_beta.yml index 90cc8aa7..1aa5c186 100644 --- a/.github/workflows/release3_beta.yml +++ b/.github/workflows/release3_beta.yml @@ -1,4 +1,4 @@ -name: Beta Release V2.7 Beta +name: Beta Release V2.7 on: push: diff --git a/platformio.ini b/platformio.ini index c96be973..dd1fa9fa 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"008"\" + -D CO2_GADGET_REV="\"009"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From f62678764324b904d3ab50bbff2cb4ac92a84456 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Thu, 22 Feb 2024 08:15:03 +0100 Subject: [PATCH 16/53] Test building Beta v0.10.010 --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index dd1fa9fa..e8f7fbb2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"009"\" + -D CO2_GADGET_REV="\"010"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From a83555e498b76889c3665d186b053691c5643565 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Thu, 22 Feb 2024 09:08:40 +0100 Subject: [PATCH 17/53] Update battery voltage threshold for external power detection --- CO2_Gadget_Battery.h | 4 ++-- platformio.ini | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CO2_Gadget_Battery.h b/CO2_Gadget_Battery.h index 8e9ce2b9..e2c74e48 100644 --- a/CO2_Gadget_Battery.h +++ b/CO2_Gadget_Battery.h @@ -64,8 +64,8 @@ void batteryLoop() { lastBatteryVoltage = batteryVoltage; } } - // If battery voltage is more than 5% of the fully charged battery voltage, asume it's working on external power - workingOnExternalPower = (batteryVoltage * 1000 > batteryFullyChargedMillivolts + (batteryFullyChargedMillivolts * 5 / 100)); + // If battery voltage is more than 9% of the fully charged battery voltage (~4.58V), asume it's working on external power + workingOnExternalPower = (batteryVoltage * 1000 > batteryFullyChargedMillivolts + (batteryFullyChargedMillivolts * 9 / 100)); } #endif // CO2_Gadget_Battery_h \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index bb8effc2..5c526ca3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -61,7 +61,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"006"\" + -D CO2_GADGET_REV="\"007"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From 8627725949e4e3d04464c8c0701c855cff813e69 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Thu, 22 Feb 2024 09:49:30 +0100 Subject: [PATCH 18/53] Update battery level variable and add BATTERY_READ_INTERVAL --- CO2_Gadget.ino | 2 +- CO2_Gadget_Battery.h | 25 +++++++++++++++++-------- CO2_Gadget_MQTT.h | 2 +- platformio.ini | 2 +- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/CO2_Gadget.ino b/CO2_Gadget.ino index 64d6e93e..c3f9c00c 100644 --- a/CO2_Gadget.ino +++ b/CO2_Gadget.ino @@ -92,7 +92,7 @@ uint64_t timeInitializationCompleted = 0; // Variables for Battery reading float batteryVoltage = 0; -uint8_t battery_level = 0; +uint8_t batteryLevel = 100; uint16_t vRef = 1100; uint16_t batteryDischargedMillivolts = 3500; // Voltage of battery when we consider it discharged (0%). uint16_t batteryFullyChargedMillivolts = 4200; // Voltage of battery when it is considered fully charged (100%). diff --git a/CO2_Gadget_Battery.h b/CO2_Gadget_Battery.h index e2c74e48..fe3caf59 100644 --- a/CO2_Gadget_Battery.h +++ b/CO2_Gadget_Battery.h @@ -54,18 +54,27 @@ uint8_t getBatteryPercentage() { return battery.level(); } +const unsigned long BATTERY_READ_INTERVAL = 3000; // 3 seconds + void batteryLoop() { static float lastBatteryVoltage = readBatteryVoltage(); - readBatteryVoltage(); - if (!inMenu) { - if (abs(lastBatteryVoltage - batteryVoltage) >= 0.1) { // If battery voltage changed by at least 0.1V, update battery level - battery_level = getBatteryPercentage(); - // Serial.printf("-->[BATT] Battery Level: %d%%. Battery voltage changed from: %.4fV to %.4fV\n", battery_level, lastBatteryVoltage, batteryVoltage); - lastBatteryVoltage = batteryVoltage; + static unsigned long lastBatteryReadTime = 0; + + if (millis() - lastBatteryReadTime >= BATTERY_READ_INTERVAL) { // Check if at least 3 segundos have passed + readBatteryVoltage(); + if (!inMenu) { + if (abs(lastBatteryVoltage - batteryVoltage) >= 0.1) { // If battery voltage changed by at least 0.1V, update battery level + batteryLevel = getBatteryPercentage(); + // Serial.printf("-->[BATT] Battery Level: %d%%. Battery voltage changed from: %.4fV to %.4fV\n", batteryLevel, lastBatteryVoltage, batteryVoltage); + lastBatteryVoltage = batteryVoltage; + } } + // If battery voltage is more than 9% of the fully charged battery voltage (~4.58V), assume it's working on external power + workingOnExternalPower = (batteryVoltage * 1000 > batteryFullyChargedMillivolts + (batteryFullyChargedMillivolts * 9 / 100)); + // Serial.printf("-->[BATT] Battery Level: %d%%. Battery voltage: %.4fV. Working on external power: %s\n", batteryLevel, batteryVoltage, workingOnExternalPower ? "Yes" : "No"); + lastBatteryReadTime = millis(); // Update last read time } - // If battery voltage is more than 9% of the fully charged battery voltage (~4.58V), asume it's working on external power - workingOnExternalPower = (batteryVoltage * 1000 > batteryFullyChargedMillivolts + (batteryFullyChargedMillivolts * 9 / 100)); } + #endif // CO2_Gadget_Battery_h \ No newline at end of file diff --git a/CO2_Gadget_MQTT.h b/CO2_Gadget_MQTT.h index bcff135e..e5bad4fe 100644 --- a/CO2_Gadget_MQTT.h +++ b/CO2_Gadget_MQTT.h @@ -283,7 +283,7 @@ void publishMQTTAlarms() { void publishMQTTSystemData() { publishIntMQTT("/uptime", millis() / 1000); publishFloatMQTT("/voltage", batteryVoltage); - publishIntMQTT("/battery", battery_level); + publishIntMQTT("/battery", batteryLevel); publishIntMQTT("/freeMem", ESP.getFreeHeap()); publishIntMQTT("/wifiRSSI", WiFi.RSSI()); publishStrMQTT("/IP", WiFi.localIP().toString()); diff --git a/platformio.ini b/platformio.ini index 5c526ca3..d9a56d9f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -61,7 +61,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"007"\" + -D CO2_GADGET_REV="\"008"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From 39c8da3f92e19a6331eefdbfcfa75dbe5dfbf21c Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Thu, 22 Feb 2024 20:19:18 +0100 Subject: [PATCH 19/53] Improve battery reading --- CO2_Gadget_Battery.h | 29 ++++++++++++++++++++++++----- CO2_Gadget_Preferences.h | 11 ++++++----- CO2_Gadget_TFT.h | 5 ++--- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/CO2_Gadget_Battery.h b/CO2_Gadget_Battery.h index fe3caf59..1a05cf45 100644 --- a/CO2_Gadget_Battery.h +++ b/CO2_Gadget_Battery.h @@ -10,7 +10,7 @@ /*****************************************************************************************************/ // clang-format on -uint16_t timeBetweenBatteryRead = 5; +uint16_t timeBetweenBatteryRead = 1; uint64_t lastTimeBatteryRead = 0; // Time of last battery reading const uint8_t batterySamples = 3; // Number of samples to average for battery voltage. @@ -54,12 +54,32 @@ uint8_t getBatteryPercentage() { return battery.level(); } -const unsigned long BATTERY_READ_INTERVAL = 3000; // 3 seconds +// #include -void batteryLoop() { +// void readEfuse() { +// esp_adc_cal_characteristics_t chars; +// auto val_type = esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, 1100, &chars); +// if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) { +// Serial.println("eFuse Vref"); +// } else if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) { +// Serial.println("Two Point"); +// } else { +// Serial.println("Default"); +// } +// } + +const unsigned long BATTERY_READ_INTERVAL = 3000; // 3 seconds +// static bool firstReadBattery = true; + +void batteryLoop(bool forceReading = false) { static float lastBatteryVoltage = readBatteryVoltage(); static unsigned long lastBatteryReadTime = 0; - + + // if (firstReadBattery) { + // readEfuse(); + // firstReadBattery = false; + // } + if (millis() - lastBatteryReadTime >= BATTERY_READ_INTERVAL) { // Check if at least 3 segundos have passed readBatteryVoltage(); if (!inMenu) { @@ -76,5 +96,4 @@ void batteryLoop() { } } - #endif // CO2_Gadget_Battery_h \ No newline at end of file diff --git a/CO2_Gadget_Preferences.h b/CO2_Gadget_Preferences.h index 50f8132b..2d8ebec7 100644 --- a/CO2_Gadget_Preferences.h +++ b/CO2_Gadget_Preferences.h @@ -420,12 +420,13 @@ bool handleSavePreferencesfromJSON(String jsonPreferences) { rootTopic = JsonDocument["rootTopic"].as().c_str(); batteryDischargedMillivolts = JsonDocument["batDischgd"]; batteryFullyChargedMillivolts = JsonDocument["batChargd"]; - if (vRef != JsonDocument["vRef"]) { + // if (vRef != JsonDocument["vRef"]) { + // vRef = JsonDocument["vRef"]; + // battery.begin(vRef, voltageDividerRatio, &sigmoidal); + // delay(10); + // batteryVoltage = (float)battery.voltage() / 1000; + // } vRef = JsonDocument["vRef"]; - battery.begin(vRef, voltageDividerRatio, &sigmoidal); - delay(10); - batteryVoltage = (float)battery.voltage() / 1000; - } mqttClientId = JsonDocument["mqttClientId"].as().c_str(); mqttBroker = JsonDocument["mqttBroker"].as().c_str(); mqttUser = JsonDocument["mqttUser"].as().c_str(); diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index 9dcc68a3..3e317a85 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -376,15 +376,14 @@ void showBatteryVoltage(int32_t posX, int32_t posY) { tft.setTextDatum(TL_DATUM); tft.setCursor(posX, posY); spr.loadFont(SMALL_FONT); - spr.setTextColor(getBatteryColor(battery.voltage()), TFT_BLACK); + spr.setTextColor(getBatteryColor(batteryVoltage), TFT_BLACK); spr.printToSprite(batteryVoltageString); // Space padding helps over-write old numbers spr.unloadFont(); } void showBatteryIcon(int32_t posX, int32_t posY) { // For TTGO T-Display posX=tft.width() - 32, posY=4 - if ((!displayShowBattery) || (batteryVoltage < 1)) return; - uint8_t batteryLevel = battery.level(); uint16_t color; + if ((!displayShowBattery) || (batteryVoltage < 1)) return; if (batteryLevel < 20) { color = TFT_RED; } else { From bbdcee83fb5b03b4e971e4e6e4e0249e83425498 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Thu, 22 Feb 2024 20:44:10 +0100 Subject: [PATCH 20/53] Fix and improve getBatteryColor() function --- CO2_Gadget_TFT.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index 3e317a85..61624283 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -356,13 +356,13 @@ bool displayNotification(String notificationText, String notificationText2, noti return true; } -uint16_t getBatteryColor(uint16_t batteryVoltage) { +uint16_t getBatteryColor(float batteryVoltage) { uint16_t color; if (batteryVoltage <= 3.6) { color = TFT_RED; } else if (batteryVoltage <= 3.8) { color = TFT_ORANGE; - } else if (batteryVoltage <= 4.5) { + } else if (batteryVoltage <= (batteryFullyChargedMillivolts + (batteryFullyChargedMillivolts * 9 / 100)) / 100) { color = TFT_GREEN; } else { color = TFT_SKYBLUE; From 832eba6652a1748174cc38f2b3444f6be2faec98 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:09:22 +0100 Subject: [PATCH 21/53] Reworked battery readings and display to fix issues --- CO2_Gadget.ino | 42 ++++++++++++++++++++--------- CO2_Gadget_Battery.h | 57 ++++++++++++++-------------------------- CO2_Gadget_MQTT.h | 8 ++++++ CO2_Gadget_Preferences.h | 11 ++++---- CO2_Gadget_TFT.h | 3 ++- platformio.ini | 2 +- 6 files changed, 64 insertions(+), 59 deletions(-) diff --git a/CO2_Gadget.ino b/CO2_Gadget.ino index c3f9c00c..33f88b9f 100644 --- a/CO2_Gadget.ino +++ b/CO2_Gadget.ino @@ -18,6 +18,7 @@ // Functions and enum definitions void reverseButtons(bool reversed); void outputsLoop(); +void publishMQTTLogData(String logData); // Define enum for toneBuzzerBeep enum ToneBuzzerBeep { @@ -93,7 +94,7 @@ uint64_t timeInitializationCompleted = 0; // Variables for Battery reading float batteryVoltage = 0; uint8_t batteryLevel = 100; -uint16_t vRef = 1100; +uint16_t vRef = 960; uint16_t batteryDischargedMillivolts = 3500; // Voltage of battery when we consider it discharged (0%). uint16_t batteryFullyChargedMillivolts = 4200; // Voltage of battery when it is considered fully charged (100%). @@ -102,7 +103,7 @@ bool workingOnExternalPower = true; // True if working on external power (U uint32_t actualDisplayBrightness = 100; // To know if it's on or off bool displayOffOnExternalPower = false; uint16_t timeToDisplayOff = 0; // Time in seconds to turn off the display to save power. -volatile uint64_t lastTimeButtonPressed = 0; // Last time stamp a button was pressed +volatile uint64_t lastTimeButtonPressed = 0; // Last time stamp button up was pressed // Variables for MQTT timming uint16_t timeBetweenMQTTPublish = 60; // Time in seconds between MQTT transmissions @@ -287,6 +288,7 @@ void wakeUpDisplay() { if (actualDisplayBrightness == 0) { #if defined(SUPPORT_OLED) || defined(SUPPORT_TFT) setDisplayBrightness(DisplayBrightness); + publishMQTTLogData("Display woken up. Setting display brightness to " + String(DisplayBrightness)); #endif lastTimeButtonPressed = millis(); } @@ -434,25 +436,40 @@ void adjustBrightnessLoop() { if ((!displayOffOnExternalPower) && (workingOnExternalPower)) { setDisplayBrightness(DisplayBrightness); } + if (timeToDisplayOff==0) { + setDisplayBrightness(DisplayBrightness); + } return; } // Display backlight is NOT sleeping and brightness change detected if ((actualDisplayBrightness > 0) && (actualDisplayBrightness != DisplayBrightness)) { setDisplayBrightness(DisplayBrightness); + publishMQTTLogData("Setting display brightness to " + String(DisplayBrightness)); } - // If configured not to turn off the display on external power and it's working on external power, do nothing and return (except if DisplayBrightness is 0)) - if ((!displayOffOnExternalPower) && (workingOnExternalPower)) { + // If configured not to turn off the display on external power and it's working on external power, do nothing and return (except if DisplayBrightness is 0, then turn on display)) + if ((workingOnExternalPower) && (!displayOffOnExternalPower)) { if (actualDisplayBrightness == 0) { setDisplayBrightness(DisplayBrightness); // Exception: When USB connected (just connected) & TFT is OFF -> Turn Display ON + publishMQTTLogData("Turning on display on external power. Actual brightness: " + String(actualDisplayBrightness)); } return; } + if (timeToDisplayOff == 0) return; // If timeToDisplayOff is 0, don't turn off the display + if ((actualDisplayBrightness != 0) && (millis() - lastTimeButtonPressed >= timeToDisplayOff * 1000) && DisplayBrightness > 0) { - Serial.println("-->[MAIN] Turning off display to save power. Actual brightness: " + String(actualDisplayBrightness)); - turnOffDisplay(); + if ((workingOnExternalPower) && (displayOffOnExternalPower)) { + Serial.println("-->[MAIN] Turning off display on external power to save power. Actual brightness: " + String(actualDisplayBrightness)); + turnOffDisplay(); + publishMQTTLogData("[MAIN] Turning off display on external power to save power. Actual brightness: " + String(actualDisplayBrightness)); + } + if (!workingOnExternalPower) { + Serial.println("-->[MAIN] Turning off display on battery to save power. Actual brightness: " + String(actualDisplayBrightness)); + turnOffDisplay(); + publishMQTTLogData("[MAIN] Turning off display on battery to save power. Actual brightness: " + String(actualDisplayBrightness)); + } } #endif } @@ -490,8 +507,8 @@ void utilityLoop() { void setup() { uint32_t brown_reg_temp = READ_PERI_REG(RTC_CNTL_BROWN_OUT_REG); // save WatchDog register WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); // disable brownout detector - setCpuFrequencyMhz(80); // Lower CPU frecuency to reduce power consumption Serial.begin(115200); + Serial.setRxBufferSize(1024); delay(50); #ifdef AUTO_VERSION Serial.printf("\n-->[STUP] CO2 Gadget Version: %s%s Flavour: %s (Git HEAD: %s)\n", CO2_GADGET_VERSION, CO2_GADGET_REV, FLAVOUR, AUTO_VERSION); @@ -505,14 +522,13 @@ void setup() { Serial.printf("-->[STUP] Free PSRAM: %d\n", ESP.getFreePsram()); // Get the size of the flash memory - uint32_t flash_size = ESP.getFlashChipSize(); - Serial.printf("-->[STUP] Flash size: %d\n", flash_size); - Serial.printf("-->[STUP] Flash speed: %d\n", ESP.getFlashChipSpeed()); - Serial.printf("-->[STUP] Flash mode: %d\n", ESP.getFlashChipMode()); + // Serial.printf("-->[STUP] Flash size: %d\n", ESP.getFlashChipSize()); + // Serial.printf("-->[STUP] Flash speed: %d\n", ESP.getFlashChipSpeed()); + // Serial.printf("-->[STUP] Flash mode: %d\n", ESP.getFlashChipMode()); Serial.printf("-->[STUP] Starting up...\n\n"); - initImprov(); + // initImprov(); initPreferences(); initBattery(); initGPIO(); @@ -560,4 +576,4 @@ void loop() { buttonsLoop(); menuLoop(); BLELoop(); -} +} \ No newline at end of file diff --git a/CO2_Gadget_Battery.h b/CO2_Gadget_Battery.h index 1a05cf45..3e9f349b 100644 --- a/CO2_Gadget_Battery.h +++ b/CO2_Gadget_Battery.h @@ -10,6 +10,7 @@ /*****************************************************************************************************/ // clang-format on +float lastBatteryVoltage = 0; uint16_t timeBetweenBatteryRead = 1; uint64_t lastTimeBatteryRead = 0; // Time of last battery reading const uint8_t batterySamples = 3; // Number of samples to average for battery voltage. @@ -24,34 +25,30 @@ const float voltageDividerRatio = (voltageDividerR1Ohms + voltageDividerR2Ohms) #include Battery battery(batteryDischargedMillivolts, batteryFullyChargedMillivolts, ADC_BATTERY_PIN); -/** - * 1 cell li-ion/li-poly battery wired to A0, continuous sensing, sigmoidal mapping function, cut off at 3000mV - * https://github.com/rlogiacco/BatterySense#lesser-than-5v-with-voltage-booster - **/ + void initBattery() { battery.onDemand(battery.ON_DEMAND_DISABLE, LOW); battery.begin(vRef, voltageDividerRatio, &sigmoidal); + Serial.println("-->[BATT***] Battery initialized with vRef: " + String(vRef) + " and voltage divider ratio: " + String(voltageDividerRatio)); } -float readBatteryVoltage() { - float avrgBatteryVoltage = 0; +void readBatteryVoltage() { + float batteryVoltageNow = 0; if ((millis() - lastTimeBatteryRead >= timeBetweenBatteryRead * 1000) || (lastTimeBatteryRead == 0)) { for (uint8_t i = 0; i < batterySamples; i++) { - avrgBatteryVoltage += (float)battery.voltage() / 1000; + batteryVoltageNow += float(battery.voltage()) / 1000; delay(10); } - avrgBatteryVoltage /= 3; - batteryVoltage = avrgBatteryVoltage; - // Serial.print("-->[BATT] Battery read: "); - // Serial.print(batteryVoltage); - // Serial.println("V"); + batteryVoltageNow /= 3; + batteryVoltage = batteryVoltageNow; + batteryLevel = battery.level(); lastTimeBatteryRead = millis(); + + // If battery voltage is more than 9% of the fully charged battery voltage (~4.58V), assume it's working on external power + workingOnExternalPower = (batteryVoltageNow * 1000 > batteryFullyChargedMillivolts + (batteryFullyChargedMillivolts * 9 / 100)); + + // publishMQTTLogData("Battery Level: " + String(batteryLevel) + "% Battery voltage changed from: " + String(lastBatteryVoltage) + "V to " + String(batteryVoltage) + "V"); } - return (batteryVoltage); -} - -uint8_t getBatteryPercentage() { - return battery.level(); } // #include @@ -68,32 +65,16 @@ uint8_t getBatteryPercentage() { // } // } -const unsigned long BATTERY_READ_INTERVAL = 3000; // 3 seconds -// static bool firstReadBattery = true; - -void batteryLoop(bool forceReading = false) { - static float lastBatteryVoltage = readBatteryVoltage(); - static unsigned long lastBatteryReadTime = 0; - - // if (firstReadBattery) { - // readEfuse(); - // firstReadBattery = false; - // } - - if (millis() - lastBatteryReadTime >= BATTERY_READ_INTERVAL) { // Check if at least 3 segundos have passed +void batteryLoop() { + float batteryVoltageNow = 0; readBatteryVoltage(); + // Serial.printf("-->[BATT] Battery Level: %d%%. Battery voltage: %.4fV\n", batteryLevel, batteryVoltageNow); if (!inMenu) { - if (abs(lastBatteryVoltage - batteryVoltage) >= 0.1) { // If battery voltage changed by at least 0.1V, update battery level - batteryLevel = getBatteryPercentage(); - // Serial.printf("-->[BATT] Battery Level: %d%%. Battery voltage changed from: %.4fV to %.4fV\n", batteryLevel, lastBatteryVoltage, batteryVoltage); + if (abs(lastBatteryVoltage - batteryVoltage) >= 0.1) { // If battery voltage changed by at least 0.1V, update battery level + Serial.printf("-->[BATT] Battery Level: %d%%. Battery voltage changed from: %.4fV to %.4fV\n", batteryLevel, lastBatteryVoltage, batteryVoltage); lastBatteryVoltage = batteryVoltage; } } - // If battery voltage is more than 9% of the fully charged battery voltage (~4.58V), assume it's working on external power - workingOnExternalPower = (batteryVoltage * 1000 > batteryFullyChargedMillivolts + (batteryFullyChargedMillivolts * 9 / 100)); - // Serial.printf("-->[BATT] Battery Level: %d%%. Battery voltage: %.4fV. Working on external power: %s\n", batteryLevel, batteryVoltage, workingOnExternalPower ? "Yes" : "No"); - lastBatteryReadTime = millis(); // Update last read time - } } #endif // CO2_Gadget_Battery_h \ No newline at end of file diff --git a/CO2_Gadget_MQTT.h b/CO2_Gadget_MQTT.h index e5bad4fe..63c9ce2d 100644 --- a/CO2_Gadget_MQTT.h +++ b/CO2_Gadget_MQTT.h @@ -251,6 +251,14 @@ void initMQTT() { #endif } +void publishMQTTLogData(String logData) { +#ifdef SUPPORT_MQTT + // if (activeMQTT && !troubledMQTT && !troubledWIFI && (WiFi.status() == WL_CONNECTED) && mqttClient.connected()) { + // publishStrMQTT("/log", logData); + // } +#endif +} + void publishMQTTAlarms() { static bool MQTTGreenAlarm, MQTTOrangeAlarm, MQTTRedAlarm = false; diff --git a/CO2_Gadget_Preferences.h b/CO2_Gadget_Preferences.h index 2d8ebec7..0b4a6350 100644 --- a/CO2_Gadget_Preferences.h +++ b/CO2_Gadget_Preferences.h @@ -420,12 +420,11 @@ bool handleSavePreferencesfromJSON(String jsonPreferences) { rootTopic = JsonDocument["rootTopic"].as().c_str(); batteryDischargedMillivolts = JsonDocument["batDischgd"]; batteryFullyChargedMillivolts = JsonDocument["batChargd"]; - // if (vRef != JsonDocument["vRef"]) { - // vRef = JsonDocument["vRef"]; - // battery.begin(vRef, voltageDividerRatio, &sigmoidal); - // delay(10); - // batteryVoltage = (float)battery.voltage() / 1000; - // } + if (vRef != JsonDocument["vRef"]) { // If battery reference changed, apply it + vRef = JsonDocument["vRef"]; + battery.begin(vRef, voltageDividerRatio, &sigmoidal); + readBatteryVoltage(); + } vRef = JsonDocument["vRef"]; mqttClientId = JsonDocument["mqttClientId"].as().c_str(); mqttBroker = JsonDocument["mqttBroker"].as().c_str(); diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index 61624283..f2a93c81 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -362,7 +362,7 @@ uint16_t getBatteryColor(float batteryVoltage) { color = TFT_RED; } else if (batteryVoltage <= 3.8) { color = TFT_ORANGE; - } else if (batteryVoltage <= (batteryFullyChargedMillivolts + (batteryFullyChargedMillivolts * 9 / 100)) / 100) { + } else if (!workingOnExternalPower) { color = TFT_GREEN; } else { color = TFT_SKYBLUE; @@ -384,6 +384,7 @@ void showBatteryVoltage(int32_t posX, int32_t posY) { void showBatteryIcon(int32_t posX, int32_t posY) { // For TTGO T-Display posX=tft.width() - 32, posY=4 uint16_t color; if ((!displayShowBattery) || (batteryVoltage < 1)) return; + if (batteryLevel < 20) { color = TFT_RED; } else { diff --git a/platformio.ini b/platformio.ini index d9a56d9f..d6917ef4 100644 --- a/platformio.ini +++ b/platformio.ini @@ -61,7 +61,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"008"\" + -D CO2_GADGET_REV="\"010"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From 5c8f3e9a9374ce7d0eee2a0ef98a5ee63cd851d0 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Fri, 23 Feb 2024 19:38:34 +0100 Subject: [PATCH 22/53] Refactor battery icon into sprite --- CO2_Gadget_TFT.h | 61 +++++++++++++++++++++++++++--------------------- platformio.ini | 2 +- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index f2a93c81..038d4521 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -395,6 +395,40 @@ void showBatteryIcon(int32_t posX, int32_t posY) { // For TTGO T-Display posX=t color = iconDefaultColor; } + if (spr.createSprite(34, 14) == nullptr) { + Serial.printf("-->[TFT ] Error: sprite not created, not enough free RAM! Free RAM: %d\n", ESP.getFreeHeap()); + spr.deleteSprite(); + return; + } + + spr.fillSprite(TFT_BLACK); + + spr.drawRoundRect(0, 0, 32, 14, 2, color); // Battery outter rectangle + spr.drawLine(33, 4, 33, 10, color); + + if (batteryLevel > 20) spr.fillRect(4, 2, 4, 10, color); + if (batteryLevel > 40) spr.fillRect(11, 2, 4, 10, color); + if (batteryLevel > 60) spr.fillRect(18, 2, 4, 10, color); + if (batteryLevel > 80) spr.fillRect(25, 2, 4, 10, color); + + spr.pushSprite(posX, posY); + spr.deleteSprite(); +} + +void showBatteryIconOLD(int32_t posX, int32_t posY) { // For TTGO T-Display posX=tft.width() - 32, posY=4 + uint16_t color; + if ((!displayShowBattery) || (batteryVoltage < 1)) return; + + if (batteryLevel < 20) { + color = TFT_RED; + } else { + color = TFT_SILVER; + } + + if (batteryVoltage > 4.5) { // Charging... + color = iconDefaultColor; + } + tft.drawRoundRect(posX, posY, 32, 14, 2, color); // Battery outter rectangle tft.drawLine(posX + 33, posY + 4, posX + 33, posY + 10, color); @@ -522,31 +556,6 @@ uint16_t getCO2Color(uint16_t co2) { return color; } -void OLDshowCO2(uint16_t co2, int32_t posX, int32_t posY, uint16_t pixelsToBaseline) { - if (co2 > 9999) co2 = 9999; - - spr.loadFont(BIG_FONT); - uint16_t width = spr.textWidth("0000"); - uint16_t height = elementPosition.co2FontDigitsHeight; - uint16_t posSpriteX = posX - width; - uint16_t posSpriteY = posY - height; - if (posSpriteX < 0) posSpriteX = 0; - if (posSpriteY < 0) posSpriteY = 0; - if (spr.createSprite(width, height) == nullptr) { - Serial.printf("-->[TFT ] Error: sprite not created, not enough free RAM! Free RAM: %d\n", ESP.getFreeHeap()); - spr.unloadFont(); - spr.deleteSprite(); - return; - } - // spr.drawRect(0, 0, width, height, TFT_WHITE); - spr.setTextColor(getCO2Color(co2), TFT_BLACK); - spr.setTextDatum(TR_DATUM); - spr.drawNumber(co2, width, 0); - spr.pushSprite(posSpriteX, posSpriteY); - spr.unloadFont(); - spr.deleteSprite(); -} - void showCO2(uint16_t co2, int32_t posX, int32_t posY, uint16_t pixelsToBaseline) { if ((co2 == previousCO2Value) || (co2 == 0) || (co2 > 9999)) return; @@ -557,7 +566,7 @@ void showCO2(uint16_t co2, int32_t posX, int32_t posY, uint16_t pixelsToBaseline uint16_t posSpriteY = posY - height; uint16_t color = getCO2Color(co2); if (posSpriteY < 0) posSpriteY = 0; - spr.createSprite(digitWidth, height); + // spr.createSprite(digitWidth, height); if (spr.createSprite(digitWidth, height) == nullptr) { // Serial.printf("-->[TFT ] Error: sprite not created, not enough free RAM! Free RAM: %d\n", ESP.getFreeHeap()); spr.unloadFont(); diff --git a/platformio.ini b/platformio.ini index d6917ef4..388a341e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -61,7 +61,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"010"\" + -D CO2_GADGET_REV="\"011"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From 77f9ac8456d94d30b1bec30dfbcde2988a9b1b34 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Fri, 23 Feb 2024 20:19:22 +0100 Subject: [PATCH 23/53] Chsnge battery charge calculation from Symmetric sigmoidal approximation to Asymmetric sigmoidal approximation --- CO2_Gadget_Battery.h | 4 ++-- CO2_Gadget_MQTT.h | 6 +++--- CO2_Gadget_Menu.h | 2 +- CO2_Gadget_Preferences.h | 2 +- CO2_Gadget_TFT.h | 3 ++- platformio.ini | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CO2_Gadget_Battery.h b/CO2_Gadget_Battery.h index 3e9f349b..64efbc38 100644 --- a/CO2_Gadget_Battery.h +++ b/CO2_Gadget_Battery.h @@ -28,7 +28,7 @@ Battery battery(batteryDischargedMillivolts, batteryFullyChargedMillivolts, ADC_ void initBattery() { battery.onDemand(battery.ON_DEMAND_DISABLE, LOW); - battery.begin(vRef, voltageDividerRatio, &sigmoidal); + battery.begin(vRef, voltageDividerRatio, &asigmoidal); Serial.println("-->[BATT***] Battery initialized with vRef: " + String(vRef) + " and voltage divider ratio: " + String(voltageDividerRatio)); } @@ -41,7 +41,7 @@ void readBatteryVoltage() { } batteryVoltageNow /= 3; batteryVoltage = batteryVoltageNow; - batteryLevel = battery.level(); + batteryLevel = battery.level(batteryVoltage*1000); lastTimeBatteryRead = millis(); // If battery voltage is more than 9% of the fully charged battery voltage (~4.58V), assume it's working on external power diff --git a/CO2_Gadget_MQTT.h b/CO2_Gadget_MQTT.h index 63c9ce2d..6797cc6a 100644 --- a/CO2_Gadget_MQTT.h +++ b/CO2_Gadget_MQTT.h @@ -253,9 +253,9 @@ void initMQTT() { void publishMQTTLogData(String logData) { #ifdef SUPPORT_MQTT - // if (activeMQTT && !troubledMQTT && !troubledWIFI && (WiFi.status() == WL_CONNECTED) && mqttClient.connected()) { - // publishStrMQTT("/log", logData); - // } + if (activeMQTT && !troubledMQTT && !troubledWIFI && (WiFi.status() == WL_CONNECTED) && mqttClient.connected()) { + publishStrMQTT("/log", logData); + } #endif } diff --git a/CO2_Gadget_Menu.h b/CO2_Gadget_Menu.h index 2947ec3e..0fe78654 100644 --- a/CO2_Gadget_Menu.h +++ b/CO2_Gadget_Menu.h @@ -590,7 +590,7 @@ MENU(espnowConfigMenu, "ESP-NOW Config", doNothing, noEvent, wrapStyle #endif // SUPPORT_ESPNOW result doSetvRef(eventMask e, navNode &nav, prompt &item) { - battery.begin(vRef, voltageDividerRatio, &sigmoidal); + battery.begin(vRef, voltageDividerRatio, &asigmoidal); delay(10); batteryVoltage = (float)battery.voltage() / 1000; nav.target-> dirty = true; diff --git a/CO2_Gadget_Preferences.h b/CO2_Gadget_Preferences.h index 0b4a6350..c5f33d1b 100644 --- a/CO2_Gadget_Preferences.h +++ b/CO2_Gadget_Preferences.h @@ -422,7 +422,7 @@ bool handleSavePreferencesfromJSON(String jsonPreferences) { batteryFullyChargedMillivolts = JsonDocument["batChargd"]; if (vRef != JsonDocument["vRef"]) { // If battery reference changed, apply it vRef = JsonDocument["vRef"]; - battery.begin(vRef, voltageDividerRatio, &sigmoidal); + battery.begin(vRef, voltageDividerRatio, &asigmoidal); readBatteryVoltage(); } vRef = JsonDocument["vRef"]; diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index 038d4521..f8dcf3a7 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -401,8 +401,9 @@ void showBatteryIcon(int32_t posX, int32_t posY) { // For TTGO T-Display posX=t return; } - spr.fillSprite(TFT_BLACK); + publishMQTTLogData("Battery Level: " + String(batteryLevel) + "% Battery voltage: " + String(batteryVoltage) + "V"); + spr.fillSprite(TFT_BLACK); spr.drawRoundRect(0, 0, 32, 14, 2, color); // Battery outter rectangle spr.drawLine(33, 4, 33, 10, color); diff --git a/platformio.ini b/platformio.ini index 388a341e..9495af39 100644 --- a/platformio.ini +++ b/platformio.ini @@ -61,7 +61,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"011"\" + -D CO2_GADGET_REV="\"012"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From dc4a087d54c89c249543d5e89ed94cba6ccb2a28 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sat, 24 Feb 2024 11:02:26 +0100 Subject: [PATCH 24/53] Update define TDISPLAY_S3 to official define ARDUINO_LILYGO_T_DISPLAY_S3 --- CO2_Gadget_TFT.h | 4 ++-- platformio.ini | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index f5fcfaeb..387bcdf5 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -198,7 +198,7 @@ void setDisplayBrightness(uint16_t newBrightness) { actualDisplayBrightness = newBrightness; } #endif -#ifdef TDISPLAY_S3 +#ifdef ARDUINO_LILYGO_T_DISPLAY_S3 if (actualDisplayBrightness != newBrightness) { // Serial.printf("\n-->[TFT ] DisplayBrightness value at %d\n", DisplayBrightness); // Serial.printf("-->[TFT ] Old actualDisplayBrightness value at %d\n", actualDisplayBrightness); @@ -267,7 +267,7 @@ void initBacklight() { pinMode(TFT_BL, OUTPUT); setDisplayBrightness(DisplayBrightness); #endif -#ifdef TDISPLAY_S3 +#ifdef ARDUINO_LILYGO_T_DISPLAY_S3 pinMode(TFT_BL, OUTPUT); pinMode(TFT_POWER_ON_BATTERY, OUTPUT); delay(50); diff --git a/platformio.ini b/platformio.ini index e8f7fbb2..89eae626 100644 --- a/platformio.ini +++ b/platformio.ini @@ -241,7 +241,6 @@ build_flags = ${common_env_data.build_flags} -DSUPPORT_OTA -DARDUINO_ESP32_DEV=1 - -DTDISPLAY_S3 -DBTN_UP=14 ; Pinnumber for button for up/previous and select / enter actions -DBTN_DWN=0 ; Pinnum -DADC_BATTERY_PIN=4 ; ADC GPIO PIN to read battery voltage @@ -254,8 +253,8 @@ build_flags = -DBLUE_PIN=03 ; GPIO to go HIGH on orange color range -DSUPPORT_TFT -DLV_LVGL_H_INCLUDE_SIMPLE - -DARDUINO_USB_CDC_ON_BOOT=1 - -DARDUINO_USB_MODE=1 + ; -DARDUINO_USB_CDC_ON_BOOT=1 + ; -DARDUINO_USB_MODE=1 -DTOUCH_MODULES_CST_MUTUAL -DUSER_SETUP_LOADED=1 -DBOARD_HAS_PSRAM From 8245119e2dbe909e4b078fe0fb64a37933cc7a63 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sat, 24 Feb 2024 11:51:57 +0100 Subject: [PATCH 25/53] Update batteryDischargedMillivolts default value to 3200mV --- CO2_Gadget.ino | 2 +- CO2_Gadget_Preferences.h | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CO2_Gadget.ino b/CO2_Gadget.ino index 33f88b9f..8ba3f8d6 100644 --- a/CO2_Gadget.ino +++ b/CO2_Gadget.ino @@ -95,7 +95,7 @@ uint64_t timeInitializationCompleted = 0; float batteryVoltage = 0; uint8_t batteryLevel = 100; uint16_t vRef = 960; -uint16_t batteryDischargedMillivolts = 3500; // Voltage of battery when we consider it discharged (0%). +uint16_t batteryDischargedMillivolts = 3200; // Voltage of battery when we consider it discharged (0%). uint16_t batteryFullyChargedMillivolts = 4200; // Voltage of battery when it is considered fully charged (100%). // Variables to control automatic display off to save power diff --git a/CO2_Gadget_Preferences.h b/CO2_Gadget_Preferences.h index c5f33d1b..2ac43983 100644 --- a/CO2_Gadget_Preferences.h +++ b/CO2_Gadget_Preferences.h @@ -76,9 +76,8 @@ void initPreferences() { // Serial.printf("-->[PREF] Preferences NOT cleared\n"); // } // preferences.end(); - // delay(1000); + // delay(000); preferences.begin("CO2-Gadget", false); - // preferences.clear(); // Remove all preferences customCalibrationValue = preferences.getUInt("customCalValue", 415); tempOffset = float(preferences.getFloat("tempOffset", 0)); altitudeMeters = preferences.getUInt("altitudeMeters", 0); @@ -102,7 +101,7 @@ void initPreferences() { activeMQTT = false; preferences.putBool("activeMQTT", activeMQTT); } - batteryDischargedMillivolts = preferences.getUInt("batDischgd", 3500); + batteryDischargedMillivolts = preferences.getUInt("batDischgd", 3200); batteryFullyChargedMillivolts = preferences.getUInt("batChargd", 4200); vRef = preferences.getUInt("vRef", 930); // Looks like, due to a bug, 930 is a goos starting number for vRef timeToDisplayOff = preferences.getUInt("tToDispOff", 60); @@ -263,7 +262,7 @@ String getPreferencesAsJson() { doc["activeESPNOW"] = preferences.getBool("activeESPNOW", false); doc["activeOTA"] = preferences.getBool("activeOTA", false); doc["rootTopic"] = preferences.getString("rootTopic", rootTopic); - doc["batDischgd"] = preferences.getInt("batDischgd", 3500); + doc["batDischgd"] = preferences.getInt("batDischgd", 3200); doc["batChargd"] = preferences.getInt("batChargd", 4200); doc["vRef"] = preferences.getInt("vRef", 930); doc["mqttClientId"] = preferences.getString("mqttClientId", mqttClientId); From 856d81d1a760c8ce0f69a34657795b5639984d58 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sat, 24 Feb 2024 13:41:55 +0100 Subject: [PATCH 26/53] Update restart endpoint in preferences.html --- CO2_Gadget.ino | 3 +-- CO2_Gadget_Preferences.h | 7 +++++++ data/preferences.html | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CO2_Gadget.ino b/CO2_Gadget.ino index 8ba3f8d6..7e5e1fc8 100644 --- a/CO2_Gadget.ino +++ b/CO2_Gadget.ino @@ -508,7 +508,6 @@ void setup() { uint32_t brown_reg_temp = READ_PERI_REG(RTC_CNTL_BROWN_OUT_REG); // save WatchDog register WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); // disable brownout detector Serial.begin(115200); - Serial.setRxBufferSize(1024); delay(50); #ifdef AUTO_VERSION Serial.printf("\n-->[STUP] CO2 Gadget Version: %s%s Flavour: %s (Git HEAD: %s)\n", CO2_GADGET_VERSION, CO2_GADGET_REV, FLAVOUR, AUTO_VERSION); @@ -528,7 +527,7 @@ void setup() { Serial.printf("-->[STUP] Starting up...\n\n"); - // initImprov(); + initImprov(); initPreferences(); initBattery(); initGPIO(); diff --git a/CO2_Gadget_Preferences.h b/CO2_Gadget_Preferences.h index 2ac43983..1be7cfc3 100644 --- a/CO2_Gadget_Preferences.h +++ b/CO2_Gadget_Preferences.h @@ -5,9 +5,14 @@ #include Preferences preferences; +uint8_t prefVersion = 0; +uint8_t prefRevision = 0; + void printPreferences() { Serial.printf("-->[PREF] \n"); Serial.printf("-->[PREF] LOADED PREFERENCES FROM NVR:\n"); + Serial.printf("-->[PREF] prefVersion:\t #%d#\n", prefVersion); + Serial.printf("-->[PREF] prefRevision:\t #%d#\n", prefRevision); Serial.printf("-->[PREF] customCalValue: #%d#\n", customCalibrationValue); Serial.printf("-->[PREF] tempOffset:\t #%.1f#\n", tempOffset); Serial.printf("-->[PREF] altitudeMeters:\t #%d#\n", altitudeMeters); @@ -78,6 +83,8 @@ void initPreferences() { // preferences.end(); // delay(000); preferences.begin("CO2-Gadget", false); + prefVersion = preferences.getUInt("prefVersion", 0); + prefRevision = preferences.getUInt("prefRevision", 0); customCalibrationValue = preferences.getUInt("customCalValue", 415); tempOffset = float(preferences.getFloat("tempOffset", 0)); altitudeMeters = preferences.getUInt("altitudeMeters", 0); diff --git a/data/preferences.html b/data/preferences.html index e06a644d..5b22176a 100644 --- a/data/preferences.html +++ b/data/preferences.html @@ -618,7 +618,7 @@

CO2 Gadget Preferences

// If the user confirms, proceed with the restart if (isConfirmed) { // Send a request to the ESP32 endpoint to trigger a reset - fetch('/restart-esp32', { + fetch('/restart', { method: 'POST', headers: { 'Content-Type': 'application/json', From fa9b4f18a8e20e008530564e05456c3255f7a829 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:18:39 +0100 Subject: [PATCH 27/53] Add troubleshooting indicators for troubled WiFi and MQTT connections --- CO2_Gadget_TFT.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index 387bcdf5..8fb6ca78 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -406,6 +406,11 @@ void showBatteryIcon(int32_t posX, int32_t posY) { // For TTGO T-Display posX=t void showWiFiIcon(int32_t posX, int32_t posY) { int8_t rssi = WiFi.RSSI(); + if (troubledWIFI) { + tft.drawRoundRect(posX - 2, posY - 2, 16 + 4, 16 + 4, 2, TFT_RED); + tft.drawBitmap(posX, posY, iconWiFi, 16, 16, TFT_BLACK, TFT_RED); + return; + } tft.drawRoundRect(posX - 2, posY - 2, 16 + 4, 16 + 4, 2, TFT_DARKGREY); if (!activeWIFI) { tft.drawBitmap(posX, posY, iconWiFi, 16, 16, TFT_BLACK, TFT_DARKGREY); @@ -415,10 +420,10 @@ void showWiFiIcon(int32_t posX, int32_t posY) { tft.drawBitmap(posX, posY, iconWiFi, 16, 16, TFT_BLACK, iconDefaultColor); else if (rssi < 70) tft.drawBitmap(posX, posY, iconWiFiMed, 16, 16, TFT_BLACK, TFT_ORANGE); - else if (rssi < 90) + else if (rssi < 80) tft.drawBitmap(posX, posY, iconWiFiMed, 16, 16, TFT_BLACK, TFT_YELLOW); } else { - tft.drawBitmap(posX, posY, iconWiFiLow, 16, 16, TFT_BLACK, TFT_RED); + tft.drawBitmap(posX, posY, iconWiFiLow, 16, 16, TFT_BLACK, TFT_BLUE); } } } @@ -433,6 +438,11 @@ void showBLEIcon(int32_t posX, int32_t posY) { } void showMQTTIcon(int32_t posX, int32_t posY) { + if (troubledMQTT) { + tft.drawRoundRect(posX - 2, posY - 2, 16 + 4, 16 + 4, 2, TFT_RED); + tft.drawBitmap(posX, posY, iconMQTT, 16, 16, TFT_BLACK, TFT_RED); + return; + } tft.drawRoundRect(posX - 2, posY - 2, 16 + 4, 16 + 4, 2, TFT_DARKGREY); if (!activeMQTT) { tft.drawBitmap(posX, posY, iconMQTT, 16, 16, TFT_BLACK, TFT_DARKGREY); From d50ee55ff2a5a51d83e91c20bcdb41bb1943ea63 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:41:26 +0100 Subject: [PATCH 28/53] Improve WiFi connection handling --- CO2_Gadget_Menu.h | 6 +++--- CO2_Gadget_WIFI.h | 12 +++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CO2_Gadget_Menu.h b/CO2_Gadget_Menu.h index 41a3af70..c951b0f3 100644 --- a/CO2_Gadget_Menu.h +++ b/CO2_Gadget_Menu.h @@ -1060,10 +1060,10 @@ result idle(menuOut &o, idleEvent e) { void menuLoop() { uint16_t timeToWaitForImprov = 5; // Time to wait for Improv-WiFi to connect on startup if (Serial.available() && Serial.peek() == 0x2A) { // 0x2A is the '*' character. - inMenu = true; - if (inMenu) { + // inMenu = true; + // if (inMenu) { nav.doInput(); // Do input, even if no display, as serial menu needs this - } + // } } if (millis() < timeInitializationCompleted + timeToWaitForImprov * 1000) { // Wait before starting the menu to avoid issues with Improv-WiFi diff --git a/CO2_Gadget_WIFI.h b/CO2_Gadget_WIFI.h index d38daa5d..9c5eacc7 100644 --- a/CO2_Gadget_WIFI.h +++ b/CO2_Gadget_WIFI.h @@ -713,9 +713,8 @@ void initWifi() { activeWIFI = false; } if (activeWIFI) { - wifiChanged = true; - if (!connectToWiFi()) { + wifiChanged = false; return; } @@ -729,6 +728,8 @@ void initWifi() { // Try to connect to MQTT broker on next loop if needed troubledMQTT = false; + + wifiChanged = true; } } @@ -745,9 +746,10 @@ void wifiClientLoop() { Serial.println("-->[WiFi] RSSI: " + String(WiFi.RSSI()) + " dBm"); wifiSSID = WiFi.SSID(); activeWIFI = true; - putPreferences(); - // initWifi(); - wifiChanged = true; + if (wifiSSID != "") { + putPreferences(); + wifiChanged = true; + } } if ((wifiChanged) && (!inMenu)) { From b0507e37839476a9346373e0793a4af67da9a804 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sat, 24 Feb 2024 21:44:03 +0100 Subject: [PATCH 29/53] Fix issue display won't turn on when on battery. Rename define TFT_BL to TFT_BACKLIGHT --- CO2_Gadget.ino | 2 +- CO2_Gadget_TFT.h | 16 ++++++++-------- platformio.ini | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CO2_Gadget.ino b/CO2_Gadget.ino index 7e5e1fc8..41abfbe9 100644 --- a/CO2_Gadget.ino +++ b/CO2_Gadget.ino @@ -154,7 +154,7 @@ uint16_t co2RedRange = 1000; #include #include -Stream& miSerialPort = Serial; +// Stream& miSerialPort = Serial; enum notificationTypes { notifyNothing, notifyInfo, diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index f8dcf3a7..1b29804d 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -194,7 +194,7 @@ void setDisplayBrightness(uint16_t newBrightness) { // Serial.printf("\n-->[TFT ] DisplayBrightness value at %d\n", DisplayBrightness); // Serial.printf("-->[TFT ] actualDisplayBrightness value at %d\n", actualDisplayBrightness); // Serial.printf("-->[TFT ] New display brightness value at %d\n", newBrightness); - analogWrite(TFT_BL, newBrightness); + analogWrite(TFT_BACKLIGHT, newBrightness); actualDisplayBrightness = newBrightness; } #endif @@ -204,16 +204,16 @@ void setDisplayBrightness(uint16_t newBrightness) { // Serial.printf("-->[TFT ] Old actualDisplayBrightness value at %d\n", actualDisplayBrightness); // Serial.printf("-->[TFT ] New actualDisplayBrightness value at %d\n", newBrightness); if (newBrightness == 0) { - digitalWrite(TFT_BL, LOW); + digitalWrite(TFT_BACKLIGHT, LOW); } else { - digitalWrite(TFT_BL, HIGH); + digitalWrite(TFT_BACKLIGHT, HIGH); } actualDisplayBrightness = newBrightness; } #endif #ifdef ST7789_240x320 if (actualDisplayBrightness != newBrightness) { - analogWrite(TFT_BL, newBrightness); + analogWrite(TFT_BACKLIGHT, newBrightness); actualDisplayBrightness = newBrightness; } #endif @@ -264,14 +264,14 @@ void displaySplashScreen() { void initBacklight() { #if defined(TTGO_TDISPLAY) || defined(ST7789_240x320) - pinMode(TFT_BL, OUTPUT); + pinMode(TFT_BACKLIGHT, OUTPUT); setDisplayBrightness(DisplayBrightness); #endif #ifdef TDISPLAY_S3 - pinMode(TFT_BL, OUTPUT); + pinMode(TFT_BACKLIGHT, OUTPUT); pinMode(TFT_POWER_ON_BATTERY, OUTPUT); - delay(50); - digitalWrite(TFT_BL, HIGH); + delay(20); + digitalWrite(TFT_BACKLIGHT, HIGH); digitalWrite(TFT_POWER_ON_BATTERY, HIGH); #endif } diff --git a/platformio.ini b/platformio.ini index ac791140..4a78c738 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"012"\" + -D CO2_GADGET_REV="\"013"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer @@ -135,7 +135,7 @@ build_flags = -DTFT_CS=5 -DTFT_DC=16 -DTFT_RST=23 - -DTFT_BL=4 + -DTFT_BACKLIGHT=4 -DTFT_BACKLIGHT_ON=HIGH -DLOAD_GLCD=1 -DLOAD_FONT2=1 @@ -185,7 +185,7 @@ build_flags = -DTFT_CS=5 -DTFT_DC=16 -DTFT_RST=23 - -DTFT_BL=4 + -DTFT_BACKLIGHT=4 -DTFT_BACKLIGHT_ON=HIGH -DLOAD_GLCD=1 -DLOAD_FONT2=1 @@ -282,7 +282,7 @@ build_flags = -DTFT_D5=46 -DTFT_D6=47 -DTFT_D7=48 - -DTFT_BL=38 + -DTFT_BACKLIGHT=38 -DTFT_POWER_ON_BATTERY=15 ; Pin must be high to power on display when on battery -DTFT_BACKLIGHT_ON=HIGH -DLOAD_GLCD @@ -335,7 +335,7 @@ build_flags = -DTFT_CS=5 -DTFT_DC=16 -DTFT_RST=-1 - -DTFT_BL=17 + -DTFT_BACKLIGHT=17 -DLOAD_GLCD=1 -DLOAD_FONT2=1 -DLOAD_FONT4=1 From 681947e70b27847dc991086a2c9bec7d60cdac06 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sat, 24 Feb 2024 21:53:58 +0100 Subject: [PATCH 30/53] Commented out code for publishing MQTT log data --- CO2_Gadget_MQTT.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CO2_Gadget_MQTT.h b/CO2_Gadget_MQTT.h index 6797cc6a..63c9ce2d 100644 --- a/CO2_Gadget_MQTT.h +++ b/CO2_Gadget_MQTT.h @@ -253,9 +253,9 @@ void initMQTT() { void publishMQTTLogData(String logData) { #ifdef SUPPORT_MQTT - if (activeMQTT && !troubledMQTT && !troubledWIFI && (WiFi.status() == WL_CONNECTED) && mqttClient.connected()) { - publishStrMQTT("/log", logData); - } + // if (activeMQTT && !troubledMQTT && !troubledWIFI && (WiFi.status() == WL_CONNECTED) && mqttClient.connected()) { + // publishStrMQTT("/log", logData); + // } #endif } From c658837e29610cc9216c78be3eb57d340adb8713 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sat, 24 Feb 2024 21:57:20 +0100 Subject: [PATCH 31/53] Commented out debug print statements in CO2_Gadget_Battery.h --- CO2_Gadget_Battery.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CO2_Gadget_Battery.h b/CO2_Gadget_Battery.h index 64efbc38..92fd48e0 100644 --- a/CO2_Gadget_Battery.h +++ b/CO2_Gadget_Battery.h @@ -29,7 +29,7 @@ Battery battery(batteryDischargedMillivolts, batteryFullyChargedMillivolts, ADC_ void initBattery() { battery.onDemand(battery.ON_DEMAND_DISABLE, LOW); battery.begin(vRef, voltageDividerRatio, &asigmoidal); - Serial.println("-->[BATT***] Battery initialized with vRef: " + String(vRef) + " and voltage divider ratio: " + String(voltageDividerRatio)); + // Serial.println("-->[BATT***] Battery initialized with vRef: " + String(vRef) + " and voltage divider ratio: " + String(voltageDividerRatio)); } void readBatteryVoltage() { @@ -71,7 +71,7 @@ void batteryLoop() { // Serial.printf("-->[BATT] Battery Level: %d%%. Battery voltage: %.4fV\n", batteryLevel, batteryVoltageNow); if (!inMenu) { if (abs(lastBatteryVoltage - batteryVoltage) >= 0.1) { // If battery voltage changed by at least 0.1V, update battery level - Serial.printf("-->[BATT] Battery Level: %d%%. Battery voltage changed from: %.4fV to %.4fV\n", batteryLevel, lastBatteryVoltage, batteryVoltage); + // Serial.printf("-->[BATT] Battery Level: %d%%. Battery voltage changed from: %.4fV to %.4fV\n", batteryLevel, lastBatteryVoltage, batteryVoltage); lastBatteryVoltage = batteryVoltage; } } From ab7f7e2264803126fe6390b37d783c1828c030e0 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sat, 24 Feb 2024 22:46:24 +0100 Subject: [PATCH 32/53] Version Beta v0.10.015 --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 33428dd4..4f37ae91 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"013"\" + -D CO2_GADGET_REV="\"014"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From 5cf0930a2fd6925540b3acb61a46c86674d4ebf4 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sun, 25 Feb 2024 08:31:55 +0100 Subject: [PATCH 33/53] Sync Version Beta v0.10.016 --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 4f37ae91..ef9f0e7a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"014"\" + -D CO2_GADGET_REV="\"016"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From 63d5f88c68c7b99c28b3c87e64f8a94d10337c70 Mon Sep 17 00:00:00 2001 From: Mariete Date: Sun, 25 Feb 2024 08:39:50 +0100 Subject: [PATCH 34/53] Update release3_beta.yml --- .github/workflows/release3_beta.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.github/workflows/release3_beta.yml b/.github/workflows/release3_beta.yml index 1aa5c186..7d38fa06 100644 --- a/.github/workflows/release3_beta.yml +++ b/.github/workflows/release3_beta.yml @@ -171,22 +171,6 @@ jobs: ls -la ./beta_firmware cp .pio/build/${{ matrix.environment }}/spiffs.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-spiffs.bin - - name: Create Beta Release - id: create_beta_release - uses: softprops/action-gh-release@v1 - with: - name: ${{ github.event.repository.name }}-${{ steps.get_version.outputs.VERSION }}-beta - files: | - ./beta_firmware/*.bin - ./beta_firmware/*.json - draft: false - prerelease: true - generate_release_notes: true - token: ${{ secrets.GITHUB_TOKEN }} - env: - CHIP_FAMILY: ${{ env.CHIP_FAMILY }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: 📂 Sync beta files - FTP-Deploy-Action uses: SamKirkland/FTP-Deploy-Action@2.0.0 env: From cf01ac0157521c9783379f2d7f7be3fcda931cb3 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sun, 25 Feb 2024 08:42:01 +0100 Subject: [PATCH 35/53] Sync Version Beta v0.10.017 --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index ef9f0e7a..95d7ece0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"016"\" + -D CO2_GADGET_REV="\"017"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From 30a5d886fbe39385cd64771323caa78ff7c4b07c Mon Sep 17 00:00:00 2001 From: Mariete Date: Sun, 25 Feb 2024 08:52:07 +0100 Subject: [PATCH 36/53] Update release3_beta.yml --- .github/workflows/release3_beta.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release3_beta.yml b/.github/workflows/release3_beta.yml index 7d38fa06..a8264bb2 100644 --- a/.github/workflows/release3_beta.yml +++ b/.github/workflows/release3_beta.yml @@ -19,9 +19,9 @@ jobs: environment: # - esp32dev # - esp32dev_OLED - # - TTGO_TDISPLAY + - TTGO_TDISPLAY - TTGO_TDISPLAY_SANDWICH - # - TDISPLAY_S3 + - TDISPLAY_S3 # - esp32dev_ST7789_240x320 env: From 86a5bba70d616fbf9a62c20dc549e7e7c2b81be0 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sun, 25 Feb 2024 08:57:19 +0100 Subject: [PATCH 37/53] Sync Version Beta v0.10.018 --- .github/workflows/release3_beta.yml | 4 ++++ platformio.ini | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release3_beta.yml b/.github/workflows/release3_beta.yml index a8264bb2..77af66a7 100644 --- a/.github/workflows/release3_beta.yml +++ b/.github/workflows/release3_beta.yml @@ -1,5 +1,9 @@ name: Beta Release V2.7 +# # # # # # # # # # # +# To create new Beta version and upload so web server, just commit with a message with the format "Beta v*.*.*" (Beta v1.0.1, Beta v1.1.12, Beta v2.1.123, etc) +# # # # # # # # # # # + on: push: branches: diff --git a/platformio.ini b/platformio.ini index 95d7ece0..144a1185 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"017"\" + -D CO2_GADGET_REV="\"018"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From 968e206537ddf1ecc7781f1a238aee8e55ec567a Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sun, 25 Feb 2024 08:59:13 +0100 Subject: [PATCH 38/53] Sync Version Beta v0.10.019 --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 144a1185..61bc5655 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"018"\" + -D CO2_GADGET_REV="\"019"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From 7f9e96c597c221f58ca50933ca68e1ad398d2b8e Mon Sep 17 00:00:00 2001 From: Mariete Date: Sun, 25 Feb 2024 09:01:18 +0100 Subject: [PATCH 39/53] Update release3_beta.yml --- .github/workflows/release3_beta.yml | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/.github/workflows/release3_beta.yml b/.github/workflows/release3_beta.yml index 77af66a7..d230b079 100644 --- a/.github/workflows/release3_beta.yml +++ b/.github/workflows/release3_beta.yml @@ -23,9 +23,9 @@ jobs: environment: # - esp32dev # - esp32dev_OLED - - TTGO_TDISPLAY + # - TTGO_TDISPLAY - TTGO_TDISPLAY_SANDWICH - - TDISPLAY_S3 + # - TDISPLAY_S3 # - esp32dev_ST7789_240x320 env: @@ -40,7 +40,6 @@ jobs: - name: Show environments run: | echo - - name: Determine chipFamily id: determine_chip_family run: | @@ -54,7 +53,6 @@ jobs: CHIP_FAMILY="UNKNOWN";; esac echo "::set-output name=chipFamily::${CHIP_FAMILY}" - - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v1 with: @@ -65,7 +63,6 @@ jobs: python -m pip install --upgrade pip pip install -U platformio platformio update - - name: Get the version id: get_version run: | @@ -79,19 +76,16 @@ jobs: echo "Commit message does not contain version information." exit 1 fi - - name: Create Git tag if: success() run: | git config user.name "GitHub Actions" git config user.email "<>" git tag -a "v${{ steps.get_version.outputs.VERSION }}-beta" -m "Beta Release v${{ steps.get_version.outputs.VERSION }}" - - name: Push Git tag if: success() run: | git push origin "v${{ steps.get_version.outputs.VERSION }}-beta" - - name: Show version run: echo ${{ steps.get_version.outputs.VERSION }} @@ -100,7 +94,6 @@ jobs: run: | echo "::set-output name=date::$(date +'%d-%m-%Y')" echo "::set-output name=time::$(date +'%H:%M:%S')" - - name: Create beta manifest file id: create_betamanifest run: | @@ -119,7 +112,6 @@ jobs: firmware_offset=65536 spiffs_offset=3997696 fi - # Create beta manifest echo "{" > ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo " \"name\": \"${{ github.event.repository.name }}-${{ matrix.environment }}\"," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json @@ -143,38 +135,31 @@ jobs: echo " ]" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo "}" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo "::set-output name=betamanifest::$(cat ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json)" - - name: Read beta manifest files run: | echo "Beta Manifest:" echo ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo "Beta Manifest file contents read with cat:" cat ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json - - name: Copy beta manifest files run: | mkdir ./beta_firmware cp ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json - - name: Build beta firmware file run: | pio run -e ${{ matrix.environment }} - - name: Copy beta firmware files run: | cp .pio/build/${{ matrix.environment }}/bootloader.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-bootloader.bin cp .pio/build/${{ matrix.environment }}/partitions.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-partitions.bin cp .pio/build/${{ matrix.environment }}/firmware.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-firmware.bin - - name: Build beta spiffs file run: | pio run -e ${{ matrix.environment }} -t buildfs - - name: Copy beta spiffs files run: | ls -la ./beta_firmware cp .pio/build/${{ matrix.environment }}/spiffs.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-spiffs.bin - - name: 📂 Sync beta files - FTP-Deploy-Action uses: SamKirkland/FTP-Deploy-Action@2.0.0 env: @@ -190,4 +175,4 @@ jobs: - name: Clean eMariete.com Cache # run: curl https://emariete.com/clean_cache_wp_rocket.php run: curl https://emariete.com/clean_cache_litespeed.php - + From 272a8a5eeb78a7237b981117835e359b431a2c69 Mon Sep 17 00:00:00 2001 From: Mariete Date: Sun, 25 Feb 2024 09:01:46 +0100 Subject: [PATCH 40/53] Update release3_beta.yml --- .github/workflows/release3_beta.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release3_beta.yml b/.github/workflows/release3_beta.yml index d230b079..2c21256d 100644 --- a/.github/workflows/release3_beta.yml +++ b/.github/workflows/release3_beta.yml @@ -23,9 +23,9 @@ jobs: environment: # - esp32dev # - esp32dev_OLED - # - TTGO_TDISPLAY + - TTGO_TDISPLAY - TTGO_TDISPLAY_SANDWICH - # - TDISPLAY_S3 + - TDISPLAY_S3 # - esp32dev_ST7789_240x320 env: From 85482041854831306beeb12570076c1cdfb5c343 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sun, 25 Feb 2024 09:02:06 +0100 Subject: [PATCH 41/53] Sync Version Beta v0.10.020 --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 61bc5655..31d42bc2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"019"\" + -D CO2_GADGET_REV="\"020"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From 0f711a498918086319a666d964c989cf4d840757 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sun, 25 Feb 2024 09:03:35 +0100 Subject: [PATCH 42/53] Sync Version Beta v0.10.021 --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 31d42bc2..12f05a1b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"020"\" + -D CO2_GADGET_REV="\"021"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From 6ed4d9d43a9d1b9972a3a9ed6cb3254d7c856a20 Mon Sep 17 00:00:00 2001 From: Mariete Date: Sun, 25 Feb 2024 09:10:41 +0100 Subject: [PATCH 43/53] Update release3_beta.yml --- .github/workflows/release3_beta.yml | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release3_beta.yml b/.github/workflows/release3_beta.yml index 2c21256d..292815b3 100644 --- a/.github/workflows/release3_beta.yml +++ b/.github/workflows/release3_beta.yml @@ -1,4 +1,4 @@ -name: Beta Release V2.7 +name: Beta Release V2.8 # # # # # # # # # # # # To create new Beta version and upload so web server, just commit with a message with the format "Beta v*.*.*" (Beta v1.0.1, Beta v1.1.12, Beta v2.1.123, etc) @@ -40,6 +40,7 @@ jobs: - name: Show environments run: | echo + - name: Determine chipFamily id: determine_chip_family run: | @@ -53,6 +54,7 @@ jobs: CHIP_FAMILY="UNKNOWN";; esac echo "::set-output name=chipFamily::${CHIP_FAMILY}" + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v1 with: @@ -63,6 +65,7 @@ jobs: python -m pip install --upgrade pip pip install -U platformio platformio update + - name: Get the version id: get_version run: | @@ -76,16 +79,7 @@ jobs: echo "Commit message does not contain version information." exit 1 fi - - name: Create Git tag - if: success() - run: | - git config user.name "GitHub Actions" - git config user.email "<>" - git tag -a "v${{ steps.get_version.outputs.VERSION }}-beta" -m "Beta Release v${{ steps.get_version.outputs.VERSION }}" - - name: Push Git tag - if: success() - run: | - git push origin "v${{ steps.get_version.outputs.VERSION }}-beta" + - name: Show version run: echo ${{ steps.get_version.outputs.VERSION }} @@ -94,6 +88,7 @@ jobs: run: | echo "::set-output name=date::$(date +'%d-%m-%Y')" echo "::set-output name=time::$(date +'%H:%M:%S')" + - name: Create beta manifest file id: create_betamanifest run: | @@ -112,6 +107,7 @@ jobs: firmware_offset=65536 spiffs_offset=3997696 fi + # Create beta manifest echo "{" > ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo " \"name\": \"${{ github.event.repository.name }}-${{ matrix.environment }}\"," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json @@ -135,31 +131,38 @@ jobs: echo " ]" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo "}" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo "::set-output name=betamanifest::$(cat ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json)" + - name: Read beta manifest files run: | echo "Beta Manifest:" echo ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo "Beta Manifest file contents read with cat:" cat ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + - name: Copy beta manifest files run: | mkdir ./beta_firmware cp ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + - name: Build beta firmware file run: | pio run -e ${{ matrix.environment }} + - name: Copy beta firmware files run: | cp .pio/build/${{ matrix.environment }}/bootloader.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-bootloader.bin cp .pio/build/${{ matrix.environment }}/partitions.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-partitions.bin cp .pio/build/${{ matrix.environment }}/firmware.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-firmware.bin + - name: Build beta spiffs file run: | pio run -e ${{ matrix.environment }} -t buildfs + - name: Copy beta spiffs files run: | ls -la ./beta_firmware cp .pio/build/${{ matrix.environment }}/spiffs.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-spiffs.bin + - name: 📂 Sync beta files - FTP-Deploy-Action uses: SamKirkland/FTP-Deploy-Action@2.0.0 env: @@ -175,4 +178,3 @@ jobs: - name: Clean eMariete.com Cache # run: curl https://emariete.com/clean_cache_wp_rocket.php run: curl https://emariete.com/clean_cache_litespeed.php - From c3be45830054f8d50001c082afab62997ca84638 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sun, 25 Feb 2024 09:11:44 +0100 Subject: [PATCH 44/53] Sync Version Beta v0.10.022 --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 12f05a1b..bf4b8ca4 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"021"\" + -D CO2_GADGET_REV="\"022"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From f6d952f63e78b873c148fc0fa228304d5db213ea Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sun, 25 Feb 2024 10:01:32 +0100 Subject: [PATCH 45/53] Do not show ESPNOW icon if ESPNOW is not supported (in platformio.ini) --- CO2_Gadget_TFT.h | 2 ++ platformio.ini | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index 2ddc10a3..36a62f6c 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -487,12 +487,14 @@ void showMQTTIcon(int32_t posX, int32_t posY) { } void showEspNowIcon(int32_t posX, int32_t posY) { + #ifdef SUPPORT_ESPNOW tft.drawRoundRect(posX - 2, posY - 2, 16 + 4, 16 + 4, 2, TFT_DARKGREY); if (!activeESPNOW) { tft.drawBitmap(posX, posY, iconEspNow, 16, 16, TFT_BLACK, TFT_DARKGREY); } else { tft.drawBitmap(posX, posY, iconEspNow, 16, 16, TFT_BLACK, iconDefaultColor); } + #endif } void showTemperatureIcon(int32_t posX, int32_t posY) { diff --git a/platformio.ini b/platformio.ini index bf4b8ca4..5e83b2cf 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"022"\" + -D CO2_GADGET_REV="\"023"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer @@ -70,7 +70,7 @@ build_flags = -DSUPPORT_BLE ; Comment to dissable Bluetooth (makes more memory available) -DSUPPORT_BUZZER ; -DSUPPORT_ESPNOW - -USUPPORT_OTA ; + -DSUPPORT_OTA ; -DSUPPORT_MDNS ; -DSUPPORT_MQTT ; -DSUPPORT_MQTT_DISCOVERY From 9703c94dac45f3e2b93b7090130ff9fae6ef3c12 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sun, 25 Feb 2024 12:19:42 +0100 Subject: [PATCH 46/53] Show USB icon instead of battery level if connected to external power --- CO2_Gadget_TFT.h | 40 +++++++++++++++++++++++----------------- icons.h | 7 +++++++ platformio.ini | 2 +- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index 36a62f6c..8150b435 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -124,15 +124,15 @@ void setElementLocations() { elementPosition.humidityX = displayWidth - 60; elementPosition.humidityY = displayHeight - 25; elementPosition.batteryIconX = displayWidth - 36; - elementPosition.batteryIconY = 4; + elementPosition.batteryIconY = 2; elementPosition.batteryVoltageX = displayWidth - 92; elementPosition.batteryVoltageY = 2; elementPosition.bleIconX = 2; - elementPosition.bleIconY = 1; + elementPosition.bleIconY = 2; elementPosition.wifiIconX = 26; - elementPosition.wifiIconY = 1; + elementPosition.wifiIconY = 2; elementPosition.mqttIconX = 50; - elementPosition.mqttIconY = 1; + elementPosition.mqttIconY = 2; elementPosition.espNowIconX = 74; elementPosition.espNowIconY = 1; } @@ -149,7 +149,7 @@ void setElementLocations() { elementPosition.humidityX = displayWidth - 60; elementPosition.humidityY = displayHeight - 25; elementPosition.batteryIconX = displayWidth - 36; - elementPosition.batteryIconY = 4; + elementPosition.batteryIconY = 2; elementPosition.batteryVoltageX = displayWidth - 92; elementPosition.batteryVoltageY = 2; elementPosition.bleIconX = 2; @@ -174,7 +174,7 @@ void setElementLocations() { elementPosition.humidityX = displayWidth - 60; elementPosition.humidityY = displayHeight - 25; elementPosition.batteryIconX = displayWidth - 36; - elementPosition.batteryIconY = 4; + elementPosition.batteryIconY = 2; elementPosition.batteryVoltageX = displayWidth - 92; elementPosition.batteryVoltageY = 2; elementPosition.bleIconX = 2; @@ -395,22 +395,28 @@ void showBatteryIcon(int32_t posX, int32_t posY) { // For TTGO T-Display posX=t color = iconDefaultColor; } - if (spr.createSprite(34, 14) == nullptr) { + if (spr.createSprite(34, 20) == nullptr) { Serial.printf("-->[TFT ] Error: sprite not created, not enough free RAM! Free RAM: %d\n", ESP.getFreeHeap()); spr.deleteSprite(); return; } - publishMQTTLogData("Battery Level: " + String(batteryLevel) + "% Battery voltage: " + String(batteryVoltage) + "V"); + publishMQTTLogData("-->[TFT ] Battery Level: " + String(batteryLevel) + "% Battery voltage: " + String(batteryVoltage) + "V"); spr.fillSprite(TFT_BLACK); - spr.drawRoundRect(0, 0, 32, 14, 2, color); // Battery outter rectangle - spr.drawLine(33, 4, 33, 10, color); - if (batteryLevel > 20) spr.fillRect(4, 2, 4, 10, color); - if (batteryLevel > 40) spr.fillRect(11, 2, 4, 10, color); - if (batteryLevel > 60) spr.fillRect(18, 2, 4, 10, color); - if (batteryLevel > 80) spr.fillRect(25, 2, 4, 10, color); + if (workingOnExternalPower) { + spr.drawRoundRect(12, 0, 16 + 4, 16 + 4, 2, TFT_DARKGREY); + spr.setSwapBytes(true); + spr.drawBitmap(14, 2, iconUSB, 16, 16, TFT_BLACK, iconDefaultColor); + } else { + spr.drawRoundRect(0, 0, 32, 14, 2, color); // Battery outter rectangle + spr.drawLine(33, 4, 33, 10, color); + if (batteryLevel > 20) spr.fillRect(4, 2, 4, 10, color); + if (batteryLevel > 40) spr.fillRect(11, 2, 4, 10, color); + if (batteryLevel > 60) spr.fillRect(18, 2, 4, 10, color); + if (batteryLevel > 80) spr.fillRect(25, 2, 4, 10, color); + } spr.pushSprite(posX, posY); spr.deleteSprite(); @@ -487,14 +493,14 @@ void showMQTTIcon(int32_t posX, int32_t posY) { } void showEspNowIcon(int32_t posX, int32_t posY) { - #ifdef SUPPORT_ESPNOW +#ifdef SUPPORT_ESPNOW tft.drawRoundRect(posX - 2, posY - 2, 16 + 4, 16 + 4, 2, TFT_DARKGREY); if (!activeESPNOW) { tft.drawBitmap(posX, posY, iconEspNow, 16, 16, TFT_BLACK, TFT_DARKGREY); } else { tft.drawBitmap(posX, posY, iconEspNow, 16, 16, TFT_BLACK, iconDefaultColor); } - #endif +#endif } void showTemperatureIcon(int32_t posX, int32_t posY) { @@ -631,7 +637,7 @@ void displayShowValues() { showTemperature(temp, elementPosition.tempX, elementPosition.tempY); showHumidity(hum, elementPosition.humidityX, elementPosition.humidityY); showBatteryIcon(elementPosition.batteryIconX, elementPosition.batteryIconY); - showBatteryVoltage(elementPosition.batteryVoltageX, elementPosition.batteryVoltageY); + // showBatteryVoltage(elementPosition.batteryVoltageX, elementPosition.batteryVoltageY); showWiFiIcon(elementPosition.wifiIconX, elementPosition.wifiIconY); showMQTTIcon(elementPosition.mqttIconX, elementPosition.mqttIconY); showBLEIcon(elementPosition.bleIconX, elementPosition.bleIconY); diff --git a/icons.h b/icons.h index 018f32e2..56bbcab1 100644 --- a/icons.h +++ b/icons.h @@ -1,3 +1,5 @@ +// https://sourceforge.net/projects/lcd-image-converter/ +// https://notisrac.github.io/FileToCArray/ Drag and drop file on "Choose file..." button. Tick box "Treat as binary". Click "Convert". Click "Save as file" and move the header file to sketch folder. Open the sketch in IDE. Include the header file containing the array. // https://iconarchive.com/show/farm-fresh-icons-by-fatcow/temperature-5-icon.html // https://www.flaticon.com/search?word=bluetooth&order_by=4&type=icon @@ -44,6 +46,11 @@ const unsigned char iconEspNow[32] PROGMEM = { 0xff, 0xff, 0xff, 0xff, 0xc0, 0x03, 0xc0, 0x03, 0xe6, 0x67, 0xe2, 0x47, 0xf0, 0x0f, 0xf8, 0x1f, 0xfc, 0x3f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff}; +// 'iconUSB', 16x16px +static unsigned char iconUSB[32] PROGMEM = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfc, 0x1f, 0xfd, 0xbf, 0x9b, 0xff, 0x03, 0x41, + 0x04, 0x00, 0x9e, 0xff, 0xfe, 0x4f, 0xff, 0x07, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; + // 'iconHumidity', 16x16px const uint16_t iconHumidity[256] PROGMEM = { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xc79f, 0xc79f, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, diff --git a/platformio.ini b/platformio.ini index 5e83b2cf..f8892088 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"023"\" + -D CO2_GADGET_REV="\"024"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From 0fa1d4776544defaa311632171419383edf684c9 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sun, 25 Feb 2024 13:28:54 +0100 Subject: [PATCH 47/53] Add displayShowBatteryVoltage option and web server settings endpoint Adjust icon possitions --- CO2_Gadget.ino | 1 + CO2_Gadget_Preferences.h | 5 +++++ CO2_Gadget_TFT.h | 46 +++++++++++----------------------------- CO2_Gadget_WIFI.h | 24 ++++++++++++++++----- platformio.ini | 2 +- 5 files changed, 38 insertions(+), 40 deletions(-) diff --git a/CO2_Gadget.ino b/CO2_Gadget.ino index 41abfbe9..00a01786 100644 --- a/CO2_Gadget.ino +++ b/CO2_Gadget.ino @@ -71,6 +71,7 @@ bool showFahrenheit = false; bool displayShowTemperature = true; bool displayShowHumidity = true; bool displayShowBattery = true; +bool displayShowBatteryVoltage = false; bool displayShowCO2 = true; bool displayShowPM25 = true; bool debugSensors = false; diff --git a/CO2_Gadget_Preferences.h b/CO2_Gadget_Preferences.h index 1be7cfc3..f17307f2 100644 --- a/CO2_Gadget_Preferences.h +++ b/CO2_Gadget_Preferences.h @@ -62,6 +62,7 @@ void printPreferences() { Serial.printf("-->[PREF] showTemp:\t #%s#\n", ((displayShowTemperature) ? "Show" : "Hide")); Serial.printf("-->[PREF] showHumidity:\t #%s#\n", ((displayShowHumidity) ? "Show" : "Hide")); Serial.printf("-->[PREF] showBattery:\t #%s#\n", ((displayShowBattery) ? "Show" : "Hide")); + Serial.printf("-->[PREF] showBatteryVolt:\t #%s#\n", ((displayShowBatteryVoltage) ? "Show" : "Hide")); Serial.printf("-->[PREF] showCO2:\t #%s#\n", ((displayShowCO2) ? "Show" : "Hide")); Serial.printf("-->[PREF] showPM25:\t #%s#\n", ((displayShowPM25) ? "Show" : "Hide")); @@ -154,6 +155,7 @@ void initPreferences() { displayShowTemperature = preferences.getBool("showTemp", true); displayShowHumidity = preferences.getBool("showHumidity", true); displayShowBattery = preferences.getBool("showBattery", true); + displayShowBatteryVoltage = preferences.getBool("showBattVolt", false); displayShowCO2 = preferences.getBool("showCO2", true); displayShowPM25 = preferences.getBool("showPM25", true); @@ -234,6 +236,7 @@ void putPreferences() { preferences.putBool("showTemp", displayShowTemperature); preferences.putBool("showHumidity", displayShowHumidity); preferences.putBool("showBattery", displayShowBattery); + preferences.putBool("showBattVolt", displayShowBatteryVoltage); preferences.putBool("showCO2", displayShowCO2); preferences.putBool("showPM25", displayShowPM25); @@ -369,6 +372,7 @@ String getActualSettingsAsJson() { doc["showTemp"] = displayShowTemperature; doc["showHumidity"] = displayShowHumidity; doc["showBattery"] = displayShowBattery; + doc["showBattVolt"] = displayShowBatteryVoltage; doc["showCO2"] = displayShowCO2; doc["showPM25"] = displayShowPM25; doc["measInterval"] = measurementInterval; @@ -464,6 +468,7 @@ bool handleSavePreferencesfromJSON(String jsonPreferences) { displayShowTemperature = JsonDocument["showTemp"]; displayShowHumidity = JsonDocument["showHumidity"]; displayShowBattery = JsonDocument["showBattery"]; + displayShowBatteryVoltage = JsonDocument["showBattVolt"]; displayShowCO2 = JsonDocument["showCO2"]; displayShowPM25 = JsonDocument["showPM25"]; diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index 8150b435..58af26a7 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -123,7 +123,7 @@ void setElementLocations() { elementPosition.tempY = displayHeight - 25; elementPosition.humidityX = displayWidth - 60; elementPosition.humidityY = displayHeight - 25; - elementPosition.batteryIconX = displayWidth - 36; + elementPosition.batteryIconX = displayWidth - 34; elementPosition.batteryIconY = 2; elementPosition.batteryVoltageX = displayWidth - 92; elementPosition.batteryVoltageY = 2; @@ -148,7 +148,7 @@ void setElementLocations() { elementPosition.tempY = displayHeight - 25; elementPosition.humidityX = displayWidth - 60; elementPosition.humidityY = displayHeight - 25; - elementPosition.batteryIconX = displayWidth - 36; + elementPosition.batteryIconX = displayWidth - 34; elementPosition.batteryIconY = 2; elementPosition.batteryVoltageX = displayWidth - 92; elementPosition.batteryVoltageY = 2; @@ -173,7 +173,7 @@ void setElementLocations() { elementPosition.tempY = displayHeight - 25; elementPosition.humidityX = displayWidth - 60; elementPosition.humidityY = displayHeight - 25; - elementPosition.batteryIconX = displayWidth - 36; + elementPosition.batteryIconX = displayWidth - 34; elementPosition.batteryIconY = 2; elementPosition.batteryVoltageX = displayWidth - 92; elementPosition.batteryVoltageY = 2; @@ -371,7 +371,7 @@ uint16_t getBatteryColor(float batteryVoltage) { } void showBatteryVoltage(int32_t posX, int32_t posY) { - if ((!displayShowBattery) || (batteryVoltage < 1)) return; + if ((!displayShowBatteryVoltage) || (!displayShowBattery) || (batteryVoltage < 1)) return; String batteryVoltageString = " " + String(batteryVoltage, 1) + "V "; tft.setTextDatum(TL_DATUM); tft.setCursor(posX, posY); @@ -410,41 +410,19 @@ void showBatteryIcon(int32_t posX, int32_t posY) { // For TTGO T-Display posX=t spr.setSwapBytes(true); spr.drawBitmap(14, 2, iconUSB, 16, 16, TFT_BLACK, iconDefaultColor); } else { - spr.drawRoundRect(0, 0, 32, 14, 2, color); // Battery outter rectangle - spr.drawLine(33, 4, 33, 10, color); - if (batteryLevel > 20) spr.fillRect(4, 2, 4, 10, color); - if (batteryLevel > 40) spr.fillRect(11, 2, 4, 10, color); - if (batteryLevel > 60) spr.fillRect(18, 2, 4, 10, color); - if (batteryLevel > 80) spr.fillRect(25, 2, 4, 10, color); + uint32_t upperLine = 4; + spr.drawRoundRect(0, upperLine, 32, 14, 2, color); // Battery outter rectangle + spr.drawLine(33, upperLine + 4, 33, upperLine + 10, color); + if (batteryLevel > 20) spr.fillRect(4, upperLine + 2, 4, 10, color); + if (batteryLevel > 40) spr.fillRect(11, upperLine + 2, 4, 10, color); + if (batteryLevel > 60) spr.fillRect(18, upperLine + 2, 4, 10, color); + if (batteryLevel > 80) spr.fillRect(25, upperLine + 2, 4, 10, color); } spr.pushSprite(posX, posY); spr.deleteSprite(); } -void showBatteryIconOLD(int32_t posX, int32_t posY) { // For TTGO T-Display posX=tft.width() - 32, posY=4 - uint16_t color; - if ((!displayShowBattery) || (batteryVoltage < 1)) return; - - if (batteryLevel < 20) { - color = TFT_RED; - } else { - color = TFT_SILVER; - } - - if (batteryVoltage > 4.5) { // Charging... - color = iconDefaultColor; - } - - tft.drawRoundRect(posX, posY, 32, 14, 2, color); // Battery outter rectangle - tft.drawLine(posX + 33, posY + 4, posX + 33, posY + 10, color); - - if (batteryLevel > 20) tft.fillRect(posX + 4, posY + 2, 4, 10, color); - if (batteryLevel > 40) tft.fillRect(posX + 11, posY + 2, 4, 10, color); - if (batteryLevel > 60) tft.fillRect(posX + 18, posY + 2, 4, 10, color); - if (batteryLevel > 80) tft.fillRect(posX + 25, posY + 2, 4, 10, color); -} - void showWiFiIcon(int32_t posX, int32_t posY) { int8_t rssi = WiFi.RSSI(); if (troubledWIFI) { @@ -637,7 +615,7 @@ void displayShowValues() { showTemperature(temp, elementPosition.tempX, elementPosition.tempY); showHumidity(hum, elementPosition.humidityX, elementPosition.humidityY); showBatteryIcon(elementPosition.batteryIconX, elementPosition.batteryIconY); - // showBatteryVoltage(elementPosition.batteryVoltageX, elementPosition.batteryVoltageY); + showBatteryVoltage(elementPosition.batteryVoltageX, elementPosition.batteryVoltageY); showWiFiIcon(elementPosition.wifiIconX, elementPosition.wifiIconY); showMQTTIcon(elementPosition.mqttIconX, elementPosition.mqttIconY); showBLEIcon(elementPosition.bleIconX, elementPosition.bleIconY); diff --git a/CO2_Gadget_WIFI.h b/CO2_Gadget_WIFI.h index 9c5eacc7..1e5bb504 100644 --- a/CO2_Gadget_WIFI.h +++ b/CO2_Gadget_WIFI.h @@ -560,17 +560,19 @@ void initWebServer() { server.on("/settings", HTTP_GET, [](AsyncWebServerRequest *request) { String inputString; // /settings?MeasurementInterval=100 - if (request->hasParam(PARAM_INPUT_1)) { - inputString = request->getParam(PARAM_INPUT_1)->value(); + if (request->hasParam("MeasurementInterval")) { + inputString = request->getParam("MeasurementInterval")->value(); if (checkStringIsNumerical(inputString)) { Serial.printf("-->[WiFi] Received /settings command MeasurementInterval with parameter %s\n", inputString); measurementInterval = inputString.toInt(); request->send(200, "text/plain", "OK. Setting MeasurementInterval to " + inputString + ", please re-calibrate your sensor."); + } else { + request->send(400, "text/plain", "Error. MeasurementInterval must have a number as parameter."); } }; // /settings?CalibrateCO2=400 - if (request->hasParam(PARAM_INPUT_2)) { - inputString = request->getParam(PARAM_INPUT_2)->value(); + if (request->hasParam("CalibrateCO2")) { + inputString = request->getParam("CalibrateCO2")->value(); if (checkStringIsNumerical(inputString)) { Serial.printf("-->[WiFi] Received /settings command CalibrateCO2 with parameter %s\n", inputString); if ((inputString.toInt() >= 400) && (inputString.toInt() <= 2000)) { @@ -578,10 +580,22 @@ void initWebServer() { pendingCalibration = true; request->send(200, "text/plain", "OK. Recalibrating CO2 sensor to " + inputString); } else { - request->send(200, "text/plain", "Error. CO2 calibration value must be between 400 and 2000"); + request->send(400, "text/plain", "Error. CO2 calibration value must be between 400 and 2000"); } } }; + // /settings?displayShowBatteryVoltage=true + if (request->hasParam("displayShowBatteryVoltage")) { + String inputString = request->getParam("displayShowBatteryVoltage")->value(); + if (inputString.equalsIgnoreCase("true") || inputString.equalsIgnoreCase("false")) { + bool newValue = inputString.equalsIgnoreCase("true"); + displayShowBatteryVoltage = newValue; + Serial.printf("-->[WiFi] Received /settings command displayShowBatteryVoltage with parameter: %s\n", newValue ? "true" : "false"); + request->send(200, "text/plain", "OK. Setting displayShowBatteryVoltage to " + inputString); + } else { + request->send(400, "text/plain", "Error. Invalid parameter. Use 'true' or 'false'"); + } + } }); server.on("/getPreferences", HTTP_GET, [](AsyncWebServerRequest *request) { diff --git a/platformio.ini b/platformio.ini index f8892088..cf85f144 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"024"\" + -D CO2_GADGET_REV="\"025"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From bc25589793a8a05238870f4320ef2aa999035000 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sun, 25 Feb 2024 13:32:07 +0100 Subject: [PATCH 48/53] Beta v0.10.26 General fixes and improvements --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index cf85f144..d285e27e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"025"\" + -D CO2_GADGET_REV="\"026"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From f6c897d914e1191fb4ea2fd92b84fc8178f015eb Mon Sep 17 00:00:00 2001 From: Mariete Date: Sun, 25 Feb 2024 13:45:43 +0100 Subject: [PATCH 49/53] Update release3_beta.yml --- .github/workflows/release3_beta.yml | 60 +++++++++++++++-------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/.github/workflows/release3_beta.yml b/.github/workflows/release3_beta.yml index 292815b3..7fb2c07f 100644 --- a/.github/workflows/release3_beta.yml +++ b/.github/workflows/release3_beta.yml @@ -1,4 +1,4 @@ -name: Beta Release V2.8 +name: Beta Release V2.9 # # # # # # # # # # # # To create new Beta version and upload so web server, just commit with a message with the format "Beta v*.*.*" (Beta v1.0.1, Beta v1.1.12, Beta v2.1.123, etc) @@ -40,6 +40,20 @@ jobs: - name: Show environments run: | echo + + + - name: Check if version exists + id: check_version + run: | + commit_message=$(git log --format=%B -n 1 $GITHUB_SHA) + version_regex="Beta v([0-9]+\.[0-9]+\.[0-9]+)" + if [[ $commit_message =~ $version_regex ]]; then + echo "Version found: ${BASH_REMATCH[1]}" + echo "::set-output name=VERSION::${BASH_REMATCH[1]}" + else + echo "No valid version found in commit message. Exiting..." + exit 1 + fi - name: Determine chipFamily id: determine_chip_family @@ -61,28 +75,12 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies + if: steps.check_version.outputs.VERSION != '' run: | python -m pip install --upgrade pip pip install -U platformio platformio update - - name: Get the version - id: get_version - run: | - # Get the version from the commit message - commit_message=$(git log --format=%B -n 1 $GITHUB_SHA) - version_regex="Beta v([0-9]+\.[0-9]+\.[0-9]+)" - if [[ $commit_message =~ $version_regex ]]; then - version=${BASH_REMATCH[1]} - echo "::set-output name=VERSION::${version}" - else - echo "Commit message does not contain version information." - exit 1 - fi - - - name: Show version - run: echo ${{ steps.get_version.outputs.VERSION }} - - name: Get current date id: date run: | @@ -90,6 +88,7 @@ jobs: echo "::set-output name=time::$(date +'%H:%M:%S')" - name: Create beta manifest file + if: steps.check_version.outputs.VERSION != '' id: create_betamanifest run: | # Define offset values based on env.CHIP_FAMILY @@ -112,7 +111,7 @@ jobs: echo "{" > ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo " \"name\": \"${{ github.event.repository.name }}-${{ matrix.environment }}\"," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo " \"flavour\": \"${{ matrix.environment }}\"," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json - echo " \"version\": \"${{ steps.get_version.outputs.VERSION }}-beta\"," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " \"version\": \"${{ steps.check_version.outputs.VERSION }}-beta\"," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo " \"compilation_date\": \"${{ steps.date.outputs.date }}\"," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo " \"compilation_time\": \"${{ steps.date.outputs.time }}\"," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo " \"new_install_prompt_erase\": true," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json @@ -122,10 +121,10 @@ jobs: echo " \"chipFamily\": \"${{ env.CHIP_FAMILY }}\"," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo " \"improv\": true," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo " \"parts\": [" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json - echo " { \"path\": \"${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-bootloader.bin\", \"offset\": $bootloader_offset }," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json - echo " { \"path\": \"${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-partitions.bin\", \"offset\": $partitions_offset }," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json - echo " { \"path\": \"${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-firmware.bin\", \"offset\": $firmware_offset }," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json - echo " { \"path\": \"${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-spiffs.bin\", \"offset\": $spiffs_offset }" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " { \"path\": \"${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.check_version.outputs.VERSION }}-bootloader.bin\", \"offset\": $bootloader_offset }," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " { \"path\": \"${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.check_version.outputs.VERSION }}-partitions.bin\", \"offset\": $partitions_offset }," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " { \"path\": \"${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.check_version.outputs.VERSION }}-firmware.bin\", \"offset\": $firmware_offset }," >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json + echo " { \"path\": \"${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.check_version.outputs.VERSION }}-spiffs.bin\", \"offset\": $spiffs_offset }" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo " ]" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo " }" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json echo " ]" >> ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json @@ -145,25 +144,30 @@ jobs: cp ${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}.beta.manifest.json - name: Build beta firmware file + if: steps.check_version.outputs.VERSION != '' run: | pio run -e ${{ matrix.environment }} - name: Copy beta firmware files + if: steps.check_version.outputs.VERSION != '' run: | - cp .pio/build/${{ matrix.environment }}/bootloader.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-bootloader.bin - cp .pio/build/${{ matrix.environment }}/partitions.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-partitions.bin - cp .pio/build/${{ matrix.environment }}/firmware.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-firmware.bin + cp .pio/build/${{ matrix.environment }}/bootloader.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.check_version.outputs.VERSION }}-bootloader.bin + cp .pio/build/${{ matrix.environment }}/partitions.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.check_version.outputs.VERSION }}-partitions.bin + cp .pio/build/${{ matrix.environment }}/firmware.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.check_version.outputs.VERSION }}-firmware.bin - name: Build beta spiffs file + if: steps.check_version.outputs.VERSION != '' run: | pio run -e ${{ matrix.environment }} -t buildfs - name: Copy beta spiffs files + if: steps.check_version.outputs.VERSION != '' run: | ls -la ./beta_firmware - cp .pio/build/${{ matrix.environment }}/spiffs.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.get_version.outputs.VERSION }}-spiffs.bin + cp .pio/build/${{ matrix.environment }}/spiffs.bin ./beta_firmware/${{ github.event.repository.name }}-${{ matrix.environment }}-${{ steps.check_version.outputs.VERSION }}-spiffs.bin - name: 📂 Sync beta files - FTP-Deploy-Action + if: steps.check_version.outputs.VERSION != '' uses: SamKirkland/FTP-Deploy-Action@2.0.0 env: FTP_SERVER: ${{ secrets.FTP_SERVER }} @@ -176,5 +180,5 @@ jobs: ARGS: --verbose - name: Clean eMariete.com Cache - # run: curl https://emariete.com/clean_cache_wp_rocket.php + if: steps.check_version.outputs.VERSION != '' run: curl https://emariete.com/clean_cache_litespeed.php From d0c8029bae69844a11aca41a7d0ee2cffb732668 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sun, 25 Feb 2024 14:25:53 +0100 Subject: [PATCH 50/53] Add make rounding box around icons red on trouble --- CO2_Gadget.ino | 1 + CO2_Gadget_TFT.h | 9 +++++++-- platformio.ini | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CO2_Gadget.ino b/CO2_Gadget.ino index 00a01786..f0f5dfeb 100644 --- a/CO2_Gadget.ino +++ b/CO2_Gadget.ino @@ -55,6 +55,7 @@ bool activeESPNOW = false; bool activeOTA = false; bool troubledWIFI = false; // There are problems connecting to WIFI. Temporary suspend WIFI bool troubledMQTT = false; // There are problems connecting to MQTT. Temporary suspend MQTT +bool troubledESPNOW = false; // There are problems connecting to ESP-NOW. Temporary suspend ESP-NOW uint64_t timeTroubledWIFI = 0; // Time since WIFI is troubled uint64_t timeTroubledMQTT = 0; // Time since MQTT is troubled uint64_t timeToRetryTroubledWIFI = 300; // Time in seconds to retry WIFI connection after it is troubled diff --git a/CO2_Gadget_TFT.h b/CO2_Gadget_TFT.h index 58af26a7..1c1efd2d 100644 --- a/CO2_Gadget_TFT.h +++ b/CO2_Gadget_TFT.h @@ -427,7 +427,7 @@ void showWiFiIcon(int32_t posX, int32_t posY) { int8_t rssi = WiFi.RSSI(); if (troubledWIFI) { tft.drawRoundRect(posX - 2, posY - 2, 16 + 4, 16 + 4, 2, TFT_RED); - tft.drawBitmap(posX, posY, iconWiFi, 16, 16, TFT_BLACK, TFT_RED); + tft.drawBitmap(posX, posY, iconWiFi, 16, 16, TFT_BLACK, iconDefaultColor); return; } tft.drawRoundRect(posX - 2, posY - 2, 16 + 4, 16 + 4, 2, TFT_DARKGREY); @@ -459,7 +459,7 @@ void showBLEIcon(int32_t posX, int32_t posY) { void showMQTTIcon(int32_t posX, int32_t posY) { if (troubledMQTT) { tft.drawRoundRect(posX - 2, posY - 2, 16 + 4, 16 + 4, 2, TFT_RED); - tft.drawBitmap(posX, posY, iconMQTT, 16, 16, TFT_BLACK, TFT_RED); + tft.drawBitmap(posX, posY, iconMQTT, 16, 16, TFT_BLACK, iconDefaultColor); return; } tft.drawRoundRect(posX - 2, posY - 2, 16 + 4, 16 + 4, 2, TFT_DARKGREY); @@ -472,6 +472,11 @@ void showMQTTIcon(int32_t posX, int32_t posY) { void showEspNowIcon(int32_t posX, int32_t posY) { #ifdef SUPPORT_ESPNOW + if (troubledESPNOW) { + tft.drawRoundRect(posX - 2, posY - 2, 16 + 4, 16 + 4, 2, TFT_RED); + tft.drawBitmap(posX, posY, iconEspNow, 16, 16, TFT_BLACK, iconDefaultColor); + return; + } tft.drawRoundRect(posX - 2, posY - 2, 16 + 4, 16 + 4, 2, TFT_DARKGREY); if (!activeESPNOW) { tft.drawBitmap(posX, posY, iconEspNow, 16, 16, TFT_BLACK, TFT_DARKGREY); diff --git a/platformio.ini b/platformio.ini index d285e27e..8062e5f8 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"026"\" + -D CO2_GADGET_REV="\"027"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From b259e8e5a671f291ab6947e25b45b9ac10862c57 Mon Sep 17 00:00:00 2001 From: Mariete Date: Sun, 25 Feb 2024 14:30:36 +0100 Subject: [PATCH 51/53] Update release3_beta.yml --- .github/workflows/release3_beta.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release3_beta.yml b/.github/workflows/release3_beta.yml index 7fb2c07f..41ba84c4 100644 --- a/.github/workflows/release3_beta.yml +++ b/.github/workflows/release3_beta.yml @@ -1,4 +1,4 @@ -name: Beta Release V2.9 +name: Beta Release V2.91 # # # # # # # # # # # # To create new Beta version and upload so web server, just commit with a message with the format "Beta v*.*.*" (Beta v1.0.1, Beta v1.1.12, Beta v2.1.123, etc) @@ -10,6 +10,9 @@ on: - development paths-ignore: - '.github/workflows/release3_beta.yml' # Ignore changes in the workflow file itself + # Only run when commit message contains "Beta" + # Use 'contains' with 'github.event.head_commit.message' + if: contains(github.event.head_commit.message, 'Beta') || github.event_name == 'workflow_dispatch' workflow_dispatch: jobs: From d72a512c172a7f74575b8884f204c08a1c9a9ff8 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sun, 25 Feb 2024 14:31:58 +0100 Subject: [PATCH 52/53] Version Beta v0.10.028 --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 8062e5f8..f01b1f8b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = -D MQTT_BROKER_SERVER="\"192.168.1.145"\" -D CO2_GADGET_VERSION="\"0.10."\" - -D CO2_GADGET_REV="\"027"\" + -D CO2_GADGET_REV="\"028"\" -D CORE_DEBUG_LEVEL=0 -DCACHE_DIR=".pio/build" -DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer From cb56377023b4324567aa8b29d8e7fddce5230a36 Mon Sep 17 00:00:00 2001 From: Mario Mariete <11509521+melkati@users.noreply.github.com> Date: Sun, 25 Feb 2024 14:56:44 +0100 Subject: [PATCH 53/53] Add upgradePreferences function and call it in initPreferences Upgrade in preferences batteryDischargedMillivolts from 3500 to 3200mV --- CO2_Gadget.ino | 1 + CO2_Gadget_Preferences.h | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/CO2_Gadget.ino b/CO2_Gadget.ino index f0f5dfeb..03c743fc 100644 --- a/CO2_Gadget.ino +++ b/CO2_Gadget.ino @@ -19,6 +19,7 @@ void reverseButtons(bool reversed); void outputsLoop(); void publishMQTTLogData(String logData); +void putPreferences(); // Define enum for toneBuzzerBeep enum ToneBuzzerBeep { diff --git a/CO2_Gadget_Preferences.h b/CO2_Gadget_Preferences.h index f17307f2..586967d9 100644 --- a/CO2_Gadget_Preferences.h +++ b/CO2_Gadget_Preferences.h @@ -8,6 +8,15 @@ Preferences preferences; uint8_t prefVersion = 0; uint8_t prefRevision = 0; +void upgradePreferences() { + if ((batteryDischargedMillivolts == 3500) && (prefVersion == 0) && (prefRevision == 0)) { + batteryDischargedMillivolts = 3200; + Serial.printf("-->[PREF] Upgrading preferences batteryDischargedMillivolts to %d\n", batteryDischargedMillivolts); + prefRevision = 1; + putPreferences(); + } +} + void printPreferences() { Serial.printf("-->[PREF] \n"); Serial.printf("-->[PREF] LOADED PREFERENCES FROM NVR:\n"); @@ -177,6 +186,7 @@ void initPreferences() { #ifdef DEBUG_PREFERENCES printPreferences(); #endif +upgradePreferences(); } void putPreferences() {