Skip to content

Commit

Permalink
feat: show firmware version on UI
Browse files Browse the repository at this point in the history
  • Loading branch information
adlerre committed Jan 8, 2025
1 parent e4ba98a commit b200a46
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ void deepSleep(uint32_t ms) {
esp_deep_sleep_start();
}

String getVersion() {
auto version = String(BUILD_GIT_BRANCH);
if (!version.startsWith("v")) {
version += " (" + String(BUILD_GIT_COMMIT_HASH) + ")";
}
return version;
}

void WiFiAPStart(WiFiEvent_t event, WiFiEventInfo_t info) {
wifiAPStarted = true;
DEBUG_PORT.println("WiFi AP started.");
Expand Down Expand Up @@ -173,6 +181,10 @@ void startWiFiAP() {
}

void startHttpServer() {
server.on("/api/version", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(200, "text/plain", getVersion());
});

server.on("/api/settings", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(200, "application/json", Settings.buildJson().c_str());
});
Expand Down
7 changes: 7 additions & 0 deletions ui/src/app/components/deviceInfo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
-->

<div id="deviceInfo">
<fieldset *ngIf="version">
<legend>Firmware</legend>
<dl class="row">
<dt class="col-sm-3">Version</dt>
<dd class="col-sm-9">{{ version }}</dd>
</dl>
</fieldset>
<fieldset *ngIf="wifiInfo">
<legend>WiFi Info</legend>
<dl class="row">
Expand Down
11 changes: 8 additions & 3 deletions ui/src/app/components/deviceInfo.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ const testModemInfo: ModemInfo = {

export class MockApiService {

version() {
return of("1.0.0");
}

wifiInfo() {
return of<WifiInfo>(testWiFiInfo);
}
Expand Down Expand Up @@ -84,8 +88,9 @@ describe("DeviceInfoComponent", () => {
expect(getElement("#deviceInfo")).toBeTruthy();

const legends = getElements("legend");
expect(legends.length).toBe(2);
expect(legends[0].textContent).toBe("WiFi Info");
expect(legends[1].textContent).toBe("Modem Info");
expect(legends.length).toBe(3);
expect(legends[0].textContent).toBe("Firmware");
expect(legends[1].textContent).toBe("WiFi Info");
expect(legends[2].textContent).toBe("Modem Info");
});
});
3 changes: 3 additions & 0 deletions ui/src/app/components/deviceInfo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { ApiService } from "../services/api.service";
})
export class DeviceInfoComponent implements OnInit {

version: string | undefined;

wifiInfo: WifiInfo | undefined;

modemInfo: ModemInfo | undefined;
Expand All @@ -34,6 +36,7 @@ export class DeviceInfoComponent implements OnInit {
}

ngOnInit(): void {
this.$api.version().subscribe(ver => this.version = ver);
this.$api.wifiInfo().subscribe((wi) => this.wifiInfo = wi);
this.$api.modemInfo().subscribe((mi) => this.modemInfo = mi);
}
Expand Down
8 changes: 5 additions & 3 deletions ui/src/app/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@

import { Injectable } from "@angular/core";
import { HttpClient, HttpEvent, HttpEventType, HttpHeaders, HttpRequest } from "@angular/common/http";
import { Configuration, DiscoveredDevices, ModemInfo, Settings, WifiInfo } from "../definitions";
import { Configuration, DiscoveredDevices, ModemInfo, OBDState, OTAMode, Settings, WifiInfo } from "../definitions";
import { distinctUntilChanged, last, map, Subject } from "rxjs";
import { OTAMode } from "../definitions/ota";
import { OBDState } from "../definitions/obdStates";

@Injectable()
export class ApiService {
Expand All @@ -36,6 +34,10 @@ export class ApiService {
return this.$http.post("/api/reboot?reboot=true", {}, {responseType: "text"});
}

version() {
return this.$http.get("/api/version", {responseType: "text"});
}

wifiInfo() {
return this.$http.get<WifiInfo>("/api/wifi");
}
Expand Down

0 comments on commit b200a46

Please sign in to comment.