Add version info

Signed-off-by: YoungSoo Shin <shinys000114@gmail.com>
This commit is contained in:
2025-09-24 11:22:49 +09:00
parent 4bbf1339f1
commit 39ca2d205a
8 changed files with 64 additions and 3 deletions

View File

@@ -87,5 +87,7 @@ void start_webserver(void)
register_ws_endpoint(server);
register_control_endpoint(server);
register_reboot_endpoint(server);
register_version_endpoint(server);
init_status_monitor();
}

View File

@@ -15,5 +15,6 @@ void register_control_endpoint(httpd_handle_t server);
void push_data_to_ws(const uint8_t* data, size_t len);
void register_reboot_endpoint(httpd_handle_t server);
esp_err_t change_baud_rate(int baud_rate);
void register_version_endpoint(httpd_handle_t server);
#endif // ODROID_REMOTE_HTTP_WEBSERVER_H

View File

@@ -77,3 +77,19 @@ void register_reboot_endpoint(httpd_handle_t server)
.uri = "/api/reboot", .method = HTTP_POST, .handler = reboot_post_handler, .user_ctx = NULL};
httpd_register_uri_handler(server, &post_uri);
}
static esp_err_t version_get_handler(httpd_req_t* req)
{
httpd_resp_set_type(req, "application/json");
char buf[100];
sprintf(buf, "{\"version\": \"%s\"}", VERSION_HASH);
httpd_resp_send(req, buf, strlen(buf));
return ESP_OK;
}
void register_version_endpoint(httpd_handle_t server)
{
httpd_uri_t post_uri = {
.uri = "/api/version", .method = HTTP_GET, .handler = version_get_handler, .user_ctx = NULL};
httpd_register_uri_handler(server, &post_uri);
}

View File

@@ -130,9 +130,12 @@
</div>
</main>
<footer class="bg-body-tertiary text-center p-3">
<a href="https://www.hardkernel.com/" target="_blank" class="link-secondary">Hardkernel</a> |
<a href="https://wiki.odroid.com/start" target="_blank" class="link-secondary">Wiki</a>
<footer class="bg-body-tertiary text-center p-3 position-relative">
<a href="https://www.hardkernel.com/" target="_blank" class="link-secondary text-decoration-none">Hardkernel</a> |
<a href="https://wiki.odroid.com/start" target="_blank" class="link-secondary text-decoration-none">Wiki</a>
<div class="position-absolute end-0 top-50 translate-middle-y pe-3">
<small class="text-muted" id="version-info"></small>
</div>
</footer>
<!-- Settings Modal -->

View File

@@ -110,3 +110,14 @@ export async function postControlCommand(command) {
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
return response;
}
/**
* Fetches the firmware version from the server.
* @returns {Promise<Object>} A promise that resolves to an object containing the version.
* @throws {Error} Throws an error if the network request fails.
*/
export async function fetchVersion() {
const response = await fetch('/api/version');
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
return await response.json();
}

View File

@@ -86,3 +86,6 @@ export const mainValueSpan = document.getElementById('main-current-limit-value')
export const usbSlider = document.getElementById('usb-current-limit-slider');
export const usbValueSpan = document.getElementById('usb-current-limit-value');
export const currentLimitApplyButton = document.getElementById('current-limit-apply-button');
// --- Footer ---
export const versionInfo = document.getElementById('version-info');

View File

@@ -12,6 +12,7 @@ import './style.css';
// --- Module Imports -- -
import {StatusMessage} from './proto.js';
import * as api from './api.js';
import {initWebSocket} from './websocket.js';
import {setupTerminal, term} from './terminal.js';
import {
@@ -21,6 +22,7 @@ import {
updateSensorUI,
updateSwitchStatusUI,
updateUptimeUI,
updateVersionUI,
updateWebsocketStatus,
updateWifiStatusUI
} from './ui.js';
@@ -112,6 +114,18 @@ function onWsMessage(event) {
// --- Application Initialization ---
async function initializeVersion() {
try {
const versionData = await api.fetchVersion();
if (versionData && versionData.version) {
updateVersionUI(versionData.version);
}
} catch (error) {
console.error('Error fetching version:', error);
updateVersionUI('N/A');
}
}
function connect() {
updateControlStatus();
initWebSocket({ onOpen: onWsOpen, onClose: onWsClose, onMessage: onWsMessage });
@@ -120,6 +134,7 @@ function connect() {
function initialize() {
initUI();
setupTerminal();
initializeVersion();
const savedTheme = localStorage.getItem('theme') || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
applyTheme(savedTheme);

View File

@@ -110,6 +110,16 @@ export function updateWifiStatusUI(data) {
}
}
/**
* Updates the version information in the footer.
* @param {string} version - The firmware version string.
*/
export function updateVersionUI(version) {
if (version) {
dom.versionInfo.textContent = `${version}`;
}
}
/**
* Initiates a Wi-Fi scan and updates the settings modal with the results.
*/