Include pcb version information

This commit is contained in:
2026-03-02 08:37:44 +01:00
parent 294f1731c9
commit 56b9d04cf8
6 changed files with 28 additions and 9 deletions

View File

@@ -170,12 +170,22 @@ def prebuild(env):
print("Production version style") print("Production version style")
version = env.GetProjectOption('custom_version') 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() now = datetime.utcnow()
env.Append( env.Append(
CPPDEFINES=[ CPPDEFINES=[
('FWVERSION', version), ('FWVERSION', version),
("FWBUILDDATE", f"{now:%Y-%m-%d}"), ("FWBUILDDATE", f"{now:%Y-%m-%d}"),
("FWBUILDTIME", f"{now:%H:%M:%S}"), ("FWBUILDTIME", f"{now:%H:%M:%S}"),
("HWVERSION", pcbvers)
] ]
) )

View File

@@ -28,6 +28,12 @@
#define VERSION STRINGIFY(FWVERSION) #define VERSION STRINGIFY(FWVERSION)
#endif #endif
#ifndef HWVERSION
#define PCBVERSION "*undef*"
#else
#define PCBVERSION STRINGIFY(HWVERSION)
#endif
#ifndef BUILD_DATE #ifndef BUILD_DATE
#define BUILD_DATE STRINGIFY(FWBUILDDATE) #define BUILD_DATE STRINGIFY(FWBUILDDATE)
#endif #endif

View File

@@ -13,7 +13,6 @@ lib_deps =
ESP32Async/AsyncTCP@3.4.9 ESP32Async/AsyncTCP@3.4.9
ESP32Async/ESPAsyncWebServer@3.9.1 ESP32Async/ESPAsyncWebServer@3.9.1
ttlappalainen/NMEA2000-library@4.24 ttlappalainen/NMEA2000-library@4.24
# https://github.com/thooge/NMEA2000.git
robtillaart/SHT31@^0.5.2 robtillaart/SHT31@^0.5.2
# only these files will be emedded into firmware # only these files will be emedded into firmware
@@ -44,7 +43,7 @@ build_flags =
build_unflags = build_unflags =
-std=gnu++11 -std=gnu++11
custom_version = 0.2.0 custom_version = 0.1.1
custom_versionformat = DEVELOP # Version format switch: e.g.DEVELOP=dev<yyyymmdd>|RELEASE=1.0.0 custom_versionformat = DEVELOP # Version format switch: e.g.DEVELOP=dev<yyyymmdd>|RELEASE=1.0.0
[env:obpkp61] [env:obpkp61]

View File

@@ -181,6 +181,7 @@ void webserver_init() {
server.on("/api/status", HTTP_GET, [](AsyncWebServerRequest *request) { server.on("/api/status", HTTP_GET, [](AsyncWebServerRequest *request) {
StaticJsonDocument<512> doc; StaticJsonDocument<512> doc;
doc["version"] = VERSION; doc["version"] = VERSION;
doc["pcbversion"] = PCBVERSION;
int cpu_freq = esp_clk_cpu_freq() / 1000000; int cpu_freq = esp_clk_cpu_freq() / 1000000;
doc["cpuspeed"] = String(cpu_freq) + "MHz"; doc["cpuspeed"] = String(cpu_freq) + "MHz";
char ssid[13]; char ssid[13];
@@ -271,7 +272,7 @@ void webserver_init() {
server.on("/api/update", HTTP_POST, [](AsyncWebServerRequest *request) { server.on("/api/update", HTTP_POST, [](AsyncWebServerRequest *request) {
// the request handler is triggered after the upload has finished... // the request handler is triggered after the upload has finished...
// create the response, add header, and send response // create the response, add header, and send response
LOGD(TAG, "update called"); LOGI(TAG, "update called");
StaticJsonDocument<100> doc; StaticJsonDocument<100> doc;
if (updateSuccess) { if (updateSuccess) {
doc["status"] = "OK"; 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) { }, [](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
// this is the new image upload part // this is the new image upload part
Serial.print("Retrieving firmware image named: ");
Serial.println(filename);
if (index == 0) { if (index == 0) {
LOGI(TAG, "Retrieving firmware image named: %s", filename);
if (! Update.begin(UPDATE_SIZE_UNKNOWN)) { if (! Update.begin(UPDATE_SIZE_UNKNOWN)) {
Update.printError(Serial); Update.printError(Serial);
updateError = "Update.begin() failed"; updateError = "Update.begin() failed";
@@ -310,7 +309,6 @@ void webserver_init() {
updateError = "Update.end() failed"; updateError = "Update.end() failed";
} }
} }
}); });
server.on("/api/devicelist", HTTP_GET, [](AsyncWebServerRequest *request) { server.on("/api/devicelist", HTTP_GET, [](AsyncWebServerRequest *request) {

View File

@@ -118,13 +118,17 @@ if (!window.isSecureContext) {
<span class="label">Firmware type</span> <span class="label">Firmware type</span>
<span class="value status-fwtype">---</span> <span class="value status-fwtype">---</span>
</div> </div>
<div class="row">
<span class="label">Current version</span>
<span class="value status-version">---</span>
</div>
<div class="row"> <div class="row">
<span class="label">Chip type</span> <span class="label">Chip type</span>
<span class="value status-chipid">---</span> <span class="value status-chipid">---</span>
</div> </div>
<div class="row"> <div class="row">
<span class="label">Current version</span> <span class="label">Hardware version</span>
<span class="value status-version">---</span> <span class="value status-pcbversion">---</span>
</div> </div>
<div class="row"> <div class="row">
<span class="label">New Firmware</span> <span class="label">New Firmware</span>

View File

@@ -1435,10 +1435,12 @@
.then(function (result) { .then(function (result) {
let currentType; let currentType;
let currentVersion; let currentVersion;
let currentPcbVersion;
let chipid; let chipid;
forEl('.status-version', function (el) { currentVersion = el.textContent }); forEl('.status-version', function (el) { currentVersion = el.textContent });
forEl('.status-fwtype', function (el) { currentType = el.textContent }); forEl('.status-fwtype', function (el) { currentType = el.textContent });
forEl('.status-chipid', function (el) { chipid = 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'; let confirmText = 'Ready to update firmware?\n';
if (result.chipId != chipid) { if (result.chipId != chipid) {
confirmText += "WARNING: the chipid in the image (" + result.chipId; confirmText += "WARNING: the chipid in the image (" + result.chipId;