Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream'
Browse files Browse the repository at this point in the history
  • Loading branch information
OFreddy committed May 8, 2024
2 parents 0375d86 + 1f1227f commit 2b25350
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 158 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,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 @@ -138,7 +138,7 @@ jobs:
for i in */; do cp ${i}opendtu-*.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
8 changes: 8 additions & 0 deletions include/__compiled_constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// 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_DATE_TIME_UTC_STR__;
68 changes: 53 additions & 15 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 @@ -15,27 +16,64 @@

from dulwich import porcelain

def get_firmware_specifier_build_flag():

def updateFileIfChanged(filename, content):
mustUpdate = True
try:
build_version = porcelain.describe('.') # '.' refers to the repository root dir
fp = open(filename, "rb")
if fp.read() == content:
mustUpdate = False
fp.close()
except:
build_version = "g0000000"
pass
if mustUpdate:
fp = open(filename, "wb")
fp.write(content)
fp.close()
return mustUpdate

print ("###########################################")
print ("Firmware Revision retuned from git: " + build_version)

# filter out release tag from build info git describe --tags
gitindex = build_version.find("-g")
if gitindex >= 0:
print ("contains build info at index %i" % gitindex)
build_version = build_version[gitindex+1:]
print ("filtered git hash: " + build_version)
def get_build_version():
try:
build_version = porcelain.describe('.') # '.' refers to the repository root dir
except:
build_version = "g0000000"
print ("Firmware Revision: " + build_version)
return build_version

print ("###########################################")

def get_firmware_specifier_build_flag():
build_version = get_build_version()
build_flag = "-D AUTO_GIT_HASH=\\\"" + build_version + "\\\""
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())

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

extra_scripts =
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 @@ -380,7 +381,7 @@ void MqttHandleHassClass::createInverterInfo(JsonDocument& root, std::shared_ptr
getDtuUrl(),
"OpenDTU",
inv->typeName(),
AUTO_GIT_HASH,
__COMPILED_GIT_HASH__,
getDtuUniqueId());
}

Expand All @@ -393,7 +394,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/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
11 changes: 6 additions & 5 deletions src/WebApi_prometheus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "NetworkSettings.h"
#include "WebApi.h"
#include <Hoymiles.h>
#include "__compiled_constants.h"

void WebApiPrometheusClass::init(AsyncWebServer& server, Scheduler& scheduler)
{
Expand All @@ -29,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 @@ -142,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 @@ -154,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 @@ -165,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 @@ -176,5 +177,5 @@ void WebApiPrometheusClass::addPanelInfo(AsyncResponseStream* stream, const Stri
idx,
inv->name(),
channel,
config.Inverter[idx].channel[channel].YieldTotalOffset);
config->channel[channel].YieldTotalOffset);
}
7 changes: 2 additions & 5 deletions src/WebApi_sysstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
#include <Hoymiles.h>
#include <LittleFS.h>
#include <ResetReason.h>

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

void WebApiSysstatusClass::init(AsyncWebServer& server, Scheduler& scheduler)
{
Expand Down Expand Up @@ -64,7 +61,7 @@ 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_hash"] = __COMPILED_GIT_HASH__;
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 2b25350

Please sign in to comment.