diff --git a/build_and_flash.sh b/build_and_flash.sh index 381c9fc..4082742 100755 --- a/build_and_flash.sh +++ b/build_and_flash.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # The script will build and flash Yaeger to your ESP device. # Ensure this script is executable (`chmod +x build_and_flash.sh`) and has the correct permissions. @@ -12,7 +13,7 @@ # # If you cloned the project from GitHub, ensure all folders have the correct permissions: # chmod -R u+rwX . -# The SPIFFS filesystem might fail if permissions are incorrect. +# The LittleFS filesystem might fail if permissions are incorrect. # Step 0: Check for required parameter (s3 or s3-mini) if [[ -z "$1" ]]; then @@ -30,6 +31,19 @@ fi echo "Using PlatformIO environment: $PIO_ENV" + +read -p "Choose frontend (r for reyaeger, empty for classic): " frontend + +if [ $frontend = 'r' ]; then + +echo "reyaeger download"; +curl -L https://github.com/RobTS/reyaeger/releases/latest/download/reyaeger.zip > reyaeger.zip +rm -rf data +mkdir data +unzip -d ./data ./reyaeger.zip + +else + # Step 1: Navigate to the miniweb directory echo "Navigating to miniweb..." cd miniweb || { echo "miniweb folder not found!"; exit 1; } @@ -46,14 +60,15 @@ npm run build || { echo "npm build failed!"; exit 1; } echo "Returning to the project root..." cd .. || exit 1 +fi # Step 5: Erase the device memory (optional but recommended) echo "Erasing the device memory..." pio run -e "$PIO_ENV" -t erase || { echo "Memory erase failed!"; exit 1; } -# Step 6: Build and upload the SPIFFS filesystem -echo "Building and uploading SPIFFS filesystem..." -pio run -e "$PIO_ENV" -t buildfs -t uploadfs || { echo "SPIFFS upload failed!"; exit 1; } +# Step 6: Build and upload the LittleFS filesystem +echo "Building and uploading LittleFS filesystem..." +pio run -e "$PIO_ENV" -t buildfs -t uploadfs || { echo "LittleFS upload failed!"; exit 1; } # Step 7: Build and upload the firmware echo "Building and uploading the firmware..." diff --git a/platformio.ini b/platformio.ini index e3cf1e4..c601e6a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -28,7 +28,7 @@ build_flags = ; -D ARDUINO_USB_CDC_ON_BOOT=1 lib_compat_mode = strict lib_deps = - ayushsharma82/ElegantOTA @ ^3.1.4 + ayushsharma82/ElegantOTA ArduinoJson Adafruit NeoPixel adafruit/Adafruit MAX31855 library diff --git a/src/CommandLoop.cpp b/src/CommandLoop.cpp index 54f77a8..0ec45d8 100644 --- a/src/CommandLoop.cpp +++ b/src/CommandLoop.cpp @@ -6,6 +6,10 @@ #include #include #include +#include + +Preferences preferences; + void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) { @@ -20,7 +24,7 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, logf("[%u] Disconnected!\n", client->id()); // turn off heater and set fan to 100% setHeaterPower(0); - setFanSpeed(100); + setFanSpeed(preferences.getLong("coolFanSpeed", 65)); } break; case WS_EVT_DATA: { @@ -80,17 +84,54 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, setFanSpeed(val); } + // Safeguard to prevent heater fuse blowout + if (getHeaterPower() > 0 && getFanSpeed() <= 30) { + setFanSpeed(30); + } + + if (command != NULL && strncmp(command, "setPreferences", 14) == 0) { + if (!doc["pidKp"].isNull()) { + double pidKp = doc["pidKp"].as(); + preferences.putDouble("pidKp", pidKp); + } + if (!doc["pidKi"].isNull()) { + double pidKi = doc["pidKi"].as(); + preferences.putDouble("pidKi", pidKi); + } + if (!doc["pidKd"].isNull()) { + double pidKd = doc["pidKd"].as(); + preferences.putDouble("pidKd", pidKd); + } + if (!doc["cooldownFanSpeed"].isNull()) { + long cooldownFanSpeed = doc["cooldownFanSpeed"].as(); + logf("cooldownFanSpeed: %d\n", cooldownFanSpeed); + preferences.putLong("coolFanSpeed", cooldownFanSpeed); + } + } + + if (command != NULL && (strncmp(command, "setPreferences", 14) == 0 || strncmp(command, "getPreferences", 14) == 0)) { + JsonObject root = doc.to(); + JsonObject data = root.createNestedObject("data"); + root["id"] = ln_id; + data["type"] = "preferences"; + data["pidKp"] = preferences.getDouble("pidKp", 1.0); + data["pidKi"] = preferences.getDouble("pidKi", 0.1); + data["pidKd"] = preferences.getDouble("pidKd", 0.01); + data["cooldownFanSpeed"] = preferences.getLong("coolFanSpeed", 65); + } + if (command != NULL && strncmp(command, "getData", 7) == 0) { - JsonObject root = doc.to(); - JsonObject data = root.createNestedObject("data"); - root["id"] = ln_id; - float etbt[3]; - getETBTReadings(etbt); - data["ET"] = etbt[0]; // Med_ExhaustTemp.getMedian() - data["BT"] = etbt[1]; // Med_BeanTemp.getMedian(); - data["Amb"] = etbt[2]; - data["BurnerVal"] = getHeaterPower(); // float(DimmerVal); - data["FanVal"] = getFanSpeed(); + JsonObject root = doc.to(); + JsonObject data = root.createNestedObject("data"); + root["id"] = ln_id; + float etbt[3]; + getETBTReadings(etbt); + data["type"] = "status"; + data["ET"] = etbt[0]; // Med_ExhaustTemp.getMedian() + data["BT"] = etbt[1]; // Med_BeanTemp.getMedian(); + data["Amb"] = etbt[2]; + data["BurnerVal"] = getHeaterPower(); // float(DimmerVal); + data["FanVal"] = getFanSpeed(); } char buffer[200]; // create temp buffer @@ -112,4 +153,7 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, } } -void setupMainLoop(AsyncWebSocket *ws) { ws->onEvent(onWsEvent); } +void setupMainLoop(AsyncWebSocket *ws) { + preferences.begin("preferences"); + ws->onEvent(onWsEvent); +} diff --git a/src/main.cpp b/src/main.cpp index 18b1be7..1d44057 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -79,6 +79,8 @@ void setup(void) { Serial.println("LittleFS failed"); } server.serveStatic("/", LittleFS, "/").setDefaultFile("index.html"); + server.serveStatic("/settings", LittleFS, "/").setDefaultFile("index.html"); + server.serveStatic("/editor", LittleFS, "/").setDefaultFile("index.html"); ElegantOTA.begin(&server); // Start ElegantOTA // ElegantOTA callbacks