Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions build_and_flash.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand All @@ -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; }
Expand All @@ -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..."
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
68 changes: 56 additions & 12 deletions src/CommandLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include <ESPAsyncWebServer.h>
#include <cmath>
#include <cstring>
#include <Preferences.h>

Preferences preferences;


void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client,
AwsEventType type, void *arg, uint8_t *data, size_t len) {
Expand All @@ -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: {

Expand Down Expand Up @@ -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<double>();
preferences.putDouble("pidKp", pidKp);
}
if (!doc["pidKi"].isNull()) {
double pidKi = doc["pidKi"].as<double>();
preferences.putDouble("pidKi", pidKi);
}
if (!doc["pidKd"].isNull()) {
double pidKd = doc["pidKd"].as<double>();
preferences.putDouble("pidKd", pidKd);
}
if (!doc["cooldownFanSpeed"].isNull()) {
long cooldownFanSpeed = doc["cooldownFanSpeed"].as<long>();
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>();
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>();
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>();
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
Expand All @@ -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);
}
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down