Skip to content

Commit 14d183d

Browse files
committed
v3.34
1 parent 5200e60 commit 14d183d

File tree

5 files changed

+117
-46
lines changed

5 files changed

+117
-46
lines changed

NEWTAGS.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ e3dc/raw/TAG_EMS_POWER_GRID
2424
e3dc/raw/TAG_BAT_DATA/TAG_BAT_RSOC
2525
```
2626

27-
The tag names are used to build the topic names.
27+
The tag names are used to build the topic names. If there are several results for a tag, a counter is added to the end of the topic.
2828
Raw data is only published via MQTT.
2929

3030
To limit the amount of raw data, a configuration entry can be created with a regular expression that describes the topics to be published:
@@ -173,4 +173,43 @@ ADD_NEW_REQUEST=0:TAG_EMS_REQ_EP_DELAY-0
173173
174174
# System Specifications
175175
ADD_NEW_REQUEST_AT_START=0:TAG_EMS_REQ_GET_SYS_SPECS-0
176+
177+
# SG Ready
178+
ADD_NEW_REQUEST_AT_START=0:TAG_SGR_REQ_HW_PROVIDER_LIST-0
179+
ADD_NEW_TOPIC=TAG_SGR_HW_PROVIDER:TAG_SGR_INDEX:_:1:0:sg_ready/1/provider/index
180+
ADD_NEW_TOPIC=TAG_SGR_HW_PROVIDER:TAG_SGR_NAME:_:1:0:sg_ready/1/provider/name
181+
ADD_NEW_TOPIC=TAG_SGR_HW_PROVIDER:TAG_SGR_INDEX:_:1:0:sg_ready/2/provider/index
182+
ADD_NEW_TOPIC=TAG_SGR_HW_PROVIDER:TAG_SGR_NAME:_:1:0:sg_ready/2/provider/name
183+
ADD_NEW_TOPIC=TAG_SGR_HW_PROVIDER:TAG_SGR_INDEX:_:1:0:sg_ready/3/provider/index
184+
ADD_NEW_TOPIC=TAG_SGR_HW_PROVIDER:TAG_SGR_NAME:_:1:0:sg_ready/3/provider/name
185+
ADD_NEW_TOPIC=TAG_SGR_HW_PROVIDER:TAG_SGR_INDEX:_:1:0:sg_ready/4/provider/index
186+
ADD_NEW_TOPIC=TAG_SGR_HW_PROVIDER:TAG_SGR_NAME:_:1:0:sg_ready/4/provider/name
187+
ADD_NEW_REQUEST=0:TAG_SGR_REQ_READY_TO_USE-0
188+
ADD_NEW_TOPIC=0:TAG_SGR_READY_TO_USE:W:1:0:sg_ready/ready_to_use
189+
ADD_NEW_REQUEST=0:TAG_SGR_REQ_COOLDOWN_END-0
190+
ADD_NEW_TOPIC=0:TAG_SGR_COOLDOWN_END:_:1:0:sg_ready/cooldown_end
191+
ADD_NEW_REQUEST=0:TAG_SGR_REQ_USED_POWER-0
192+
ADD_NEW_TOPIC=0:TAG_SGR_USED_POWER:W:1:0:sg_ready/used_power
193+
ADD_NEW_REQUEST=0:TAG_SGR_REQ_GLOBAL_OFF-0
194+
ADD_NEW_TOPIC=0:TAG_SGR_GLOBAL_OFF:_:1:0:sg_ready/global_off
195+
ADD_NEW_REQUEST=TAG_SGR_REQ_DATA:TAG_SGR_INDEX:0-0
196+
ADD_NEW_REQUEST=TAG_SGR_REQ_DATA:TAG_SGR_REQ_STATE-1
197+
ADD_NEW_TOPIC=TAG_SGR_DATA:TAG_SGR_INDEX:_:1:0:sg_ready/1/index
198+
ADD_NEW_TOPIC=TAG_SGR_DATA:TAG_SGR_STATE:_:1:0:sg_ready/1/status
199+
ADD_NEW_TOPIC=TAG_SGR_DATA:TAG_SGR_AKTIV:_:1:0:sg_ready/1/active
200+
ADD_NEW_REQUEST=TAG_SGR_REQ_DATA:TAG_SGR_INDEX:1-2
201+
ADD_NEW_REQUEST=TAG_SGR_REQ_DATA:TAG_SGR_REQ_STATE-3
202+
ADD_NEW_TOPIC=TAG_SGR_DATA:TAG_SGR_INDEX:_:1:0:sg_ready/2/index
203+
ADD_NEW_TOPIC=TAG_SGR_DATA:TAG_SGR_STATE:_:1:0:sg_ready/2/status
204+
ADD_NEW_TOPIC=TAG_SGR_DATA:TAG_SGR_AKTIV:_:1:0:sg_ready/2/active
205+
ADD_NEW_REQUEST=TAG_SGR_REQ_DATA:TAG_SGR_INDEX:2-4
206+
ADD_NEW_REQUEST=TAG_SGR_REQ_DATA:TAG_SGR_REQ_STATE-5
207+
ADD_NEW_TOPIC=TAG_SGR_DATA:TAG_SGR_INDEX:_:1:0:sg_ready/3/index
208+
ADD_NEW_TOPIC=TAG_SGR_DATA:TAG_SGR_STATE:_:1:0:sg_ready/3/status
209+
ADD_NEW_TOPIC=TAG_SGR_DATA:TAG_SGR_AKTIV:_:1:0:sg_ready/3/active
210+
ADD_NEW_REQUEST=TAG_SGR_REQ_DATA:TAG_SGR_INDEX:3-6
211+
ADD_NEW_REQUEST=TAG_SGR_REQ_DATA:TAG_SGR_REQ_STATE-7
212+
ADD_NEW_TOPIC=TAG_SGR_DATA:TAG_SGR_INDEX:_:1:0:sg_ready/4/index
213+
ADD_NEW_TOPIC=TAG_SGR_DATA:TAG_SGR_STATE:_:1:0:sg_ready/4/status
214+
ADD_NEW_TOPIC=TAG_SGR_DATA:TAG_SGR_AKTIV:_:1:0:sg_ready/4/active
176215
```

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ or to show the help page
160160
If everything works properly, you will see something like this:
161161

