Skip to content

Commit bbcf246

Browse files
authored
version 0.9.5 (#37)
* Have "pio run" build the svelte interface. * Use og3 0.4.0, packages Watchdog
1 parent c64dcf8 commit bbcf246

4 files changed

Lines changed: 40 additions & 27 deletions

File tree

README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,10 @@ Please see the [instructions](instructions.md) for how to assemble and set up a
3333
* [PlatformIO](https://platformio.org/) (Core or VSCode extension)
3434
* [Node.js](https://nodejs.org/) (for building the web interface)
3535

36-
### Building the Web Interface
37-
The web interface is built with Svelte and must be compiled before uploading to the ESP32's filesystem.
38-
39-
```bash
40-
./build-svelte.sh
41-
```
42-
43-
This generates the static HTML/CSS/JS files in `data/static/`, then converts them into a header file (using [svelteesp32](https://github.com/BCsabaEngine/svelteesp32))to include them all in the firmware.
44-
4536
### Building and Flashing Firmware
4637

4738
1. **Configure Secrets**: Copy `secrets.ini.example` to `secrets.ini` and set your WiFi credentials, OTA password, and MQTT details.
48-
2. **Build Firmware**:
39+
2. **Build the Web interface and Firmware**:
4940
```bash
5041
pio run
5142
```

build_svelte.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
import subprocess
3+
from SCons.Script import Import
4+
5+
# Import the build environment from PlatformIO/SCons
6+
Import("env")
7+
8+
def build_svelte():
9+
print("Building Svelte interface...")
10+
11+
# Get the project root directory
12+
project_dir = env.subst("$PROJECT_DIR")
13+
script_path = os.path.join(project_dir, "build-svelte.sh")
14+
15+
# Ensure the script is executable
16+
# This enables the OS to run it directly via the shebang (#!/bin/sh)
17+
os.chmod(script_path, 0o755)
18+
19+
# Execute the shell script directly (shell=False)
20+
# We pass the full path as the executable.
21+
try:
22+
subprocess.run([script_path], cwd=project_dir, check=True)
23+
except subprocess.CalledProcessError:
24+
print("Error: Svelte build script returned non-zero exit code!")
25+
env.Exit(1)
26+
except OSError as e:
27+
print(f"Error: Could not execute build script at {script_path}")
28+
print(f"Details: {e}")
29+
env.Exit(1)
30+
31+
build_svelte()

platformio.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ monitor_speed = 115200
2323
check_tool = clangtidy
2424
monitor_filters = esp32_exception_decoder
2525
build_type = release
26+
extra_scripts = pre:build_svelte.py
2627
lib_deps =
2728
; watering
28-
chl33/og3@^0.3.99
29+
chl33/og3@^0.4.0
2930
og3x-oled@^0.3.1
3031
og3x-shtc3@^0.3.0
3132
adafruit/Adafruit BusIO
@@ -54,5 +55,5 @@ upload_port = ${secrets.uploadPort}
5455
upload_flags =
5556
${secrets.uploadAuth}
5657
${secrets.uploadHostPort}
57-
lib_ldf_mode = deep
58+
lib_ldf_mode = chain
5859
lib_compat_mode = strict

src/main.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
#include <AsyncJson.h>
77
#include <ESPAsyncWebServer.h>
88
#include <LittleFS.h>
9-
#include <esp_task_wdt.h>
109
#include <og3/constants.h>
1110
#include <og3/ha_app.h>
1211
#include <og3/html_table.h>
1312
#include <og3/oled_wifi_info.h>
1413
#include <og3/shtc3.h>
1514
#include <og3/units.h>
1615
#include <og3/variable.h>
16+
#include <og3/wifi_watchdog.h>
1717

1818
#include <algorithm>
1919
#include <array>
@@ -24,7 +24,7 @@
2424
#include "svelteesp32async.h"
2525
#include "watering.h"
2626

27-
#define SW_VERSION "0.9.4"
27+
#define SW_VERSION "0.9.5"
2828

2929
namespace {
3030

@@ -91,6 +91,8 @@ og3::PeriodicTaskScheduler climate_scheduler(
9191
},
9292
&s_app.tasks());
9393

94+
og3::WifiWatchdog s_watchdog(&s_app, std::chrono::seconds(5), std::chrono::seconds(1));
95+
9496
// s_reservior monitors the water level of the reservoir: the float, and the number of seconds
9597
// the pumps have run since the float detected low water level.
9698
og3::ReservoirCheck s_reservoir(kWaterPin, &s_app);
@@ -473,19 +475,7 @@ void setup() {
473475

474476
// Run the og3 application setup code.
475477
s_app.setup();
476-
477-
// Initialize Watchdog Timer with 5 second timeout
478-
esp_task_wdt_init(5, true);
479-
esp_task_wdt_add(NULL); // Add current thread (loopTask) to WDT
480-
481-
// Disable WDT during OTA
482-
ArduinoOTA.onStart([]() { esp_task_wdt_delete(NULL); });
483-
ArduinoOTA.onEnd([]() { esp_task_wdt_add(NULL); });
484-
ArduinoOTA.onError([](ota_error_t error) { esp_task_wdt_add(NULL); });
485478
}
486479

487480
// This is called repeaedly when code is running.
488-
void loop() {
489-
s_app.loop();
490-
esp_task_wdt_reset(); // Reset watchdog timer
491-
}
481+
void loop() { s_app.loop(); }

0 commit comments

Comments
 (0)