From 204e1be353c8d9b7d1d8e70d120bd64daadd4da8 Mon Sep 17 00:00:00 2001 From: Oleksii Kutuzov Date: Wed, 3 Aug 2022 00:07:36 +0200 Subject: [PATCH 1/4] Change from AsyncWebServer to WebServer and misc --- air_quality/DEV_Sensors.hpp | 2 +- air_quality/air_quality.ino | 66 ++++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/air_quality/DEV_Sensors.hpp b/air_quality/DEV_Sensors.hpp index 21a7e23..40d73bd 100644 --- a/air_quality/DEV_Sensors.hpp +++ b/air_quality/DEV_Sensors.hpp @@ -12,7 +12,7 @@ #define HOMEKIT_CO2_TRIGGER 1350 // co2 level, at which HomeKit alarm will be triggered #define NEOPIXEL_PIN 16 // Pin to which NeoPixel strip is connected #define NUMPIXELS 1 // Number of pixels -#define BRIGHTNESS_DEFAULT 10 // Default (dimmed) brightness +#define BRIGHTNESS_DEFAULT 9 // Default (dimmed) brightness #define BRIGHTNESS_MAX 150 // maximum brightness of CO2 indicator led #define BRIGHTNESS_THRESHOLD 500 // TODO calibrate Threshold value of dimmed brightness #define ANALOG_PIN 35 // Analog pin, to which light sensor is connected diff --git a/air_quality/air_quality.ino b/air_quality/air_quality.ino index dca65fb..a29f5e3 100644 --- a/air_quality/air_quality.ino +++ b/air_quality/air_quality.ino @@ -49,43 +49,49 @@ * ╚═════════════════════════════╝ */ -#include +#define REQUIRED VERSION(1, 5, 1) + #include "DEV_Sensors.hpp" -#include -#include -#include #include "SerialCom.hpp" #include "Types.hpp" -#include -#include +#include +#include +#include +#include +#include +#include +#include -#define BUTTON_PIN 0 -#define LED_STATUS_PIN 26 +#define BUTTON_PIN 0 +#define LED_STATUS_PIN 26 -AsyncWebServer server(80); +#define BOOT_REASON_MESSAGE_SIZE 150 -DEV_CO2Sensor *CO2; // GLOBAL POINTER TO STORE SERVICE +WebServer server(80); + +DEV_CO2Sensor *CO2; // GLOBAL POINTER TO STORE SERVICE DEV_AirQualitySensor *AQI; // GLOBAL POINTER TO STORE SERVICE void setup() { Serial.begin(115200); - homeSpan.setControlPin(BUTTON_PIN); // Set button pin - homeSpan.setStatusPin(LED_STATUS_PIN); // Set status led pin - homeSpan.setLogLevel(0); // set log level - homeSpan.setPortNum(88); // change port number for HomeSpan so we can use port 80 for the Web Server - homeSpan.setStatusAutoOff(10); // turn off status led after 10 seconds of inactivity - homeSpan.setWifiCallback(setupWeb); // need to start Web Server after WiFi is established - homeSpan.reserveSocketConnections(3); // reserve 3 socket connections for Web Server - // homeSpan.enableAutoStartAP(); + homeSpan.setControlPin(BUTTON_PIN); // Set button pin + homeSpan.setStatusPin(LED_STATUS_PIN); // Set status led pin + homeSpan.setLogLevel(0); // set log level + homeSpan.setPortNum(88); // change port number for HomeSpan so we can use port 80 for the Web Server + homeSpan.setStatusAutoOff(10); // turn off status led after 10 seconds of inactivity + homeSpan.setWifiCallback(setupWeb); // need to start Web Server after WiFi is established + homeSpan.reserveSocketConnections(3); // reserve 3 socket connections for Web Server + homeSpan.enableWebLog(10, "pool.ntp.org", "UTC", "myLog"); // enable Web Log + homeSpan.enableAutoStartAP(); // enable auto start AP homeSpan.begin(Category::Bridges, "HomeSpan Air Sensor Bridge"); new SpanAccessory(); new Service::AccessoryInformation(); new Characteristic::Identify(); - new Characteristic::FirmwareRevision("1.2"); + new Characteristic::FirmwareRevision("1.3"); new SpanAccessory(); new Service::AccessoryInformation(); @@ -101,42 +107,42 @@ void setup() { } void loop() { - homeSpan.poll(); + server.handleClient(); } void setupWeb() { Serial.print("Starting Air Quality Sensor Server Hub...\n\n"); - server.on("/metrics", HTTP_GET, [](AsyncWebServerRequest *request) { + server.on("/metrics", HTTP_GET, []() { double airQuality = AQI->pm25->getVal(); double co2 = CO2->co2Level->getVal(); if (co2 >= 400) { // exclude when it is still warming up // double lightness = neopixelAutoBrightness(); double uptime = esp_timer_get_time() / (6 * 10e6); double heap = esp_get_free_heap_size(); - String airQualityMetric = "# HELP air_quality PM2.5 Density\nair_quality{device=\"air_sensor\",location=\"home\"} " + String(airQuality); - String CO2Metric = "# HELP co2 Carbon Dioxide\ncarbon_dioxide{device=\"air_sensor\",location=\"home\"} " + String(co2); - String uptimeMetric = "# HELP uptime Sensor uptime\nuptime{device=\"air_sensor\",location=\"home\"} " + String(int(uptime)); - String heapMetric = "# HELP heap Available heap memory\nheap{device=\"air_sensor\",location=\"home\"} " + String(int(heap)); + String airQualityMetric = "# HELP air_quality PM2.5 Density\nhomekit_air_quality{device=\"air_sensor\",location=\"home\"} " + String(airQuality); + String CO2Metric = "# HELP co2 Carbon Dioxide\nhomekit_carbon_dioxide{device=\"air_sensor\",location=\"home\"} " + String(co2); + String uptimeMetric = "# HELP uptime Sensor uptime\nhomekit_uptime{device=\"air_sensor\",location=\"home\"} " + String(int(uptime)); + String heapMetric = "# HELP heap Available heap memory\nhomekit_heap{device=\"air_sensor\",location=\"home\"} " + String(int(heap)); // String lightnessMetric = "# HELP lightness Lightness\nlightness{device=\"air_sensor\",location=\"home\"} " + String(lightness); Serial.println(airQualityMetric); Serial.println(CO2Metric); Serial.println(uptimeMetric); Serial.println(heapMetric); - request->send(200, "text/plain", airQualityMetric + "\n" + CO2Metric + "\n" + uptimeMetric + "\n" + heapMetric); + server.send(200, "text/plain", airQualityMetric + "\n" + CO2Metric + "\n" + uptimeMetric + "\n" + heapMetric); } }); - server.on("/reboot", HTTP_GET, [](AsyncWebServerRequest *request) { + server.on("/reboot", HTTP_GET, []() { String content = "Rebooting! Will return to configuration page in 10 seconds.

