Added mutex to MODBUS and I@c for mutithreading

This commit is contained in:
Emanuele Trabattoni
2025-07-14 11:29:16 +02:00
parent 7e02f3cef2
commit bdf3b9b41a
7 changed files with 26 additions and 16 deletions

View File

@@ -24,11 +24,14 @@ void callback(char *topic, uint8_t *payload, unsigned int length)
void myTask(void *mqtt)
{
while (true)
auto client = (PubSubClient *)(mqtt);
while (client->connected())
{
((PubSubClient *)(mqtt))->loop();
client->loop();
vTaskDelay(pdMS_TO_TICKS(100));
}
LOG_ERROR("Mqtt Loop Ended, client disconnected");
vTaskDelete(NULL); // delete the current task
};
/////////////// GLOBALS ///////////////
@@ -42,7 +45,7 @@ void loop()
{
const uint8_t tempBoardAddr(0xAA);
const uint8_t relayBoardAddr(0x01);
const uint8_t senecadAddr(0xBB);
const uint8_t senecaMeterAddr(0xBB);
const uint8_t baseRegister(0x00);
uint16_t k(0);
uint8_t ethRetries(0);
@@ -58,7 +61,7 @@ void loop()
delay(100);
auto io = digitalIO(i2c, bus, {relayBoardAddr});
delay(100);
auto seneca = drivers::S50140(bus, senecadAddr);
auto seneca = drivers::S50140(bus, senecaMeterAddr);
Network.onEvent([&eth](arduino_event_id_t event, arduino_event_info_t info)
{ eth.onEvent(event, info); });