Skip to content

Commit

Permalink
Prepare Release 2024.05.07 (merge development into master)
Browse files Browse the repository at this point in the history
  • Loading branch information
schlimmchen authored May 7, 2024
2 parents 3ef789c + 841523f commit ca96cca
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 163 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ jobs:

- name: Build Changelog
id: github_release
uses: mikepenz/release-changelog-builder-action@v3
uses: mikepenz/release-changelog-builder-action@v4
with:
failOnError: true
commitMode: true
Expand All @@ -169,7 +169,7 @@ jobs:
for i in */; do cp ${i}opendtu-onbattery-*.bin ./; done
- name: Create release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
body: ${{steps.github_release.outputs.changelog}}
draft: False
Expand Down
9 changes: 9 additions & 0 deletions include/__compiled_constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

// The referenced values are generated by pio-scripts/auto_firmware_version.py


extern const char *__COMPILED_GIT_HASH__;
extern const char *__COMPILED_GIT_BRANCH__;
// extern const char *__COMPILED_DATE_TIME_UTC_STR__;
76 changes: 65 additions & 11 deletions pio-scripts/auto_firmware_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# Copyright (C) 2022 Thomas Basler and others
#
import os
import pkg_resources

Import("env")
Expand All @@ -16,23 +17,76 @@
from dulwich import porcelain


def get_firmware_specifier_build_flag():
def updateFileIfChanged(filename, content):
mustUpdate = True
try:
fp = open(filename, "rb")
if fp.read() == content:
mustUpdate = False
fp.close()
except:
pass
if mustUpdate:
fp = open(filename, "wb")
fp.write(content)
fp.close()
return mustUpdate


def get_build_version():
try:
build_version = porcelain.describe('.') # '.' refers to the repository root dir
except Exception as err:
print(f"Unexpected {err=}, {type(err)=}")
except:
build_version = "g0000000"
print ("Firmware Revision: " + build_version)
return build_version


def get_build_branch():
try:
branch_name = porcelain.active_branch('.').decode('utf-8') # '.' refers to the repository root dir
except Exception as err:
print(f"Unexpected {err=}, {type(err)=}")
branch_name = "master"
build_flag = "-D AUTO_GIT_HASH=\\\"" + build_version + "\\\" "
build_flag += "-D AUTO_GIT_BRANCH=\\\"" + branch_name + "\\\""
print("Firmware Revision: " + build_version)
print("Firmware build on branch: " + branch_name)
print("Firmware Branch: " + branch_name)
return branch_name


def get_firmware_specifier_build_flag():
build_version = get_build_version()
build_flag = "-D AUTO_GIT_HASH=\\\"" + build_version + "\\\""
build_branch = get_build_branch()
build_flag += " -D AUTO_GIT_BRANCH=\\\"" + branch_name + "\\\""
return (build_flag)

env.Append(
BUILD_FLAGS=[get_firmware_specifier_build_flag()]
)

def do_main():
if 0:
# this results in a full recompilation of the whole project after each commit
env.Append(
BUILD_FLAGS=[get_firmware_specifier_build_flag()]
)
else:
# we just create a .c file containing the needed datas
targetfile = os.path.join(env.subst("$BUILD_DIR"), "__compiled_constants.c")
lines = ""
lines += "/* Generated file within build process - Do NOT edit */\n"

if 0:
# Add the current date and time as string in UTC timezone
from datetime import datetime, timezone
now = datetime.now(tz=timezone.utc)
COMPILED_DATE_TIME_UTC_STR = now.strftime("%Y/%m/%d %H:%M:%S")
lines += 'const char *__COMPILED_DATE_TIME_UTC_STR__ = "%s";\n' % (COMPILED_DATE_TIME_UTC_STR)

if 1:
# Add the description of the current git revision
lines += 'const char *__COMPILED_GIT_HASH__ = "%s";\n' % (get_build_version())
# ... and git branch
lines += 'const char *__COMPILED_GIT_BRANCH__ = "%s";\n' % (get_build_branch())

