diff --git a/extra_pre.py b/extra_pre.py index 59de58e..7f02959 100644 --- a/extra_pre.py +++ b/extra_pre.py @@ -170,12 +170,22 @@ def prebuild(env): print("Production version style") version = env.GetProjectOption('custom_version') + # get hardware compiler option + pcbvers = "unknown" + for x in env["BUILD_FLAGS"]: + if not x.startswith('-D'): + continue + opt = x[2:].strip() + if opt.startswith("HARDWARE_"): + pcbvers = x.split('_')[1].lower() + now = datetime.utcnow() env.Append( CPPDEFINES=[ ('FWVERSION', version), ("FWBUILDDATE", f"{now:%Y-%m-%d}"), ("FWBUILDTIME", f"{now:%H:%M:%S}"), + ("HWVERSION", pcbvers) ] ) diff --git a/include/main.h b/include/main.h index 8ac5d4f..bbbb381 100644 --- a/include/main.h +++ b/include/main.h @@ -28,6 +28,12 @@ #define VERSION STRINGIFY(FWVERSION) #endif +#ifndef HWVERSION +#define PCBVERSION "*undef*" +#else +#define PCBVERSION STRINGIFY(HWVERSION) +#endif + #ifndef BUILD_DATE #define BUILD_DATE STRINGIFY(FWBUILDDATE) #endif diff --git a/platformio.ini b/platformio.ini index fb2afdd..e8ead7c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,7 +13,6 @@ lib_deps = ESP32Async/AsyncTCP@3.4.9 ESP32Async/ESPAsyncWebServer@3.9.1 ttlappalainen/NMEA2000-library@4.24 - # https://github.com/thooge/NMEA2000.git robtillaart/SHT31@^0.5.2 # only these files will be emedded into firmware @@ -44,7 +43,7 @@ build_flags = build_unflags = -std=gnu++11 -custom_version = 0.2.0 +custom_version = 0.1.1 custom_versionformat = DEVELOP # Version format switch: e.g.DEVELOP=dev|RELEASE=1.0.0 [env:obpkp61] diff --git a/src/webserver.cpp b/src/webserver.cpp index 29647d4..7f3aa8b 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -181,6 +181,7 @@ void webserver_init() { server.on("/api/status", HTTP_GET, [](AsyncWebServerRequest *request) { StaticJsonDocument<512> doc; doc["version"] = VERSION; + doc["pcbversion"] = PCBVERSION; int cpu_freq = esp_clk_cpu_freq() / 1000000; doc["cpuspeed"] = String(cpu_freq) + "MHz"; char ssid[13]; @@ -271,7 +272,7 @@ void webserver_init() { server.on("/api/update", HTTP_POST, [](AsyncWebServerRequest *request) { // the request handler is triggered after the upload has finished... // create the response, add header, and send response - LOGD(TAG, "update called"); + LOGI(TAG, "update called"); StaticJsonDocument<100> doc; if (updateSuccess) { doc["status"] = "OK"; @@ -289,10 +290,8 @@ void webserver_init() { } }, [](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) { // this is the new image upload part - Serial.print("Retrieving firmware image named: "); - Serial.println(filename); - if (index == 0) { + LOGI(TAG, "Retrieving firmware image named: %s", filename); if (! Update.begin(UPDATE_SIZE_UNKNOWN)) { Update.printError(Serial); updateError = "Update.begin() failed"; @@ -310,7 +309,6 @@ void webserver_init() { updateError = "Update.end() failed"; } } - }); server.on("/api/devicelist", HTTP_GET, [](AsyncWebServerRequest *request) { diff --git a/web/index.html b/web/index.html index 656ea7d..baa4677 100644 --- a/web/index.html +++ b/web/index.html @@ -118,13 +118,17 @@ if (!window.isSecureContext) { Firmware type --- +
+ Current version + --- +
Chip type ---
- Current version - --- + Hardware version + ---
New Firmware diff --git a/web/index.js b/web/index.js index c50cacf..639d3bf 100644 --- a/web/index.js +++ b/web/index.js @@ -1435,10 +1435,12 @@ .then(function (result) { let currentType; let currentVersion; + let currentPcbVersion; let chipid; forEl('.status-version', function (el) { currentVersion = el.textContent }); forEl('.status-fwtype', function (el) { currentType = el.textContent }); forEl('.status-chipid', function (el) { chipid = el.textContent }); + forEl('.status-pcbversion', function (el) { currentPcbVersion = el.textContent }); let confirmText = 'Ready to update firmware?\n'; if (result.chipId != chipid) { confirmText += "WARNING: the chipid in the image (" + result.chipId;