From f6993fdc696780284353ecd27a010c38ac40269b Mon Sep 17 00:00:00 2001 From: Markus Krause Date: Fri, 31 Mar 2023 00:12:01 +0200 Subject: [PATCH 1/8] fix S3 bin distribution --- scripts/getVersion.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/getVersion.py b/scripts/getVersion.py index 0ebe1ec2..7fbe0e1b 100644 --- a/scripts/getVersion.py +++ b/scripts/getVersion.py @@ -50,6 +50,7 @@ def readVersion(path, infile): versionnumber += line[p+13:].rstrip() + "." os.mkdir(path + "firmware/") + os.mkdir(path + "firmware/s3/") sha = os.getenv("SHA",default="sha") versionout = version[:-1] + "_" + sha + "_esp8266.bin" @@ -80,7 +81,7 @@ def readVersion(path, infile): versionout = version[:-1] + "_" + sha + "_esp32s3.bin" src = path + ".pio/build/opendtufusionv1-release/firmware.bin" - dst = path + "firmware/" + versionout + dst = path + "firmware/s3/" + versionout os.rename(src, dst) # other ESP32 bin files @@ -89,6 +90,15 @@ def readVersion(path, infile): os.rename(src + "bootloader.bin", dst + "bootloader.bin") os.rename(src + "partitions.bin", dst + "partitions.bin") genOtaBin(path + "firmware/") + + # other ESP32S3 bin files + src = path + ".pio/build/opendtufusionv1-release/" + dst = path + "firmware/s3/" + os.rename(src + "bootloader.bin", dst + "bootloader.bin") + os.rename(src + "partitions.bin", dst + "partitions.bin") + os.rename("~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin", dst + "ota.bin") + genOtaBin(path + "firmware/s3/") + os.rename("../scripts/gh-action-dev-build-flash.html", path + "install.html") print("name=" + versionnumber[:-1] ) From 2eb845a9cb6e63df886d455fbe2375d6efb0f370 Mon Sep 17 00:00:00 2001 From: Markus Krause Date: Fri, 31 Mar 2023 00:21:16 +0200 Subject: [PATCH 2/8] remove redundant call --- scripts/getVersion.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/getVersion.py b/scripts/getVersion.py index 7fbe0e1b..e3927907 100644 --- a/scripts/getVersion.py +++ b/scripts/getVersion.py @@ -97,7 +97,6 @@ def readVersion(path, infile): os.rename(src + "bootloader.bin", dst + "bootloader.bin") os.rename(src + "partitions.bin", dst + "partitions.bin") os.rename("~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin", dst + "ota.bin") - genOtaBin(path + "firmware/s3/") os.rename("../scripts/gh-action-dev-build-flash.html", path + "install.html") From c9b6cc5f6f09dd7f79528ffbc54226a75123d16f Mon Sep 17 00:00:00 2001 From: Markus Krause Date: Fri, 31 Mar 2023 00:49:48 +0200 Subject: [PATCH 3/8] fix ota bin copy --- .github/workflows/compile_development.yml | 3 ++ .github/workflows/compile_release.yml | 3 ++ ahoy.code-workspace | 45 +++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 ahoy.code-workspace diff --git a/.github/workflows/compile_development.yml b/.github/workflows/compile_development.yml index ffde2d21..768a522f 100644 --- a/.github/workflows/compile_development.yml +++ b/.github/workflows/compile_development.yml @@ -49,6 +49,9 @@ jobs: - name: Run PlatformIO run: pio run -d src --environment esp8266-release --environment esp8266-release-prometheus --environment esp8285-release --environment esp32-wroom32-release --environment esp32-wroom32-release-prometheus --environment opendtufusionv1-release + - name: Copy boot_app0.bin + run: cp ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin .pio/build/opendtufusionv1-release/ota.bin + - name: Rename Binary files id: rename-binary-files working-directory: src diff --git a/.github/workflows/compile_release.yml b/.github/workflows/compile_release.yml index 84ad5111..25f34fa6 100644 --- a/.github/workflows/compile_release.yml +++ b/.github/workflows/compile_release.yml @@ -53,6 +53,9 @@ jobs: - name: Run PlatformIO run: pio run -d src --environment esp8266-release --environment esp8266-release-prometheus --environment esp8285-release --environment esp32-wroom32-release --environment esp32-wroom32-release-prometheus --environment opendtufusionv1-release + - name: Copy boot_app0.bin + run: cp ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin .pio/build/opendtufusionv1-release/ota.bin + - name: Rename Binary files id: rename-binary-files working-directory: src diff --git a/ahoy.code-workspace b/ahoy.code-workspace new file mode 100644 index 00000000..20d5909e --- /dev/null +++ b/ahoy.code-workspace @@ -0,0 +1,45 @@ +{ + "folders": [ + { + "path": "." + }, + { + "path": "src" + } + ], + "settings": { + "files.associations": { + "algorithm": "cpp", + "array": "cpp", + "chrono": "cpp", + "deque": "cpp", + "format": "cpp", + "forward_list": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "iterator": "cpp", + "list": "cpp", + "memory": "cpp", + "queue": "cpp", + "random": "cpp", + "regex": "cpp", + "vector": "cpp", + "xhash": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xmemory": "cpp", + "xstring": "cpp", + "xtree": "cpp", + "xutility": "cpp", + "*.tcc": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "string_view": "cpp", + "sstream": "cpp", + "istream": "cpp", + "ostream": "cpp" + }, + "editor.formatOnSave": false + } +} \ No newline at end of file From 2eb0a6542db3693502f7d5f79b40202839d76f93 Mon Sep 17 00:00:00 2001 From: Markus Krause Date: Fri, 31 Mar 2023 00:53:59 +0200 Subject: [PATCH 4/8] take new ota.bin --- scripts/getVersion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/getVersion.py b/scripts/getVersion.py index e3927907..e8393ae1 100644 --- a/scripts/getVersion.py +++ b/scripts/getVersion.py @@ -96,7 +96,7 @@ def readVersion(path, infile): dst = path + "firmware/s3/" os.rename(src + "bootloader.bin", dst + "bootloader.bin") os.rename(src + "partitions.bin", dst + "partitions.bin") - os.rename("~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin", dst + "ota.bin") + os.rename(src + "ota.bin", dst + "ota.bin") os.rename("../scripts/gh-action-dev-build-flash.html", path + "install.html") From 3043eaca1f94ddc326e8cb1e17d4a174152255b1 Mon Sep 17 00:00:00 2001 From: Markus Krause Date: Fri, 31 Mar 2023 01:04:39 +0200 Subject: [PATCH 5/8] fix path --- .github/workflows/compile_development.yml | 2 +- .github/workflows/compile_release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compile_development.yml b/.github/workflows/compile_development.yml index 768a522f..4913d726 100644 --- a/.github/workflows/compile_development.yml +++ b/.github/workflows/compile_development.yml @@ -50,7 +50,7 @@ jobs: run: pio run -d src --environment esp8266-release --environment esp8266-release-prometheus --environment esp8285-release --environment esp32-wroom32-release --environment esp32-wroom32-release-prometheus --environment opendtufusionv1-release - name: Copy boot_app0.bin - run: cp ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin .pio/build/opendtufusionv1-release/ota.bin + run: cp ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin src/.pio/build/opendtufusionv1-release/ota.bin - name: Rename Binary files id: rename-binary-files diff --git a/.github/workflows/compile_release.yml b/.github/workflows/compile_release.yml index 25f34fa6..a50ec355 100644 --- a/.github/workflows/compile_release.yml +++ b/.github/workflows/compile_release.yml @@ -54,7 +54,7 @@ jobs: run: pio run -d src --environment esp8266-release --environment esp8266-release-prometheus --environment esp8285-release --environment esp32-wroom32-release --environment esp32-wroom32-release-prometheus --environment opendtufusionv1-release - name: Copy boot_app0.bin - run: cp ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin .pio/build/opendtufusionv1-release/ota.bin + run: cp ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin src/.pio/build/opendtufusionv1-release/ota.bin - name: Rename Binary files id: rename-binary-files From ba996f56dd1b32c6d6beca5b9e085f1f5179ea9f Mon Sep 17 00:00:00 2001 From: Markus Krause Date: Fri, 31 Mar 2023 02:10:09 +0200 Subject: [PATCH 6/8] change build settings fpr S3 to address flash instability --- src/platformio.ini | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/platformio.ini b/src/platformio.ini index 4e2e92fd..7cb7cbfe 100644 --- a/src/platformio.ini +++ b/src/platformio.ini @@ -137,6 +137,10 @@ monitor_filters = [env:opendtufusionv1-release] platform = espressif32 board = esp32-s3-devkitc-1 +upload_protocol = esp-builtin +upload_speed = 115200 +debug_tool = esp-builtin +debug_speed = 12000 build_flags = -D RELEASE -std=gnu++14 build_unflags = -std=gnu++11 monitor_filters = From 33264cc776b1c8501b2894a8f2f8ebfee9cd93a4 Mon Sep 17 00:00:00 2001 From: Markus Krause Date: Fri, 31 Mar 2023 22:51:01 +0200 Subject: [PATCH 7/8] make LED polarity selectable --- src/app.cpp | 28 +++++++++++++++------------- src/app.h | 4 ++-- src/config/settings.h | 4 ++++ src/web/RestApi.h | 1 + src/web/html/setup.html | 12 ++++++++++++ src/web/web.h | 3 ++- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index d3fba12a..088454f6 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -69,7 +69,7 @@ void app::setup() { mPayload.addAlarmListener(std::bind(&PubMqttType::alarmEventListener, &mMqtt, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); } #endif - setupLed(); + setupLed(mConfig->led.led_high_active); mWeb.setup(this, &mSys, mConfig); mWeb.setProtection(strlen(mConfig->sys.adminPwd) != 0); @@ -353,7 +353,7 @@ void app::tickSend(void) { } yield(); - updateLed(); + updateLed(mConfig->led.led_high_active); } //----------------------------------------------------------------------------- @@ -386,31 +386,33 @@ void app::mqttSubRxCb(JsonObject obj) { } //----------------------------------------------------------------------------- -void app::setupLed(void) { - /** LED connection diagram - * \\ - * PIN ---- |<----- 3.3V - * - * */ +void app::setupLed(uint8_t is_high_active) { + + uint8_t led_off = (is_high_active != 0) ? LOW : HIGH; + if (mConfig->led.led0 != 0xff) { pinMode(mConfig->led.led0, OUTPUT); - digitalWrite(mConfig->led.led0, HIGH); // LED off + digitalWrite(mConfig->led.led0, led_off); } if (mConfig->led.led1 != 0xff) { pinMode(mConfig->led.led1, OUTPUT); - digitalWrite(mConfig->led.led1, HIGH); // LED off + digitalWrite(mConfig->led.led1, led_off); } } //----------------------------------------------------------------------------- -void app::updateLed(void) { +void app::updateLed(uint8_t is_high_active) { + + uint8_t led_off = (is_high_active != 0) ? LOW : HIGH; + uint8_t led_on = (is_high_active != 0) ? HIGH : LOW; + if (mConfig->led.led0 != 0xff) { Inverter<> *iv = mSys.getInverterByPos(0); if (NULL != iv) { if (iv->isProducing(mTimestamp)) - digitalWrite(mConfig->led.led0, LOW); // LED on + digitalWrite(mConfig->led.led0, led_on); else - digitalWrite(mConfig->led.led0, HIGH); // LED off + digitalWrite(mConfig->led.led0, led_off); } } } diff --git a/src/app.h b/src/app.h index cbf7e6a1..252434ae 100644 --- a/src/app.h +++ b/src/app.h @@ -213,8 +213,8 @@ class app : public IApp, public ah::Scheduler { void mqttSubRxCb(JsonObject obj); - void setupLed(void); - void updateLed(void); + void setupLed(uint8_t is_high_active); + void updateLed(uint8_t is_high_active); void tickReboot(void) { DPRINTLN(DBG_INFO, F("Rebooting...")); diff --git a/src/config/settings.h b/src/config/settings.h index 6d58b406..7449a0b6 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -100,6 +100,7 @@ typedef struct { typedef struct { uint8_t led0; // first LED pin uint8_t led1; // second LED pin + uint8_t led_high_active; // determines if LEDs are high or low active } cfgLed_t; typedef struct { @@ -378,6 +379,7 @@ class settings { mCfg.led.led0 = DEF_PIN_OFF; mCfg.led.led1 = DEF_PIN_OFF; + mCfg.led.led_high_active = LOW; memset(&mCfg.inst, 0, sizeof(cfgInst_t)); @@ -517,9 +519,11 @@ class settings { if(set) { obj[F("0")] = mCfg.led.led0; obj[F("1")] = mCfg.led.led1; + obj[F("2")] = mCfg.led.led_high_active; } else { mCfg.led.led0 = obj[F("0")]; mCfg.led.led1 = obj[F("1")]; + mCfg.led.led_high_active = obj[F("2")]; } } diff --git a/src/web/RestApi.h b/src/web/RestApi.h index b224f239..8c193e28 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -391,6 +391,7 @@ class RestApi { obj[F("miso")] = mConfig->nrf.pinMiso; obj[F("led0")] = mConfig->led.led0; obj[F("led1")] = mConfig->led.led1; + obj[F("led_high_active")] = mConfig->led.led_high_active; } void getRadio(JsonObject obj) { diff --git a/src/web/html/setup.html b/src/web/html/setup.html index bfbda402..fbe29010 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -411,6 +411,10 @@ [47, "GPIO47"], [48, "GPIO48"], ]; + var led_high_active = [ + [0, "low active"], + [1, "high active"], + ]; const re = /11[2,4,6]1.*/; @@ -670,6 +674,14 @@ ]) ); } + e.append( + ml("div", { class: "row mb-3" }, [ + ml("div", { class: "col-12 col-sm-3 my-2" }, "LED polarity"), + ml("div", { class: "col-12 col-sm-9" }, + sel('pinLedHighActive', led_high_active, obj["led_high_active"]) + ) + ]) + ); } function parseRadio(obj) { diff --git a/src/web/web.h b/src/web/web.h index c141e013..94f6ece7 100644 --- a/src/web/web.h +++ b/src/web/web.h @@ -33,7 +33,7 @@ #define WEB_SERIAL_BUF_SIZE 2048 -const char *const pinArgNames[] = {"pinCs", "pinCe", "pinIrq", "pinSclk", "pinMosi", "pinMiso", "pinLed0", "pinLed1"}; +const char *const pinArgNames[] = {"pinCs", "pinCe", "pinIrq", "pinSclk", "pinMosi", "pinMiso", "pinLed0", "pinLed1", "pinLedHighActive"}; template class Web { @@ -532,6 +532,7 @@ class Web { case 5: mConfig->nrf.pinMiso = ((pin != 0xff) ? pin : DEF_MISO_PIN); break; case 6: mConfig->led.led0 = pin; break; case 7: mConfig->led.led1 = pin; break; + case 8: mConfig->led.led_high_active = pin; break; // this is not really a pin but a polarity, but handling it close to here makes sense } } From 48a6bf021cf11f79ca71a25fa9eae571779d3748 Mon Sep 17 00:00:00 2001 From: Markus Krause Date: Sat, 1 Apr 2023 13:00:38 +0200 Subject: [PATCH 8/8] add MQTT status to LED update, try to fix settings save for led polarity --- src/app.cpp | 22 +++++++++++++++------- src/app.h | 4 ++-- src/config/settings.h | 4 ++-- src/web/html/setup.html | 2 +- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index 088454f6..9ec6ff26 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -69,7 +69,7 @@ void app::setup() { mPayload.addAlarmListener(std::bind(&PubMqttType::alarmEventListener, &mMqtt, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); } #endif - setupLed(mConfig->led.led_high_active); + setupLed(); mWeb.setup(this, &mSys, mConfig); mWeb.setProtection(strlen(mConfig->sys.adminPwd) != 0); @@ -353,7 +353,7 @@ void app::tickSend(void) { } yield(); - updateLed(mConfig->led.led_high_active); + updateLed(); } //----------------------------------------------------------------------------- @@ -386,9 +386,9 @@ void app::mqttSubRxCb(JsonObject obj) { } //----------------------------------------------------------------------------- -void app::setupLed(uint8_t is_high_active) { +void app::setupLed(void) { - uint8_t led_off = (is_high_active != 0) ? LOW : HIGH; + uint8_t led_off = (mConfig->led.led_high_active != 0) ? LOW : HIGH; if (mConfig->led.led0 != 0xff) { pinMode(mConfig->led.led0, OUTPUT); @@ -401,10 +401,10 @@ void app::setupLed(uint8_t is_high_active) { } //----------------------------------------------------------------------------- -void app::updateLed(uint8_t is_high_active) { +void app::updateLed(void) { - uint8_t led_off = (is_high_active != 0) ? LOW : HIGH; - uint8_t led_on = (is_high_active != 0) ? HIGH : LOW; + uint8_t led_off = (mConfig->led.led_high_active != 0) ? LOW : HIGH; + uint8_t led_on = (mConfig->led.led_high_active != 0) ? HIGH : LOW; if (mConfig->led.led0 != 0xff) { Inverter<> *iv = mSys.getInverterByPos(0); @@ -415,4 +415,12 @@ void app::updateLed(uint8_t is_high_active) { digitalWrite(mConfig->led.led0, led_off); } } + + if (mConfig->led.led1 != 0xff) { + if (getMqttIsConnected()) { + digitalWrite(mConfig->led.led1, led_on); + } else { + digitalWrite(mConfig->led.led1, led_off); + } + } } diff --git a/src/app.h b/src/app.h index 252434ae..6dfc404c 100644 --- a/src/app.h +++ b/src/app.h @@ -213,8 +213,8 @@ class app : public IApp, public ah::Scheduler { void mqttSubRxCb(JsonObject obj); - void setupLed(uint8_t is_high_active); - void updateLed(uint8_t is_high_active); + void setupLed(); + void updateLed(); void tickReboot(void) { DPRINTLN(DBG_INFO, F("Rebooting...")); diff --git a/src/config/settings.h b/src/config/settings.h index 7449a0b6..e895a8a9 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -519,11 +519,11 @@ class settings { if(set) { obj[F("0")] = mCfg.led.led0; obj[F("1")] = mCfg.led.led1; - obj[F("2")] = mCfg.led.led_high_active; + obj[F("led_high_active")] = mCfg.led.led_high_active; } else { mCfg.led.led0 = obj[F("0")]; mCfg.led.led1 = obj[F("1")]; - mCfg.led.led_high_active = obj[F("2")]; + mCfg.led.led_high_active = obj[F("led_high_active")]; } } diff --git a/src/web/html/setup.html b/src/web/html/setup.html index fbe29010..97bf5608 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -678,7 +678,7 @@ ml("div", { class: "row mb-3" }, [ ml("div", { class: "col-12 col-sm-3 my-2" }, "LED polarity"), ml("div", { class: "col-12 col-sm-9" }, - sel('pinLedHighActive', led_high_active, obj["led_high_active"]) + sel('pinLedHighActive', led_high_active, obj['led_high_active']) ) ]) );