Skip to content

Commit ae39232

Browse files
committed
Merge branch 'development'
2 parents 4d0f958 + b081845 commit ae39232

File tree

13 files changed

+159
-63
lines changed

13 files changed

+159
-63
lines changed

include/HttpPowerMeter.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <stdint.h>
55
#include <Arduino.h>
6+
#include <HTTPClient.h>
67

78
class HttpPowerMeterClass {
89
public:
@@ -14,9 +15,12 @@ class HttpPowerMeterClass {
1415
float getFloatValueByJsonPath(const char* jsonString, const char* jsonPath, float &value);
1516

1617
private:
17-
float power[POWERMETER_MAX_PHASES];
1818
void extractUrlComponents(const String& url, String& protocol, String& hostname, String& uri);
19+
void prepareRequest(uint32_t timeout, const char* httpHeader, const char* httpValue);
20+
HTTPClient httpClient;
21+
float power[POWERMETER_MAX_PHASES];
1922
String sha256(const String& data);
23+
2024
};
2125

2226
extern HttpPowerMeterClass HttpPowerMeter;

include/MqttHandleDtu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class MqttHandleDtuClass {
99
void loop();
1010

1111
private:
12-
uint32_t _lastPublish;
12+
uint32_t _lastPublish = 0;
1313
};
1414

1515
extern MqttHandleDtuClass MqttHandleDtu;

include/MqttHandleInverter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class MqttHandleInverterClass {
1717
void publishField(std::shared_ptr<InverterAbstract> inv, ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId);
1818
void onMqttMessage(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total);
1919

20-
uint32_t _lastPublishStats[INV_MAX_COUNT];
21-
uint32_t _lastPublish;
20+
uint32_t _lastPublishStats[INV_MAX_COUNT] = { 0 };
21+
uint32_t _lastPublish = 0;
2222

2323
FieldId_t _publishFields[14] = {
2424
FLD_UDC,

lib/Hoymiles/src/Hoymiles.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "Hoymiles.h"
66
#include "Utils.h"
77
#include "inverters/HMS_1CH.h"
8+
#include "inverters/HMS_1CHv2.h"
89
#include "inverters/HMS_2CH.h"
910
#include "inverters/HMS_4CH.h"
1011
#include "inverters/HMT_6CH.h"
@@ -147,6 +148,8 @@ std::shared_ptr<InverterAbstract> HoymilesClass::addInverter(const char* name, u
147148
i = std::make_shared<HMS_2CH>(_radioCmt.get(), serial);
148149
} else if (HMS_1CH::isValidSerial(serial)) {
149150
i = std::make_shared<HMS_1CH>(_radioCmt.get(), serial);
151+
} else if (HMS_1CHv2::isValidSerial(serial)) {
152+
i = std::make_shared<HMS_1CHv2>(_radioCmt.get(), serial);
150153
} else if (HM_4CH::isValidSerial(serial)) {
151154
i = std::make_shared<HM_4CH>(_radioNrf.get(), serial);
152155
} else if (HM_2CH::isValidSerial(serial)) {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Copyright (C) 2023 Thomas Basler and others
4+
*/
5+
#include "HMS_1CHv2.h"
6+
7+
static const byteAssign_t byteAssignment[] = {
8+
{ TYPE_DC, CH0, FLD_UDC, UNIT_V, 2, 2, 10, false, 1 },
9+
{ TYPE_DC, CH0, FLD_IDC, UNIT_A, 6, 2, 100, false, 2 },
10+
{ TYPE_DC, CH0, FLD_PDC, UNIT_W, 10, 2, 10, false, 1 },
11+
{ TYPE_DC, CH0, FLD_YD, UNIT_WH, 22, 2, 1, false, 0 },
12+
{ TYPE_DC, CH0, FLD_YT, UNIT_KWH, 14, 4, 1000, false, 3 },
13+
{ TYPE_DC, CH0, FLD_IRR, UNIT_PCT, CALC_IRR_CH, CH0, CMD_CALC, false, 3 },
14+
15+
{ TYPE_AC, CH0, FLD_UAC, UNIT_V, 26, 2, 10, false, 1 },
16+
{ TYPE_AC, CH0, FLD_IAC, UNIT_A, 34, 2, 100, false, 2 },
17+
{ TYPE_AC, CH0, FLD_PAC, UNIT_W, 30, 2, 10, false, 1 },
18+
{ TYPE_AC, CH0, FLD_Q, UNIT_VAR, 20, 2, 10, false, 1 },
19+
{ TYPE_AC, CH0, FLD_F, UNIT_HZ, 28, 2, 100, false, 2 },
20+
{ TYPE_AC, CH0, FLD_PF, UNIT_NONE, 36, 2, 1000, false, 3 },
21+
22+
{ TYPE_INV, CH0, FLD_T, UNIT_C, 38, 2, 10, true, 1 },
23+
{ TYPE_INV, CH0, FLD_EVT_LOG, UNIT_NONE, 18, 2, 1, false, 0 },
24+
25+
{ TYPE_AC, CH0, FLD_YD, UNIT_WH, CALC_YD_CH0, 0, CMD_CALC, false, 0 },
26+
{ TYPE_AC, CH0, FLD_YT, UNIT_KWH, CALC_YT_CH0, 0, CMD_CALC, false, 3 },
27+
{ TYPE_AC, CH0, FLD_PDC, UNIT_W, CALC_PDC_CH0, 0, CMD_CALC, false, 1 },
28+
{ TYPE_AC, CH0, FLD_EFF, UNIT_PCT, CALC_EFF_CH0, 0, CMD_CALC, false, 3 }
29+
};
30+
31+
HMS_1CHv2::HMS_1CHv2(HoymilesRadio* radio, uint64_t serial)
32+
: HMS_Abstract(radio, serial) {};
33+
34+
bool HMS_1CHv2::isValidSerial(uint64_t serial)
35+
{
36+
// serial >= 0x112500000000 && serial <= 0x112599999999
37+
uint16_t preSerial = (serial >> 32) & 0xffff;
38+
return preSerial == 0x1125;
39+
}
40+
41+
String HMS_1CHv2::typeName()
42+
{
43+
return "HMS-500 v2";
44+
}
45+
46+
const byteAssign_t* HMS_1CHv2::getByteAssignment()
47+
{
48+
return byteAssignment;
49+
}
50+
51+
uint8_t HMS_1CHv2::getByteAssignmentSize()
52+
{
53+
return sizeof(byteAssignment) / sizeof(byteAssignment[0]);
54+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
#pragma once
3+
4+
#include "HMS_Abstract.h"
5+
#include <list>
6+
7+
class HMS_1CHv2 : public HMS_Abstract {
8+
public:
9+
explicit HMS_1CHv2(HoymilesRadio* radio, uint64_t serial);
10+
static bool isValidSerial(uint64_t serial);
11+
String typeName();
12+
const byteAssign_t* getByteAssignment();
13+
uint8_t getByteAssignmentSize();
14+
};

lib/Hoymiles/src/parser/DevInfoParser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const devInfo_t devInfo[] = {
3232
{ { 0x10, 0x20, 0x41, ALL }, 400, "HMS-400" }, // 00
3333
{ { 0x10, 0x10, 0x51, ALL }, 450, "HMS-450" }, // 01
3434
{ { 0x10, 0x10, 0x71, ALL }, 500, "HMS-500" }, // 02
35+
{ { 0x10, 0x20, 0x71, ALL }, 500, "HMS-500 v2" }, // 02
3536
{ { 0x10, 0x21, 0x11, ALL }, 600, "HMS-600" }, // 01
3637
{ { 0x10, 0x21, 0x41, ALL }, 800, "HMS-800" }, // 00
3738
{ { 0x10, 0x11, 0x51, ALL }, 900, "HMS-900" }, // 01

src/HttpPowerMeter.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "HttpPowerMeter.h"
44
#include "MessageOutput.h"
55
#include <WiFiClientSecure.h>
6-
#include <HTTPClient.h>
76
#include <FirebaseJson.h>
87
#include <Crypto.h>
98
#include <SHA256.h>
@@ -87,30 +86,19 @@ bool HttpPowerMeterClass::httpRequest(const char* url, Auth authType, const char
8786
wifiClient = std::make_unique<WiFiClient>();
8887
}
8988

90-
HTTPClient httpClient;
89+
9190
if (!httpClient.begin(*wifiClient, newUrl)) {
9291
snprintf_P(error, errorSize, "httpClient.begin(%s) failed", newUrl.c_str());
9392
return false;
9493
}
95-
96-
httpClient.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
97-
httpClient.setUserAgent("OpenDTU-OnBattery");
98-
httpClient.setConnectTimeout(timeout);
99-
httpClient.setTimeout(timeout);
100-
httpClient.addHeader("Content-Type", "application/json");
101-
httpClient.addHeader("Accept", "application/json");
102-
103-
if (strlen(httpHeader) > 0) {
104-
httpClient.addHeader(httpHeader, httpValue);
105-
}
106-
94+
prepareRequest(timeout, httpHeader, httpValue);
95+
10796
if (authType == Auth::digest) {
10897
const char *headers[1] = {"WWW-Authenticate"};
10998
httpClient.collectHeaders(headers, 1);
11099
}
111100

112101
int httpCode = httpClient.GET();
113-
114102
if (httpCode == HTTP_CODE_UNAUTHORIZED && authType == Auth::digest) {
115103
// Handle authentication challenge
116104
char realm[256]; // Buffer to store the realm received from the server
@@ -160,6 +148,12 @@ bool HttpPowerMeterClass::httpRequest(const char* url, Auth authType, const char
160148
authorization += "\", nc=00000001, qop=auth, response=\"";
161149
authorization += response;
162150
authorization += "\", algorithm=SHA-256";
151+
httpClient.end();
152+
if (!httpClient.begin(*wifiClient, newUrl)) {
153+
snprintf_P(error, errorSize, "httpClient.begin(%s) for digest auth failed", newUrl.c_str());
154+
return false;
155+
}
156+
prepareRequest(timeout, httpHeader, httpValue);
163157
httpClient.addHeader("Authorization", authorization);
164158
httpCode = httpClient.GET();
165159
}
@@ -259,4 +253,17 @@ String HttpPowerMeterClass::sha256(const String& data) {
259253
return hashStr;
260254
}
261255

256+
void HttpPowerMeterClass::prepareRequest(uint32_t timeout, const char* httpHeader, const char* httpValue) {
257+
httpClient.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
258+
httpClient.setUserAgent("OpenDTU-OnBattery");
259+
httpClient.setConnectTimeout(timeout);
260+
httpClient.setTimeout(timeout);
261+
httpClient.addHeader("Content-Type", "application/json");
262+
httpClient.addHeader("Accept", "application/json");
263+
264+
if (strlen(httpHeader) > 0) {
265+
httpClient.addHeader(httpHeader, httpValue);
266+
}
267+
}
268+
262269
HttpPowerMeterClass HttpPowerMeter;

src/MqttHandleHass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void MqttHandleHassClass::publishField(std::shared_ptr<InverterAbstract> inv, Ch
143143
root["stat_cla"] = stateCls;
144144
}
145145

146-
char buffer[512];
146+
String buffer;
147147
serializeJson(root, buffer);
148148
publish(configTopic, buffer);
149149
} else {
@@ -181,7 +181,7 @@ void MqttHandleHassClass::publishInverterButton(std::shared_ptr<InverterAbstract
181181
JsonObject deviceObj = root.createNestedObject("dev");
182182
createDeviceInfo(deviceObj, inv);
183183

184-
char buffer[512];
184+
String buffer;
185185
serializeJson(root, buffer);
186186
publish(configTopic, buffer);
187187
}
@@ -220,7 +220,7 @@ void MqttHandleHassClass::publishInverterNumber(
220220
JsonObject deviceObj = root.createNestedObject("dev");
221221
createDeviceInfo(deviceObj, inv);
222222

223-
char buffer[512];
223+
String buffer;
224224
serializeJson(root, buffer);
225225
publish(configTopic, buffer);
226226
}
@@ -249,7 +249,7 @@ void MqttHandleHassClass::publishInverterBinarySensor(std::shared_ptr<InverterAb
249249
JsonObject deviceObj = root.createNestedObject("dev");
250250
createDeviceInfo(deviceObj, inv);
251251

252-
char buffer[512];
252+
String buffer;
253253
serializeJson(root, buffer);
254254
publish(configTopic, buffer);
255255
}

webapp/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@
1212
},
1313
"dependencies": {
1414
"@popperjs/core": "^2.11.8",
15-
"bootstrap": "^5.3.1",
15+
"bootstrap": "^5.3.2",
1616
"bootstrap-icons-vue": "^1.10.3",
1717
"mitt": "^3.0.1",
1818
"sortablejs": "^1.15.0",
1919
"spark-md5": "^3.0.2",
2020
"vue": "^3.3.4",
21-
"vue-i18n": "^9.4.0",
21+
"vue-i18n": "^9.4.1",
2222
"vue-router": "^4.2.4"
2323
},
2424
"devDependencies": {
2525
"@intlify/unplugin-vue-i18n": "^1.2.0",
26-
"@rushstack/eslint-patch": "^1.3.3",
26+
"@rushstack/eslint-patch": "^1.4.0",
2727
"@tsconfig/node18": "^18.2.2",
28-
"@types/bootstrap": "^5.2.6",
29-
"@types/node": "^20.6.0",
28+
"@types/bootstrap": "^5.2.7",
29+
"@types/node": "^20.6.2",
3030
"@types/sortablejs": "^1.15.2",
3131
"@types/spark-md5": "^3.0.2",
3232
"@vitejs/plugin-vue": "^4.3.4",
@@ -35,7 +35,7 @@
3535
"eslint": "^8.49.0",
3636
"eslint-plugin-vue": "^9.17.0",
3737
"npm-run-all": "^4.1.5",
38-
"sass": "^1.66.1",
38+
"sass": "^1.67.0",
3939
"terser": "^5.19.4",
4040
"typescript": "^5.2.2",
4141
"vite": "^4.4.9",

0 commit comments

Comments
 (0)