mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-05-05 23:54:35 +00:00
Fixed broken build
This commit is contained in:
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -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
|
||||
|
||||
14
.github/workflows/release.yml
vendored
14
.github/workflows/release.yml
vendored
@@ -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
|
||||
|
||||
33
README.md
33
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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
30
scripts/pio-run.sh
Executable file
30
scripts/pio-run.sh
Executable file
@@ -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
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user