updateFileIfChanged(targetfile, bytes(lines, "utf-8"))

# Add the created file to the buildfiles - platformio knows how to handle *.c files
env.AppendUnique(PIOBUILDFILES=[targetfile])

do_main()
11 changes: 6 additions & 5 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ build_flags =
-D_TASK_STD_FUNCTION=1
-D_TASK_THREAD_SAFE=1
-DCONFIG_ASYNC_TCP_EVENT_QUEUE_SIZE=128
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=128
-Wall -Wextra -Wunused -Wmisleading-indentation -Wduplicated-cond -Wlogical-op -Wnull-dereference
; Have to remove -Werror because of
; https://github.com/espressif/arduino-esp32/issues/9044 and
Expand All @@ -37,12 +38,12 @@ build_unflags =
-std=gnu++11

lib_deps =
mathieucarbou/ESP Async WebServer @ 2.9.3
bblanchon/ArduinoJson @ ^7.0.4
mathieucarbou/ESP Async WebServer @ 2.9.5
bblanchon/ArduinoJson @ 7.0.4
https://github.com/bertmelis/espMqttClient.git#v1.6.0
nrf24/RF24 @ ^1.4.8
olikraus/U8g2 @ ^2.35.17
buelowp/sunset @ ^1.1.7
nrf24/RF24 @ 1.4.8
olikraus/U8g2 @ 2.35.19
buelowp/sunset @ 1.1.7
https://github.com/arkhipenko/TaskScheduler#testing
https://github.com/coryjfowler/MCP_CAN_lib
plerup/EspSoftwareSerial @ ^8.0.1
Expand Down
3 changes: 2 additions & 1 deletion src/MqttHandlVedirectHass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "MessageOutput.h"
#include "VictronMppt.h"
#include "Utils.h"
#include "__compiled_constants.h"

MqttHandleVedirectHassClass MqttHandleVedirectHass;

Expand Down Expand Up @@ -214,7 +215,7 @@ void MqttHandleVedirectHassClass::createDeviceInfo(JsonObject &object,
object["cu"] = String("http://") + NetworkSettings.localIP().toString();
object["mf"] = "OpenDTU";
object["mdl"] = mpptData.getPidAsString();
object["sw"] = AUTO_GIT_HASH;
object["sw"] = __COMPILED_GIT_HASH__;
}

void MqttHandleVedirectHassClass::publish(const String& subtopic, const String& payload)
Expand Down
3 changes: 2 additions & 1 deletion src/MqttHandleBatteryHass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Configuration.h"
#include "MqttSettings.h"
#include "Utils.h"
#include "__compiled_constants.h"

MqttHandleBatteryHassClass MqttHandleBatteryHass;

Expand Down Expand Up @@ -237,7 +238,7 @@ void MqttHandleBatteryHassClass::createDeviceInfo(JsonObject& object)
object["cu"] = String("http://") + NetworkSettings.localIP().toString();
object["mf"] = "OpenDTU";
object["mdl"] = Battery.getStats()->getManufacturer();
object["sw"] = AUTO_GIT_HASH;
object["sw"] = __COMPILED_GIT_HASH__;
}

void MqttHandleBatteryHassClass::publish(const String& subtopic, const String& payload)
Expand Down
5 changes: 3 additions & 2 deletions src/MqttHandleHass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "NetworkSettings.h"
#include "Utils.h"
#include "defaults.h"
#include "__compiled_constants.h"

MqttHandleHassClass MqttHandleHass;

Expand Down Expand Up @@ -378,7 +379,7 @@ void MqttHandleHassClass::createInverterInfo(JsonDocument& root, std::shared_ptr
getDtuUrl(),
"OpenDTU",
inv->typeName(),
AUTO_GIT_HASH,
__COMPILED_GIT_HASH__,
getDtuUniqueId());
}

