From 30fe54eb7d9f811b391e1263ad8f2a5e755c242f Mon Sep 17 00:00:00 2001 From: EivindH06 Date: Thu, 9 Oct 2025 15:44:03 +0200 Subject: [PATCH] Fixed broken build --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 14 ++++++------ README.md | 33 ++++++++++++++++++++++++++- lib/PriceService/src/PriceService.cpp | 18 +++++++++++++++ package.json | 4 ++++ platformio.ini | 9 ++++++-- scripts/pio-run.sh | 30 ++++++++++++++++++++++++ src/AmsToMqttBridge.cpp | 25 ++++++++++++++++++++ 8 files changed, 124 insertions(+), 11 deletions(-) create mode 100755 scripts/pio-run.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 74eee154..fb81ef2c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -62,4 +62,4 @@ jobs: - name: PlatformIO lib install run: pio pkg install - name: PlatformIO run - run: pio run + run: ./scripts/pio-run.sh run diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 616fd05f..3e612bf8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -102,7 +102,7 @@ jobs: CI: false - name: PlatformIO lib install - run: pio lib install + run: ./scripts/pio-run.sh lib install - name: Create release with release notes id: create_release @@ -113,7 +113,7 @@ jobs: allowUpdates: true - name: Build esp8266 firmware - run: pio run -e esp8266 + run: ./scripts/pio-run.sh run -e esp8266 - name: Create esp8266 zip file run: /bin/sh scripts/esp8266/mkzip.sh - name: Upload esp8266 binary to release @@ -136,7 +136,7 @@ jobs: asset_content_type: application/zip - name: Build esp32 firmware - run: pio run -e esp32 + run: ./scripts/pio-run.sh run -e esp32 - name: Create esp32 zip file run: /bin/sh scripts/esp32/mkzip.sh - name: Upload esp32 binary to release @@ -159,7 +159,7 @@ jobs: asset_content_type: application/zip - name: Build esp32s2 firmware - run: pio run -e esp32s2 + run: ./scripts/pio-run.sh run -e esp32s2 - name: Create esp32s2 zip file run: /bin/sh scripts/esp32s2/mkzip.sh - name: Upload esp32s2 binary to release @@ -182,7 +182,7 @@ jobs: asset_content_type: application/zip - name: Build esp32s3 firmware - run: pio run -e esp32s3 + run: ./scripts/pio-run.sh run -e esp32s3 - name: Create esp32s3 zip file run: /bin/sh scripts/esp32s3/mkzip.sh - name: Upload esp32s3 binary to release @@ -205,7 +205,7 @@ jobs: asset_content_type: application/zip - name: Build esp32solo firmware - run: pio run -e esp32solo + run: ./scripts/pio-run.sh run -e esp32solo - name: Create esp32solo zip file run: /bin/sh scripts/esp32solo/mkzip.sh - name: Upload esp32solo binary to release @@ -228,7 +228,7 @@ jobs: asset_content_type: application/zip - name: Build esp32c3 firmware - run: pio run -e esp32c3 + run: ./scripts/pio-run.sh run -e esp32c3 - name: Create esp32c3 zip file run: /bin/sh scripts/esp32c3/mkzip.sh - name: Upload esp32c3 binary to release diff --git a/README.md b/README.md index 31df5c4a..5bbfaa32 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,38 @@ It is recommended to use Visual Studio Code with the PlatformIO plugin for devel For development purposes, copy the ```platformio-user.ini-example``` to ```platformio-user.ini``` and customize to your preference. The code will adapt to the platform and board set in your profile. -The repository now defaults to the primary ESP32 firmware when you run `pio run`. If you need to build one of the alternative targets (ESP8266, ESP32-C3, ESP32-S2, ESP32-S3, etc.), pass the environment explicitly, for example `pio run -e esp8266` or `pio run -e esp32c3`. +### Running builds on macOS Apple Silicon + +The ESP8266 and ESP32-C3 toolchains bundled with the custom Tasmota platform +are still compiled for Intel macOS. To keep `pio run` working without forcing +you to remember `arch -x86_64`, the repository now ships a tiny wrapper: + +```bash +./scripts/pio-run.sh run # build every default environment (all boards) +./scripts/pio-run.sh run -e esp8266 # build a specific environment only +``` + +The script automatically re-launches PlatformIO under Rosetta 2 when you are on +an Apple Silicon Mac. On first run it also provisions a dedicated x86 Python +virtual environment in `~/.platformio/penv-x86` and installs PlatformIO inside +it, so expect an extra minute for the initial setup. If Rosetta is missing you +will see a friendly reminder to install it with +`softwareupdate --install-rosetta --agree-to-license`. + +If you prefer using npm scripts, the same wrapper is available through: + +```bash +npm run pio:run # builds every configured board +npm run pio:run:env -- esp32c3 # pass any PlatformIO environment name +``` + +> **Heads-up:** invoking `pio run` directly on an Apple Silicon Mac will still +> fail for the ESP8266/ESP32-C3 environments unless you prefix it with +> `arch -x86_64`. Using `scripts/pio-run.sh` (or the npm aliases) keeps the +> command portable across macOS and Linux without special flags. + +> The first macOS run may print `NotOpenSSLWarning` from `urllib3`; this comes +> from Apple's LibreSSL build and can safely be ignored for local development. ## Licensing Initially, this project began as a hobby, consuming countless hours of our spare time. However, the time required to support this project has expanded beyond the scope of a hobby. As a result, we established ‘Utilitech’, a company dedicated to maintaining the software and hardware for this project as part of our regular work. diff --git a/lib/PriceService/src/PriceService.cpp b/lib/PriceService/src/PriceService.cpp index f31bf071..71669d5c 100644 --- a/lib/PriceService/src/PriceService.cpp +++ b/lib/PriceService/src/PriceService.cpp @@ -263,6 +263,14 @@ bool PriceService::loop() { bool readyToFetchForTomorrow = tomorrow == NULL && (tm.Hour > 13 || (tm.Hour == 13 && tm.Minute >= tomorrowFetchMinute)) && (lastTomorrowFetch == 0 || now - lastTomorrowFetch > (nextFetchDelayMinutes*60000)); if(today == NULL && (lastTodayFetch == 0 || now - lastTodayFetch > (nextFetchDelayMinutes*60000))) { +#if defined(ESP8266) + lastTodayFetch = now; + today = fetchPrices(t); + if(today == NULL && lastError == 0) { + lastError = 900; + nextFetchDelayMinutes = 60; + } +#else try { lastTodayFetch = now; today = fetchPrices(t); @@ -273,12 +281,21 @@ bool PriceService::loop() { } today = NULL; } +#endif return today != NULL && !readyToFetchForTomorrow; // Only trigger MQTT publish if we have todays prices and we are not immediately ready to fetch price for tomorrow. } // Prices for next day are published at 13:00 CE(S)T, but to avoid heavy server traffic at that time, we will // fetch with one hour (with some random delay) and retry every 15 minutes if(readyToFetchForTomorrow) { +#if defined(ESP8266) + lastTomorrowFetch = now; + tomorrow = fetchPrices(t+SECS_PER_DAY); + if(tomorrow == NULL && lastError == 0) { + lastError = 900; + nextFetchDelayMinutes = 60; + } +#else try { lastTomorrowFetch = now; tomorrow = fetchPrices(t+SECS_PER_DAY); @@ -289,6 +306,7 @@ bool PriceService::loop() { } tomorrow = NULL; } +#endif return tomorrow != NULL; } diff --git a/package.json b/package.json index 73e2f2c4..e698d403 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,8 @@ { + "scripts": { + "pio:run": "./scripts/pio-run.sh run", + "pio:run:env": "./scripts/pio-run.sh run -e" + }, "devDependencies": { "svelte-preprocess": "^6.0.3" } diff --git a/platformio.ini b/platformio.ini index dafc4042..6fd2a0ef 100755 --- a/platformio.ini +++ b/platformio.ini @@ -1,5 +1,5 @@ [platformio] -default_envs = esp32 +default_envs = esp8266, esp32, esp32s2, esp32s3, esp32solo, esp32c3 extra_configs = platformio-user.ini [common] @@ -28,7 +28,12 @@ platform = espressif8266@4.2.1 framework = arduino board = esp12e board_build.ldscript = eagle.flash.4m2m.ld -build_flags = ${common.build_flags} -D AMS_REMOTE_DEBUG=1 +build_unflags = -fexceptions +build_flags = + ${common.build_flags} + -fno-exceptions + -D AMS_REMOTE_DEBUG=1 + -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY lib_ldf_mode = off lib_compat_mode = off lib_deps = ESP8266WiFi, ESP8266mDNS, ESP8266WebServer, ESP8266HTTPClient, ESP8266httpUpdate, ESP8266SSDP, EspSoftwareSerial@8.2.0, ${common.lib_deps}, SvelteUi diff --git a/scripts/pio-run.sh b/scripts/pio-run.sh new file mode 100755 index 00000000..c42a2535 --- /dev/null +++ b/scripts/pio-run.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +set -euo pipefail + +ARGS=("$@") +if [[ ${#ARGS[@]} -eq 0 ]]; then + ARGS=("run") +fi + +if [[ "$(uname -s)" == "Darwin" && "$(uname -m)" == "arm64" ]]; then + if ! /usr/bin/arch -x86_64 /usr/bin/true >/dev/null 2>&1; then + cat <<'EOF' +Rosetta 2 does not appear to be installed or is disabled. Install it with: + softwareupdate --install-rosetta --agree-to-license +EOF + exit 1 + fi + + PIO_X86_DIR="${HOME}/.platformio/penv-x86" + PIO_BIN="${PIO_X86_DIR}/bin/platformio" + + if [[ ! -x "${PIO_BIN}" ]]; then + echo "Setting up x86 PlatformIO environment in ${PIO_X86_DIR}..." + /usr/bin/arch -x86_64 /usr/bin/python3 -m venv "${PIO_X86_DIR}" + /usr/bin/arch -x86_64 "${PIO_X86_DIR}/bin/pip" install --upgrade pip wheel platformio + fi + + exec /usr/bin/arch -x86_64 "${PIO_BIN}" "${ARGS[@]}" +else + exec pio "${ARGS[@]}" +fi diff --git a/src/AmsToMqttBridge.cpp b/src/AmsToMqttBridge.cpp index 4b8ec962..a5af5664 100644 --- a/src/AmsToMqttBridge.cpp +++ b/src/AmsToMqttBridge.cpp @@ -653,11 +653,15 @@ void loop() { } #endif +#if defined(ESP8266) + handlePriceService(now); +#else try { handlePriceService(now); } catch(const std::exception& e) { debugE_P(PSTR("Exception in PriceService loop (%s)"), e.what()); } +#endif start = millis(); ws.loop(); end = millis(); @@ -882,6 +886,26 @@ void loop() { if(config.isEnergyAccountingChanged()) { handleEnergyAccountingChanged(); } +#if defined(ESP8266) + start = millis(); + if(readHanPort() || now - meterState.getLastUpdateMillis() > 30000) { + end = millis(); + if(end - start > SLOW_PROC_TRIGGER_MS) { + debugW_P(PSTR("Used %dms to read HAN port (true)"), millis()-start); + } + handleTemperature(now); + handleSystem(now); + hw.setBootSuccessful(true); + } else { + end = millis(); + if(end - start > SLOW_PROC_TRIGGER_MS) { + debugW_P(PSTR("Used %dms to read HAN port (false)"), millis()-start); + } + } + if(millis() - meterState.getLastUpdateMillis() > 1800000 && !ds.isHappy(time(nullptr))) { + handleClear(now); + } +#else try { start = millis(); if(readHanPort() || now - meterState.getLastUpdateMillis() > 30000) { @@ -905,6 +929,7 @@ void loop() { debugE_P(PSTR("Exception in readHanPort (%s)"), e.what()); meterState.setLastError(METER_ERROR_EXCEPTION); } +#endif delay(10); // Needed for auto modem sleep start = millis();