162162
```
163-
rscp2mqtt [3.33]
163+
rscp2mqtt [3.34]
164164
E3DC system >192.168.178.111:5033< user: >your E3DC user<
165165
MQTT broker >localhost:1883< qos = >0< retain = >✗< tls >✗< client id >✗< prefix >e3dc<
166166
Requesting PVI ✓ | PM (0) | DCB ✓ (1 battery string) | Wallbox ✗ | Interval 2 | Autorefresh ✓ | Raw data ✗ | Logging OFF

RELEASE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Release Notes
22

3+
### Release v3.34 (01.03.2025)
4+
5+
Features:
6+
- Improvements for raw data mode and additional topics (discovered during the investigation of issue #98)
7+
38
### Release v3.33 (15.02.2025)
49

510
Bug fixes:

RscpMqttMain.cpp

Lines changed: 59 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <regex>
2323
#include <mutex>
2424

25-
#define RSCP2MQTT_VERSION "3.33"
25+
#define RSCP2MQTT_VERSION "3.34"
2626

2727
#define AES_KEY_SIZE 32
2828
#define AES_BLOCK_SIZE 32
@@ -856,15 +856,15 @@ void pushNotSupportedTag(uint32_t container, uint32_t tag) {
856856
return;
857857
}
858858

859-
bool existsAdditionalTag(uint32_t container, uint32_t tag, int index) {
859+
bool existsAdditionalTag(uint32_t container, uint32_t tag, int index, int order) {
860860
for (std::vector<RSCP_MQTT::additional_tags_t>::iterator it = RSCP_MQTT::AdditionalTags.begin(); it != RSCP_MQTT::AdditionalTags.end(); ++it) {
861-
if ((it->req_container == container) && (it->req_tag == tag) && (it->req_index == index)) return(true);
862-
}
861+
if ((it->req_container == container) && (it->req_tag == tag) && (it->req_index == index) && (it->order == order)) return(true);
862+
}
863863
return(false);
864864
}
865865

866866
void pushAdditionalTag(uint32_t req_container, uint32_t req_tag, int req_index, int order, bool one_shot) {
867-
if (existsAdditionalTag(req_container, req_tag, req_index)) return;
867+
if (existsAdditionalTag(req_container, req_tag, req_index, order)) return;
868868
RSCP_MQTT::additional_tags_t v;
869869
v.req_container = req_container;
870870
v.req_tag = req_tag;
@@ -876,38 +876,40 @@ void pushAdditionalTag(uint32_t req_container, uint32_t req_tag, int req_index,
876876
return;
877877
}
878878

879-
bool updateRawData(char *topic, char *payload) {
879+
void initRawData() {
880+
for (std::vector<RSCP_MQTT::raw_data_t>::iterator it = RSCP_MQTT::rawData.begin(); it != RSCP_MQTT::rawData.end(); ++it) {
881+
it->handled = false;
882+
it->changed = false;
883+
}
884+
return;
885+
}
886+
887+
int mergeRawData(char *topic, char *payload, bool *changed) {
888+
int i = 0;
880889
if (topic && payload) {
881-
for (std::vector<RSCP_MQTT::mqtt_data_t>::iterator it = RSCP_MQTT::rawData.begin(); it != RSCP_MQTT::rawData.end(); ++it) {
882-
if (!strcmp(it->topic, topic)) {
890+
for (std::vector<RSCP_MQTT::raw_data_t>::iterator it = RSCP_MQTT::rawData.begin(); it != RSCP_MQTT::rawData.end(); ++it) {
891+
if (!strcmp(it->topic, topic) && !it->handled && (i == it->nr)) {
883892
if (strcmp(it->payload, payload)) {
884893
if (strlen(it->payload) != strlen(payload)) it->payload = (char *)realloc(it->payload, strlen(payload) + 1);
885894
strcpy(it->payload, payload);
895+
it->changed = true;
896+
*changed = true;
886897
}
887-
return(true);
898+
it->handled = true;
899+
return(i);
888900
}
901+
if (!strcmp(it->topic, topic) && it->handled) i++;
889902
}
890-
}
891-
return(false);
892-
}
893-
894-
void insertRawData(char *topic, char *payload) {
895-
if (topic && payload) {
896-
RSCP_MQTT::mqtt_data_t v;
903+
RSCP_MQTT::raw_data_t v;
897904
v.topic = strdup(topic);
898905
v.payload = strdup(payload);
906+
v.handled = true;
907+
v.changed = true;
908+
v.nr = i;
899909
RSCP_MQTT::rawData.push_back(v);
910+
*changed = true;
900911
}
901-
return;
902-
}
903-
904-
char *readRawData(char *topic) {
905-
for (std::vector<RSCP_MQTT::mqtt_data_t>::iterator it = RSCP_MQTT::rawData.begin(); it != RSCP_MQTT::rawData.end(); ++it) {
906-
if (!strcmp(it->topic, topic)) {
907-
return(it->payload);
908-
}
909-
}
910-
return(NULL);
912+
return(i);
911913
}
912914

913915
void refreshCache(std::vector<RSCP_MQTT::cache_t> & v, char *payload) {
@@ -1085,6 +1087,13 @@ float getFloatValue(std::vector<RSCP_MQTT::cache_t> & c, uint32_t container, uin
10851087
return(value);
10861088
}
10871089

1090+
void resetHandleFlag(std::vector<RSCP_MQTT::cache_t> & c) {
1091+
for (std::vector<RSCP_MQTT::cache_t>::iterator it = c.begin(); it != c.end(); ++it) {
1092+
it->handled = false;
1093+
}
1094+
return;
1095+
}
1096+
10881097
void preparePayload(RscpProtocol *protocol, SRscpValue *response, char **buf) {
10891098
switch (response->dataType) {
10901099
case RSCP::eTypeBool: {
@@ -1143,8 +1152,7 @@ int storeResponseValue(std::vector<RSCP_MQTT::cache_t> & c, RscpProtocol *protoc
11431152
int rc = -1;
11441153

11451154
for (std::vector<RSCP_MQTT::cache_t>::iterator it = c.begin(); it != c.end(); ++it) {
1146-
if ((it->container > container) && (it->tag > response->tag)) break;
1147-
if ((!it->container || (it->container == container)) && (it->tag == response->tag) && (it->index == index)) {
1155+
if ((!it->container || (it->container == container)) && (it->tag == response->tag) && (it->index == index) && !it->handled) {
11481156
switch (response->dataType) {
11491157
case RSCP::eTypeBool: {
11501158
if (protocol->getValueAsBool(response)) strcpy(buf, "true");
@@ -1287,6 +1295,8 @@ int storeResponseValue(std::vector<RSCP_MQTT::cache_t> & c, RscpProtocol *protoc
12871295
if ((atoi(it->payload) == 0) && (battery_soc > 1)) snprintf(it->payload, PAYLOAD_SIZE, "%d", battery_soc--);
12881296
else battery_soc = atoi(it->payload);
12891297
}
1298+
it->handled = true;
1299+
break;
12901300
}
12911301
}
12921302
return(rc);
@@ -2122,21 +2132,24 @@ void createRequest(SRscpFrameBuffer * frameBuffer) {
21222132
return;
21232133
}
21242134

2125-
void publishRaw(RscpProtocol *protocol, SRscpValue *response, char *topic) {
2126-
char *payload_new = (char *)malloc(PAYLOAD_SIZE * sizeof(char) + 1);
2127-
char *payload_old = readRawData(topic);
2128-
memset(payload_new, 0, PAYLOAD_SIZE);
2129-
preparePayload(protocol, response, &payload_new);
2130-
if (payload_old && payload_new && strcmp(payload_new, "") && strcmp(payload_old, payload_new)) {
2131-
publishImmediately(topic, payload_new, false);
2132-
updateRawData(topic, payload_new);
2133-
} else if (!payload_old && payload_new && strcmp(payload_new, "")) {
2134-
publishImmediately(topic, payload_new, false);
2135-
insertRawData(topic, payload_new);
2136-
}
2137-
if (payload_new) free(payload_new);
2138-
return;
2139-
}
2135+
void publishRaw(RscpProtocol *protocol, SRscpValue *response, char *topic_in) {
2136+
char topic[TOPIC_SIZE];
2137+
char *payload = (char *)malloc(PAYLOAD_SIZE * sizeof(char) + 1);
2138+
bool changed = false;
2139+
memset(payload, 0, PAYLOAD_SIZE);
2140+
preparePayload(protocol, response, &payload);
2141+
2142+
int nr = mergeRawData(topic_in, payload, &changed);
2143+
if (nr > 0) {
2144+
if (snprintf(topic, TOPIC_SIZE, "%s/%d", topic_in, nr) >= TOPIC_SIZE) {
2145+
logMessage(cfg.logfile, (char *)__FILE__, __LINE__, (char *)"publishRaw: Buffer overflow\n");
2146+
return;
2147+
}
2148+
if (changed) publishImmediately(topic, payload, false);
2149+
} else if (changed) publishImmediately(topic_in, payload, false);
2150+
if (payload) free(payload);
2151+
return;
2152+
}
21402153

21412154
void handleRaw(RscpProtocol *protocol, SRscpValue *response, uint32_t *cache, int level) {
21422155
int l = level + 1;
@@ -2612,6 +2625,7 @@ static int processReceiveBuffer(const unsigned char * ucBuffer, int iLength) {
26122625
battery_nr = 0;
26132626
pm_nr = 0;
26142627
wb_nr = 0;
2628+
if (cfg.raw_mode) initRawData();
26152629
for (size_t i = 0; i < frame.data.size(); i++)
26162630
handleResponseValue(&protocol, &frame.data[i]);
26172631

@@ -2744,6 +2758,8 @@ static void mainLoop(void) {
27442758

27452759
gettimeofday(&start, NULL);
27462760

2761+
resetHandleFlag(RSCP_MQTT::RscpMqttCache);
2762+
27472763
// create an RSCP frame with requests to some example data
27482764
createRequest(&frameBuffer);
27492765

RscpMqttMapping.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,16 @@ typedef struct _mqtt_data_t {
152152
} mqtt_data_t;
153153

154154
std::queue<mqtt_data_t> mqttQ;
155-
std::vector<mqtt_data_t> rawData;
155+
156+
typedef struct _raw_data_t {
157+
char *topic;
158+
char *payload;
159+
int nr;
160+
bool handled;
161+
bool changed;
162+
} raw_data_t;
163+
164+
std::vector<raw_data_t> rawData;
156165

157166
typedef struct _cache_t {
158167
uint32_t container;
@@ -165,6 +174,7 @@ typedef struct _cache_t {
165174
int divisor;
166175
int bit_to_bool;
167176
bool history_log;
177+
bool handled;
168178
bool changed;
169179
bool influx;
170180
bool forced;
@@ -357,6 +367,7 @@ bool compareCache(RSCP_MQTT::cache_t c1, RSCP_MQTT::cache_t c2) {
357367
if (c1.container < c2.container) return(true);
358368
if ((c1.container == c2.container) && (c1.tag < c2.tag)) return(true);
359369
if ((c1.container == c2.container) && (c1.tag == c2.tag) && (c1.index < c2.index)) return(true);
370+
if ((c1.container == c2.container) && (c1.tag == c2.tag) && (c1.index == c2.index) && (strcmp(c1.topic, c2.topic) < 0)) return(true);
360371
return(false);
361372
}
362373

0 commit comments

Comments
 (0)