Expand All @@ -391,7 +392,7 @@ void MqttHandleHassClass::createDtuInfo(JsonDocument& root)
getDtuUrl(),
"OpenDTU",
"OpenDTU",
AUTO_GIT_HASH);
__COMPILED_GIT_HASH__);
}

void MqttHandleHassClass::createDeviceInfo(
Expand Down
3 changes: 2 additions & 1 deletion src/MqttHandlePowerLimiterHass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "NetworkSettings.h"
#include "MessageOutput.h"
#include "Utils.h"
#include "__compiled_constants.h"

MqttHandlePowerLimiterHassClass MqttHandlePowerLimiterHass;

Expand Down Expand Up @@ -193,7 +194,7 @@ void MqttHandlePowerLimiterHassClass::createDeviceInfo(JsonObject& object)
object["cu"] = String("http://") + NetworkSettings.localIP().toString();
object["mf"] = "OpenDTU";
object["mdl"] = "Dynamic Power Limiter";
object["sw"] = AUTO_GIT_HASH;
object["sw"] = __COMPILED_GIT_HASH__;
}

void MqttHandlePowerLimiterHassClass::publish(const String& subtopic, const String& payload)
Expand Down
3 changes: 2 additions & 1 deletion src/NetworkSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "defaults.h"
#include <ESPmDNS.h>
#include <ETH.h>
#include "__compiled_constants.h"

NetworkSettingsClass::NetworkSettingsClass()
: _loopTask(TASK_IMMEDIATE, TASK_FOREVER, std::bind(&NetworkSettingsClass::loop, this))
Expand Down Expand Up @@ -136,7 +137,7 @@ void NetworkSettingsClass::handleMDNS()

MDNS.addService("http", "tcp", 80);
MDNS.addService("opendtu", "tcp", 80);
MDNS.addServiceTxt("opendtu", "tcp", "git_hash", AUTO_GIT_HASH);
MDNS.addServiceTxt("opendtu", "tcp", "git_hash", __COMPILED_GIT_HASH__);

MessageOutput.println("done");
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/WebApi_prometheus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "NetworkSettings.h"
#include "WebApi.h"
#include <Hoymiles.h>
#include "MessageOutput.h"
#include "__compiled_constants.h"

void WebApiPrometheusClass::init(AsyncWebServer& server, Scheduler& scheduler)
{
Expand All @@ -30,7 +30,7 @@ void WebApiPrometheusClass::onPrometheusMetricsGet(AsyncWebServerRequest* reques
stream->print("# HELP opendtu_build Build info\n");
stream->print("# TYPE opendtu_build gauge\n");
stream->printf("opendtu_build{name=\"%s\",id=\"%s\",version=\"%d.%d.%d\"} 1\n",
NetworkSettings.getHostname().c_str(), AUTO_GIT_HASH, CONFIG_VERSION >> 24 & 0xff, CONFIG_VERSION >> 16 & 0xff, CONFIG_VERSION >> 8 & 0xff);
NetworkSettings.getHostname().c_str(), __COMPILED_GIT_HASH__, CONFIG_VERSION >> 24 & 0xff, CONFIG_VERSION >> 16 & 0xff, CONFIG_VERSION >> 8 & 0xff);

stream->print("# HELP opendtu_platform Platform info\n");
stream->print("# TYPE opendtu_platform gauge\n");
Expand Down Expand Up @@ -143,7 +143,7 @@ void WebApiPrometheusClass::addPanelInfo(AsyncResponseStream* stream, const Stri
return;
}

const CONFIG_T& config = Configuration.get();
const auto& config = Configuration.getInverterConfig(inv->serial());

const bool printHelp = (idx == 0 && channel == 0);
if (printHelp) {
Expand All @@ -155,7 +155,7 @@ void WebApiPrometheusClass::addPanelInfo(AsyncResponseStream* stream, const Stri
idx,
inv->name(),
channel,
config.Inverter[idx].channel[channel].Name);
config->channel[channel].Name);

if (printHelp) {
stream->print("# HELP opendtu_MaxPower panel maximum output power\n");
Expand All @@ -166,7 +166,7 @@ void WebApiPrometheusClass::addPanelInfo(AsyncResponseStream* stream, const Stri
idx,
inv->name(),
channel,
config.Inverter[idx].channel[channel].MaxChannelPower);
config->channel[channel].MaxChannelPower);

if (printHelp) {
stream->print("# HELP opendtu_YieldTotalOffset panel yield offset (for used inverters)\n");
Expand All @@ -177,5 +177,5 @@ void WebApiPrometheusClass::addPanelInfo(AsyncResponseStream* stream, const Stri
idx,
inv->name(),
channel,
config.Inverter[idx].channel[channel].YieldTotalOffset);
config->channel[channel].YieldTotalOffset);
}
13 changes: 3 additions & 10 deletions src/WebApi_sysstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@
#include <Hoymiles.h>
#include <LittleFS.h>
#include <ResetReason.h>

