Skip to content

Commit ba44a0e

Browse files
committed
modbus: Increase modbus timeout to 150ms. Probe one offline Node per loop.
1 parent 5fba29e commit ba44a0e

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

SmartEVSE-3/src/main.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,10 @@ void ModbusRequestLoop() {
25012501

25022502
static uint8_t PollEVNode = NR_EVSES;
25032503
static uint16_t energytimer = 0;
2504+
static uint8_t NodeOfflineProbe = 1;
2505+
static bool probedThisCycle = false;
25042506
uint8_t updated = 0;
2507+
uint8_t nodeNr;
25052508

25062509
// Every 2 seconds, request measurements from modbus meters
25072510
// Slaves all have ModbusRequest at 0 so they never enter here
@@ -2576,9 +2579,27 @@ void ModbusRequestLoop() {
25762579
case 10:
25772580
case 11:
25782581
case 12:
2582+
// Request Node Status, skip offline nodes to save time in the loop.
2583+
// Probe One offline Node per cycle.
25792584
if (LoadBl == 1) {
2580-
requestNodeStatus(ModbusRequest - 5u); // Master, Request Node 1-8 status
2581-
break;
2585+
if (ModbusRequest == 6) probedThisCycle = false;
2586+
2587+
while (ModbusRequest <= 12) {
2588+
nodeNr = ModbusRequest - 5u;
2589+
if (Node[nodeNr].Online || (!probedThisCycle && nodeNr == NodeOfflineProbe)) {
2590+
if (!Node[nodeNr].Online) {
2591+
probedThisCycle = true;
2592+
do {
2593+
if (++NodeOfflineProbe >= NR_EVSES) NodeOfflineProbe = 1;
2594+
} while (Node[NodeOfflineProbe].Online && NodeOfflineProbe != nodeNr);
2595+
_LOG_D("Probing offline Node %u\n", nodeNr);
2596+
}
2597+
requestNodeStatus(nodeNr);
2598+
break;
2599+
}
2600+
ModbusRequest++;
2601+
}
2602+
if (ModbusRequest <= 12) break;
25822603
}
25832604
ModbusRequest = 13;
25842605
// fall through

SmartEVSE-3/src/modbus.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ void ConfigureModbusMode(uint8_t newmode) {
864864
if (newmode != 255) MBserver.end();
865865
_LOG_A("ConfigureModbusMode2 task free ram: %u\n", uxTaskGetStackHighWaterMark( NULL ));
866866

867-
MBclient.setTimeout(85); // Set modbus timeout to 85ms. 15ms lower then modbusRequestloop time of 100ms.
867+
MBclient.setTimeout(150); // Set modbus timeout to 150ms.
868868
MBclient.onDataHandler(&MBhandleData);
869869
MBclient.onErrorHandler(&MBhandleError);
870870
// Start ModbusRTU Master background task

0 commit comments

Comments
 (0)