"; content += ""; - request->send(200, "text/html", content); + server.send(200, "text/html", content); ESP.restart(); }); - AsyncElegantOTA.begin(&server); // Start AsyncElegantOTA + ElegantOTA.begin(&server); // Start AsyncElegantOTA server.begin(); Serial.println("HTTP server started"); -} // setupWeb +} // setupWeb \ No newline at end of file From a8d210b651eb4197690cb3424051e54e2b585924 Mon Sep 17 00:00:00 2001 From: Oleksii Kutuzov Date: Wed, 3 Aug 2022 00:09:20 +0200 Subject: [PATCH 2/4] Update VSCode config --- .gitignore | 3 ++- .vscode/arduino.json | 4 ++-- .vscode/settings.json | 3 +++ .vscode/tasks.json | 11 +++++++---- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index d636667..1e118e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store build/ *.bin -*.code-workspace \ No newline at end of file +*.code-workspace +.vscode/c_cpp_properties.json diff --git a/.vscode/arduino.json b/.vscode/arduino.json index 161bac7..30782a0 100644 --- a/.vscode/arduino.json +++ b/.vscode/arduino.json @@ -1,7 +1,7 @@ { - "configuration": "PSRAM=disabled,PartitionScheme=default,CPUFreq=240,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=115200,LoopCore=1,EventsCore=1,DebugLevel=none", + "configuration": "PSRAM=disabled,PartitionScheme=default,CPUFreq=240,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=115200,LoopCore=1,EventsCore=0,DebugLevel=none", "board": "esp32:esp32:esp32", - "port": "/dev/tty.usbserial-1410", + "port": "/dev/tty.usbserial-01DFA3CE", "sketch": "air_quality/air_quality.ino", "output": "build", "postbuild": "cp ./build/air_quality.ino.bin ./esp32_air_quality.bin", diff --git a/.vscode/settings.json b/.vscode/settings.json index a43e4f1..36ade92 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,14 +1,17 @@ { "cSpell.words": [ "Adafruit", + "Berman", "Erriez", "Grafana", "haxfleisch", + "HOMEKIT", "homespan", "Hypfer", "kasik", "microcontroller", "NEOPIXEL", + "nhomekit", "Testpoint", "VINDRIKTNING", "webserver", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 63191cd..3f75b7e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -4,10 +4,13 @@ "version": "2.0.0", "tasks": [ { - "label": "Erase Flash", - "type": "shell", - "command": "esptool.py -p /dev/cu.usbserial-1410 erase_flash", - "problemMatcher": [] + "label": "ESP32: Build", + "command": "${command:arduino.verify}", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } } ] } \ No newline at end of file From 82d91bd1f29c8ab1facf36d510790f891417bc3d Mon Sep 17 00:00:00 2001 From: Oleksii Kutuzov <8535871+oleksiikutuzov@users.noreply.github.com> Date: Wed, 3 Aug 2022 00:16:53 +0200 Subject: [PATCH 3/4] Update build.yml --- .github/workflows/build.yml | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f7767b5..6916281 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,26 +9,12 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Checkout ESPAsyncWebServer library + - name: Checkout ElegantOTA library uses: actions/checkout@v2 with: - repository: me-no-dev/ESPAsyncWebServer + repository: ayushsharma82/ElegantOTA ref: master - path: CustomESPAsyncWebServer # must contain string "Custom" - - - name: Checkout AsyncElegantOTA library - uses: actions/checkout@v2 - with: - repository: ayushsharma82/AsyncElegantOTA - ref: master - path: CustomAsyncElegantOTA - - - name: Checkout AsyncTCP library - uses: actions/checkout@v2 - with: - repository: me-no-dev/AsyncTCP - ref: master - path: CustomAsyncTCP + path: ElegantOTA - name: Checkout ErriezMHZ19B library uses: actions/checkout@v2 @@ -55,7 +41,7 @@ jobs: uses: ArminJo/arduino-test-compile@v3 with: sketch-names: "air_quality.ino" - arduino-board-fqbn: "esp32:esp32:esp32:PSRAM=disabled,PartitionScheme=default,CPUFreq=240,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=115200,LoopCore=1,EventsCore=1,DebugLevel=none" + arduino-board-fqbn: "esp32:esp32:esp32:PSRAM=disabled,PartitionScheme=default,CPUFreq=240,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=115200,LoopCore=1,EventsCore=0,DebugLevel=none" platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json required-libraries: HomeSpan,EspSoftwareSerial # sketches-exclude: WhistleSwitch 50Hz From 642025ac7eeeb890f00fe5d107cd61a873072648 Mon Sep 17 00:00:00 2001 From: Oleksii Kutuzov <8535871+oleksiikutuzov@users.noreply.github.com> Date: Wed, 3 Aug 2022 00:18:16 +0200 Subject: [PATCH 4/4] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6916281..698109b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: with: repository: ayushsharma82/ElegantOTA ref: master - path: ElegantOTA + path: CustomElegantOTA - name: Checkout ErriezMHZ19B library uses: actions/checkout@v2