Hello,
I am trying to implement modbus communication using ESP32. Program is working perfect for about 100 mins. Later it starts to send rubbish.
I have 5 functions one by one like:
static void totEnergyRead(void *arg)
{
mgos_gpio_write(driverPin, true);
uart_write_bytes(UART_NUM_2, (char *)totEnergy, sizeof(totEnergy));
LOG(LL_INFO, ("%i", sizeof(totEnergy)));
for (int i = 0; i < sizeof(totEnergy); i++)
{
LOG(LL_INFO, ("%02X", totEnergy[i]));
}
mgos_msleep(12);
mgos_gpio_write(driverPin, false);
timeout = esp_timer_get_time();
uint8_t *tdata = (uint8_t *)malloc(BUF_SIZE);
while (1)
{
int lent = uart_read_bytes(UART_NUM_2, tdata, BUF_SIZE, 100 / portTICK_RATE_MS);
if (lent > 0)
{
vTaskDelay(delay);
char t[4] = {tdata[6], tdata[5], tdata[4], tdata[3]};
memcpy(&totResult, &t, sizeof(totResult));
LOG(LL_INFO, ("T:%.2f kWh", totResult));
uart_flush(UART_NUM_2);
free(tdata);
break;
}
else
{
LOG(LL_INFO, ("%lld", timeout));
LOG(LL_INFO, ("%lld", esp_timer_get_time()));
if (esp_timer_get_time() - timeout > 1000000)
{
timeout = 0;
free(tdata);
break;
}
}
}
(void)arg;
}
The result, after 100 mins is:
The same issue I have if I remove, but from the beginning:
LOG(LL_INFO, ("%i", sizeof(totEnergy)));
for (int i = 0; i < sizeof(totEnergy); i++)
{
LOG(LL_INFO, ("%02X", totEnergy[i]));
}
Any ideas?
Thanks in advance