#ifndef AUTO_GIT_HASH
#define AUTO_GIT_HASH ""
#endif

#ifndef AUTO_GIT_BRANCH
#define AUTO_GIT_BRANCH ""
#endif
#include "__compiled_constants.h"

void WebApiSysstatusClass::init(AsyncWebServer& server, Scheduler& scheduler)
{
Expand Down Expand Up @@ -68,8 +61,8 @@ void WebApiSysstatusClass::onSystemStatus(AsyncWebServerRequest* request)
char version[16];
snprintf(version, sizeof(version), "%d.%d.%d", CONFIG_VERSION >> 24 & 0xff, CONFIG_VERSION >> 16 & 0xff, CONFIG_VERSION >> 8 & 0xff);
root["config_version"] = version;
root["git_hash"] = AUTO_GIT_HASH;
root["git_branch"] = AUTO_GIT_BRANCH;
root["git_hash"] = __COMPILED_GIT_HASH__;
root["git_branch"] = __COMPILED_GIT_BRANCH__;
root["pioenv"] = PIOENV;

root["uptime"] = esp_timer_get_time() / 1000000;
Expand Down
16 changes: 8 additions & 8 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@
"mitt": "^3.0.1",
"sortablejs": "^1.15.2",
"spark-md5": "^3.0.2",
"vue": "^3.4.25",
"vue": "^3.4.26",
"vue-i18n": "^9.13.1",
"vue-router": "^4.3.2"
},
"devDependencies": {
"@intlify/unplugin-vue-i18n": "^4.0.0",
"@tsconfig/node18": "^18.2.4",
"@types/bootstrap": "^5.2.10",
"@types/node": "^20.12.7",
"@types/node": "^20.12.10",
"@types/pulltorefreshjs": "^0.1.7",
"@types/sortablejs": "^1.15.8",
"@types/spark-md5": "^3.0.4",
"@vitejs/plugin-vue": "^5.0.4",
"@vue/eslint-config-typescript": "^13.0.0",
"@vue/tsconfig": "^0.5.1",
"eslint": "^9.1.1",
"eslint": "^9.2.0",
"eslint-plugin-vue": "^9.25.0",
"npm-run-all": "^4.1.5",
"pulltorefreshjs": "^0.1.22",
"sass": "^1.75.0",
"terser": "^5.30.4",
"sass": "^1.76.0",
"terser": "^5.31.0",
"typescript": "^5.4.5",
"vite": "^5.2.10",
"vite": "^5.2.11",
"vite-plugin-compression": "^0.5.1",
"vite-plugin-css-injected-by-js": "^3.5.0",
"vue-tsc": "^2.0.14"
"vite-plugin-css-injected-by-js": "^3.5.1",
"vue-tsc": "^2.0.16"
}
}
Loading

0 comments on commit ca96cca

Please sign in to comment.