diff --git a/auto_firmware_version.py b/auto_firmware_version.py new file mode 100644 index 0000000..9d6a8ae --- /dev/null +++ b/auto_firmware_version.py @@ -0,0 +1,22 @@ +import pkg_resources + +Import("env") + +required_pkgs = {'dulwich'} +installed_pkgs = {pkg.key for pkg in pkg_resources.working_set} +missing_pkgs = required_pkgs - installed_pkgs + +if missing_pkgs: + env.Execute('$PYTHONEXE -m pip install dulwich --global-option="--pure"') + +from dulwich import porcelain + +def get_firmware_specifier_build_flag(): + build_version = porcelain.describe('.') # '.' refers to the repository root dir + build_flag = "-D AUTO_GIT_HASH=\\\"" + build_version + "\\\"" + print ("Firmware Revision: " + build_version) + return (build_flag) + +env.Append( + BUILD_FLAGS=[get_firmware_specifier_build_flag()] +) \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index db2d053..84645fa 100644 --- a/platformio.ini +++ b/platformio.ini @@ -28,6 +28,9 @@ lib_deps = https://github.com/marvinroger/async-mqtt-client.git nrf24/RF24 @ ^1.4.2 +extra_scripts = + pre:auto_firmware_version.py + board = esp32dev board_build.partitions = partitions_custom.csv board_build.filesystem = littlefs diff --git a/src/WebApi_sysstatus.cpp b/src/WebApi_sysstatus.cpp index 65175e9..bf57579 100644 --- a/src/WebApi_sysstatus.cpp +++ b/src/WebApi_sysstatus.cpp @@ -5,6 +5,10 @@ #include #include +#ifndef AUTO_GIT_HASH +#define AUTO_GIT_HASH "" +#endif + void WebApiSysstatusClass::init(AsyncWebServer* server) { using namespace std::placeholders; @@ -51,6 +55,7 @@ void WebApiSysstatusClass::onSystemStatus(AsyncWebServerRequest* request) char version[16]; sprintf(version, "%d.%d.%d", CONFIG_VERSION >> 24 & 0xff, CONFIG_VERSION >> 16 & 0xff, CONFIG_VERSION >> 8 & 0xff); root[F("firmware_version")] = version; + root[F("git_hash")] = AUTO_GIT_HASH; root[F("uptime")] = esp_timer_get_time() / 1000000; diff --git a/webapp/src/components/partials/FirmwareInfo.vue b/webapp/src/components/partials/FirmwareInfo.vue index e487777..709b50a 100644 --- a/webapp/src/components/partials/FirmwareInfo.vue +++ b/webapp/src/components/partials/FirmwareInfo.vue @@ -19,6 +19,10 @@ Firmware Version {{ systemDataList.firmware_version }} + + Git Hash + {{ systemDataList.git_hash }} + Reset Reason CPU 0 {{ systemDataList.resetreason_0 }}