diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..71a74b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Bestellung.xlsx \ No newline at end of file diff --git a/Software/data/index.htm b/Software/data/index.htm index 9b81571..8face8c 100644 --- a/Software/data/index.htm +++ b/Software/data/index.htm @@ -41,6 +41,7 @@
  • Öltank
  • Wartung
  • Systeminfo
  • +
  • Update
  • @@ -341,20 +342,6 @@

    Systeminfo


    -

    Firmware-Info

    -

    - - - - - - - - -
    Parameter - Value -
    Version%SW_VERSION%
    -

    Einstellungen

    @@ -462,6 +449,45 @@

    + +
    +

    Firmware Update

    +
    +

    Version-Info

    +

    +

    + + + + + + + + + +
    Firmware Version%SW_VERSION%
    Flash Version%FS_VERSION%
    +

    +
    +

    Firmware-Update

    +

    +

    +
    + +
    +
    + +
    +
    +
    + +
    +
    +
    + +

    +
    +
    diff --git a/Software/data/version b/Software/data/version new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/Software/data/version @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/Software/platformio.ini b/Software/platformio.ini index 25c6a4c..a00d74b 100644 --- a/Software/platformio.ini +++ b/Software/platformio.ini @@ -31,10 +31,10 @@ build_flags = -DADMIN_PASSWORD=${wifi_cred.admin_password} -DWIFI_AP_PASSWORD=${wifi_cred.wifi_ap_password} -DWIFI_AP_IP_GW=10,0,0,1 - ;-DFEATURE_ENABLE_WIFI_CLIENT + -DFEATURE_ENABLE_WIFI_CLIENT -DFEATURE_ENABLE_REMOTE_DEBUG - -DFEATURE_ENABLE_CAN - -DFEATURE_ENABLE_GPS + ;-DFEATURE_ENABLE_CAN + ;-DFEATURE_ENABLE_GPS board_build.filesystem = littlefs diff --git a/Software/src/common.h b/Software/src/common.h index c6bbf72..01e1e89 100644 --- a/Software/src/common.h +++ b/Software/src/common.h @@ -21,6 +21,8 @@ #define OTA_DELAY 50 // ticks -> 10ms / tick #endif +#define ATOMIC_FS_UPDATE + #ifndef ADMIN_PASSWORD #error "You need to define ADMIN_PASSWORD for OTA-Update" #endif diff --git a/Software/src/dtc.h b/Software/src/dtc.h index d0b2ecd..9e9f575 100644 --- a/Software/src/dtc.h +++ b/Software/src/dtc.h @@ -12,6 +12,7 @@ typedef enum DTCNums_e DTC_EEPROM_CFG_BAD, DTC_EEPROM_PDS_BAD, DTC_EEPROM_VERSION_BAD, + DTC_FLASHFS_ERROR, #ifdef FEATURE_ENABLE_GPS DTC_NO_GPS_SERIAL, #endif diff --git a/Software/src/globals.h b/Software/src/globals.h index fd6111f..4e6f199 100644 --- a/Software/src/globals.h +++ b/Software/src/globals.h @@ -29,6 +29,7 @@ typedef struct Globals_s char systemStatustxt[16] = ""; uint8_t purgePulses = 0; eEERequest requestEEAction = EE_IDLE; + char DeviceName[33]; } Globals_t; extern Globals_t globals; diff --git a/Software/src/main.cpp b/Software/src/main.cpp index 255f017..83b1d84 100644 --- a/Software/src/main.cpp +++ b/Software/src/main.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include @@ -41,7 +40,6 @@ ESP8266WiFiMulti wifiMulti; #endif bool startSetupMode = false; -char DeviceName[33]; Globals_t globals; uint32_t TravelDistance_highRes; @@ -84,14 +82,14 @@ Ticker EEPROMCyclicPDSTicker(EEPROMCyclicPDS_callback, 60000, 0, MILLIS); void setup() { system_update_cpu_freq(SYS_CPU_80MHZ); - snprintf(DeviceName, 32, HOST_NAME, ESP.getChipId()); + snprintf(globals.DeviceName, 32, HOST_NAME, ESP.getChipId()); WiFi.persistent(false); ClearAllDTC(); // Init DTC-Storage #ifdef FEATURE_ENABLE_WIFI_CLIENT WiFi.mode(WIFI_STA); - WiFi.setHostname(DeviceName); + WiFi.setHostname(globals.DeviceName); wifiMulti.addAP(QUOTE(WIFI_SSID), QUOTE(WIFI_PASSWORD)); WiFiMaintainConnectionTicker.start(); #else @@ -102,7 +100,7 @@ void setup() Serial.setDebugOutput(true); Serial.println("Souko's ChainLube Mk1"); - Serial.println(DeviceName); + Serial.println(globals.DeviceName); InitEEPROM(); GetConfig_EEPROM(); @@ -141,10 +139,7 @@ void setup() pinMode(GPIO_PUMP, OUTPUT); #ifdef FEATURE_ENABLE_REMOTE_DEBUG - if (MDNS.begin(DeviceName)) - MDNS.addService("telnet", "tcp", 23); - - Debug.begin(DeviceName); + Debug.begin(globals.DeviceName); Debug.setResetCmdEnabled(true); Debug.showProfiler(false); Debug.showColors(true); @@ -157,7 +152,7 @@ void setup() #endif ArduinoOTA.setPort(8266); - ArduinoOTA.setHostname(DeviceName); + ArduinoOTA.setHostname(globals.DeviceName); ArduinoOTA.setPassword(QUOTE(ADMIN_PASSWORD)); ArduinoOTA.onStart([]() @@ -302,7 +297,7 @@ void RemoteDebug_formatPersistence() void RemotDebug_printSystemInfo() { debugA("Souko's ChainOiler Mk1"); - debugA("Hostname: %s", DeviceName); + debugA("Hostname: %s", globals.DeviceName); FlashMode_t ideMode = ESP.getFlashChipMode(); debugA("Sdk version: %s", ESP.getSdkVersion()); @@ -719,7 +714,7 @@ void toggleWiFiAP(boolean shutdown) { WiFi.mode(WIFI_AP); WiFi.softAPConfig(IPAddress(WIFI_AP_IP_GW), IPAddress(WIFI_AP_IP_GW), IPAddress(255, 255, 255, 0)); - WiFi.softAP(DeviceName, QUOTE(WIFI_AP_PASSWORD)); + WiFi.softAP(globals.DeviceName, QUOTE(WIFI_AP_PASSWORD)); #ifdef FEATURE_ENABLE_WIFI_CLIENT WiFiMaintainConnectionTicker.stop(); debugV("WiFi AP started, stopped Maintain-Timer"); diff --git a/Software/src/webui.cpp b/Software/src/webui.cpp index ac42c37..5111f44 100644 --- a/Software/src/webui.cpp +++ b/Software/src/webui.cpp @@ -8,21 +8,30 @@ String processor(const String &var); void WebserverPOST_Callback(AsyncWebServerRequest *request); void WebserverNotFound_Callback(AsyncWebServerRequest *request); void Webserver_Callback(AsyncWebServerRequest *request); +void WebserverFirmwareUpdate_Callback(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final); +uint32_t GetFlashVersion(); void initWebUI() { if (!LittleFS.begin()) { Serial.println("An Error has occurred while mounting LittleFS"); + MaintainDTC(DTC_FLASHFS_ERROR, true); return; } + MDNS.begin(globals.DeviceName); + MDNS.addService("telnet", "tcp", 23); + MDNS.addService("http", "tcp", 80); + webServer.serveStatic("/static/", LittleFS, "/static/").setCacheControl("max-age=360000"); webServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { request->redirect("/index.htm"); }); webServer.onNotFound(WebserverNotFound_Callback); webServer.on("/index.htm", HTTP_GET, Webserver_Callback); webServer.on("/post.htm", HTTP_POST, WebserverPOST_Callback); + webServer.on( + "/doUpdate", HTTP_POST, [](AsyncWebServerRequest *request) {}, WebserverFirmwareUpdate_Callback); webServer.begin(); } @@ -176,6 +185,8 @@ String processor(const String &var) sprintf(buffer, "%d.%02d", SW_VERSION_MAJOR, SW_VERSION_MINOR); return String(buffer); } + if (var == "FS_VERSION") + return String(GetFlashVersion()); if (var == "PLACEHOLDER") return "placeholder"; @@ -275,4 +286,65 @@ void WebserverPOST_Callback(AsyncWebServerRequest *request) void WebserverNotFound_Callback(AsyncWebServerRequest *request) { request->send(404, "text/html", "Not found"); -} \ No newline at end of file +} + +uint32_t GetFlashVersion() +{ + + char buffer[20]; + File this_file = LittleFS.open("version", "r"); + if (!this_file) + { // failed to open the file, retrn empty result + return 0; + } + while (this_file.available()) + { + this_file.readBytesUntil('\r', buffer, sizeof(buffer)); + } + this_file.close(); + return atoi(buffer); +} + +void WebserverFirmwareUpdate_Callback(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final) +{ + + if (!index) + { + Serial.println("Update"); + size_t content_len = request->contentLength(); + // if filename includes spiffs, update the spiffs partition + int cmd = (filename.indexOf(".fs") > -1) ? U_FS : U_FLASH; + Update.runAsync(true); + if (!Update.begin(content_len, cmd)) + { + Update.printError(Serial); + } + } + + if (Update.write(data, len) != len) + { + Update.printError(Serial); + } + else + { + Serial.printf("Progress: %d%%\n", (Update.progress() * 100) / Update.size()); + } + + if (final) + { + AsyncWebServerResponse *response = request->beginResponse(302, "text/plain", "Please wait while the device reboots"); + response->addHeader("Refresh", "20"); + response->addHeader("Location", "/"); + request->send(response); + if (!Update.end(true)) + { + Update.printError(Serial); + } + else + { + Serial.println("Update complete"); + Serial.flush(); + ESP.restart(); + } + } +} diff --git a/Software/src/webui.h b/Software/src/webui.h index 55d57a5..772c5dd 100644 --- a/Software/src/webui.h +++ b/Software/src/webui.h @@ -6,6 +6,9 @@ #include #include #include +#include +#include + #include "config.h" #include "globals.h" #include "dtc.h"