From f99dec19c9dde23663d6c79b8a68b1ddcc46e26f Mon Sep 17 00:00:00 2001 From: Matthias Blankertz Date: Sun, 21 Dec 2025 20:59:16 +0100 Subject: [PATCH] feat: store git version in fw and show in web ui Signed-off-by: Matthias Blankertz --- software/boards/RPI_PICO_W/board.c | 29 +++++++++++++++++++ .../boards/RPI_PICO_W/mpconfigboard.cmake | 19 ++++++++++++ software/frontend/index.html | 25 +++++++++++++++- software/src/webserver.py | 10 +++++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 software/boards/RPI_PICO_W/board.c diff --git a/software/boards/RPI_PICO_W/board.c b/software/boards/RPI_PICO_W/board.c new file mode 100644 index 0000000..bc4ec6a --- /dev/null +++ b/software/boards/RPI_PICO_W/board.c @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2025 Matthias Blankertz + +#include "py/obj.h" +#include "py/runtime.h" +#include "py/objstr.h" + +#ifndef TONBERRY_GIT_REVISION +#define TONBERRY_GIT_REVISION "unknown" +#endif +#ifndef TONBERRY_VERSION +#define TONBERRY_VERSION "unknown" +#endif + +static const MP_DEFINE_STR_OBJ(tonberry_git_revision_obj, TONBERRY_GIT_REVISION); +static const MP_DEFINE_STR_OBJ(tonberry_version_obj, TONBERRY_VERSION); + +static const mp_rom_map_elem_t board_module_globals_table[] = { + {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_board)}, + {MP_ROM_QSTR(MP_QSTR_revision), MP_ROM_PTR(&tonberry_git_revision_obj)}, + {MP_ROM_QSTR(MP_QSTR_version), MP_ROM_PTR(&tonberry_version_obj)}, +}; +static MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); + +const mp_obj_module_t board_cmodule = { + .base = {&mp_type_module}, + .globals = (mp_obj_dict_t *)&board_module_globals, +}; +MP_REGISTER_MODULE(MP_QSTR_board, board_cmodule); diff --git a/software/boards/RPI_PICO_W/mpconfigboard.cmake b/software/boards/RPI_PICO_W/mpconfigboard.cmake index 937e648..276d917 100644 --- a/software/boards/RPI_PICO_W/mpconfigboard.cmake +++ b/software/boards/RPI_PICO_W/mpconfigboard.cmake @@ -20,3 +20,22 @@ set(GEN_PINS_CSV_ARG --board-csv "${GEN_PINS_BOARD_CSV}") add_link_options("-Wl,--print-memory-usage") set(PICO_USE_FASTEST_SUPPORTED_CLOCK 1) + +find_program(GIT git) + +execute_process(COMMAND ${GIT} rev-parse HEAD + WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" + OUTPUT_VARIABLE TONBERRY_GIT_REVISION + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +execute_process(COMMAND ${GIT} describe --match 'v*' --always + WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" + OUTPUT_VARIABLE TONBERRY_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +set(MICROPY_SOURCE_BOARD "${CMAKE_CURRENT_LIST_DIR}/board.c") +set(MICROPY_DEF_BOARD + TONBERRY_GIT_REVISION="${TONBERRY_GIT_REVISION}" + TONBERRY_VERSION="${TONBERRY_VERSION}") diff --git a/software/frontend/index.html b/software/frontend/index.html index 0184d89..20f2a22 100644 --- a/software/frontend/index.html +++ b/software/frontend/index.html @@ -131,6 +131,12 @@ list-style: none; } + .footer { + font-size: x-small; + color: gray; + margin-top: 20px; + } + @@ -257,7 +263,17 @@ - + diff --git a/software/src/webserver.py b/software/src/webserver.py index ea7f3cb..78803f3 100644 --- a/software/src/webserver.py +++ b/software/src/webserver.py @@ -4,11 +4,14 @@ Copyright (c) 2024-2025 Stefan Kratochwil ''' import asyncio +import board import hwconfig import json import machine +import network import os import time +import ubinascii from array import array from microdot import Microdot, redirect, send_file, Request @@ -270,3 +273,10 @@ async def reboot(request, method): else: return 'method not supported', 400 return '', 204 + + +@webapp.route('/api/v1/info', methods=['GET']) +async def get_info(request): + mac = ubinascii.hexlify(network.WLAN().config('mac'), ':').decode() + return {'version': board.version, + 'mac': mac}