Skip to content

Commit

Permalink
v3.31
Browse files Browse the repository at this point in the history
  • Loading branch information
pvtom committed Oct 26, 2024
1 parent 8b02569 commit ce808b6
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 66 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ or to show the help page
If everything works properly, you will see something like this:

```
rscp2mqtt [3.30]
rscp2mqtt [3.31]
E3DC system >192.168.178.111:5033< user: >your E3DC user<
MQTT broker >localhost:1883< qos = >0< retain = >✗< tls >✗< client id >✗< prefix >e3dc<
Requesting PVI ✓ | PM (0) | DCB ✓ (1 battery string) | Wallbox ✗ | Interval 2 | Autorefresh ✓ | Raw data ✗ | Logging OFF
Expand Down
6 changes: 6 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Release Notes

### Release v3.31 (26.10.2024)

Bug fixes:
- Issue #90: Cycle Time is not the Intervall given in cfg
- Issue #91: Setting e3dc/set/discharge_start_power is not working

### Release v3.30 (14.09.2024)

Bug fixes:
Expand Down
39 changes: 28 additions & 11 deletions RscpMqttMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
#include "AES.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <signal.h>
#include <mosquitto.h>
#include <thread>
#include <regex>
#include <mutex>

#define RSCP2MQTT_VERSION "3.30"
#define RSCP2MQTT_VERSION "3.31"

#define AES_KEY_SIZE 32
#define AES_BLOCK_SIZE 32
Expand Down Expand Up @@ -93,15 +94,21 @@ void signal_handler(int sig) {
go = false;
}

void wsleep(int sec) {
for (uint8_t i = 0; i < sec; i++) {
void wsleep(double seconds) {
while (seconds > 0.0) {
mtx.lock();
if (mqttRcvd || !go) {
mtx.unlock();
return;
}
mtx.unlock();
sleep(1);
if (seconds >= 1.0) {
sleep(1);
} else {
useconds_t usec = (useconds_t)(seconds * 1e6);
if (usec > 0) usleep(usec);
}
seconds = seconds - 1.0;
}
return;
}
Expand Down Expand Up @@ -218,6 +225,8 @@ int handleSetPower(std::vector<RSCP_MQTT::rec_cache_t> & c, uint32_t container,
char cmd[12];
char power[12];
char modus[2];
time_t now;
time(&now);

if (!strcmp(payload, "auto")) {
strcpy(cycles, "0");
Expand All @@ -237,12 +246,12 @@ int handleSetPower(std::vector<RSCP_MQTT::rec_cache_t> & c, uint32_t container,
switch (it->tag) {
case TAG_EMS_REQ_SET_POWER_MODE: {
strcpy(it->payload, modus);
it->refresh_count = abs(atoi(cycles));
it->refresh_until = abs(atoi(cycles)) * cfg.interval + now;
break;
}
case TAG_EMS_REQ_SET_POWER_VALUE: {
strcpy(it->payload, power);
it->refresh_count = abs(atoi(cycles));
it->refresh_until = abs(atoi(cycles)) * cfg.interval + now;
break;
}
}
Expand Down Expand Up @@ -411,7 +420,7 @@ void addTopic(uint32_t container, uint32_t tag, char *topic, char *unit, int for
}

void addSetTopic(uint32_t container, uint32_t tag, int index, char *topic, char *regex_true, char *value_true, char *regex_false, char *value_false, int type, bool finalize) {
RSCP_MQTT::rec_cache_t cache = { container, tag, index, "", "", "1", "", "0", "", UNIT_NONE, type, -1, false, true };
RSCP_MQTT::rec_cache_t cache = { container, tag, index, "", "", "1", "", "0", "", UNIT_NONE, type, 0, false, true };
strcpy(cache.topic, topic);
strcpy(cache.regex_true, regex_true);
strcpy(cache.value_true, value_true);
Expand Down Expand Up @@ -1931,10 +1940,11 @@ void createRequest(SRscpFrameBuffer * frameBuffer) {
SRscpValue ReqContainer;
int sun_mode = 0;
int max_current = -1;
time_t now;
time(&now);

for (std::vector<RSCP_MQTT::rec_cache_t>::iterator it = RSCP_MQTT::RscpMqttReceiveCache.begin(); it != RSCP_MQTT::RscpMqttReceiveCache.end(); ++it) {
if ((it->done == false) || (it->refresh_count > 0)) {
if (it->refresh_count > 0) it->refresh_count = it->refresh_count - 1;
if ((it->done == false) || (it->refresh_until > now)) {
if (!it->container && !it->tag) { //system call
if (!strcmp(it->topic, "set/log") || !strcmp(it->topic, "set/log/cache")) logCache(RSCP_MQTT::RscpMqttCache, cfg.logfile);
if (!strcmp(it->topic, "set/log/rcache")) logRecCache(RSCP_MQTT::RscpMqttReceiveCache, cfg.logfile);
Expand Down Expand Up @@ -2703,6 +2713,8 @@ static void receiveLoop(bool & bStopExecution) {
static void mainLoop(void) {
RscpProtocol protocol;
bool bStopExecution = false;
struct timeval start, end;
double elapsed;
int countdown = 3;

while (go && !bStopExecution) {
Expand All @@ -2712,6 +2724,8 @@ static void mainLoop(void) {
SRscpFrameBuffer frameBuffer;
memset(&frameBuffer, 0, sizeof(frameBuffer));

gettimeofday(&start, NULL);

// create an RSCP frame with requests to some example data
createRequest(&frameBuffer);

Expand Down Expand Up @@ -2847,7 +2861,10 @@ static void mainLoop(void) {
}
sleep(1);
} else {
wsleep(cfg.interval);
gettimeofday(&end, NULL);
elapsed = end.tv_sec - start.tv_sec + (end.tv_usec - start.tv_usec) * 1e-6;
elapsed = (double)cfg.interval - elapsed;
if (elapsed > 0.0) wsleep(elapsed);
}
}
return;
Expand Down Expand Up @@ -3500,7 +3517,7 @@ int main(int argc, char *argv[]) {
SocketClose(iSocket);
iSocket = -1;

wsleep(DELAY_BEFORE_RECONNECT);
wsleep((double)DELAY_BEFORE_RECONNECT);
}

// retain some values for a restart of the program
Expand Down
Loading

0 comments on commit ce808b6

Please sign in to comment.