Open
Description
Checklist
- Checked the issue tracker for similar issues to ensure this is not a duplicate
- Read the documentation to confirm the issue is not addressed there and your configuration is set correctly
- Tested with the latest version to ensure the issue hasn't been fixed
How often does this bug occurs?
often
Expected behavior
Start modbus TCP successfully
Actual behavior (suspected bug)
Sometimes modbus TCP slave doesn't start properly. It seems that there is some race condition and event MB_EV_READY is not handled at all.
Error logs or terminal output
On successful startup I see:
SUPLA: slave create tcp
mb_driver: Start of driver task.
SUPLA: slave start tcp
mb_driver: 0x3ffce308, fd event get: 0x101:-2, |MB_EVENT_READY|MB_EVENT_TIMEOUT
SUPLA: Modbus slave started
port.utils: Socket (#54), listener on port: 502, errno=0
mb_port.tcp.slave: loop:0x3ffce308 mbs_on_ready: fd: -1, bind is done
mb_driver: 0x3ffce308, no respond from node during timeout.
mb_driver: 0x3ffce308, fd event get: 0x100:-1, |MB_EVENT_TIMEOUT
When problem occur, there is no MB_EVENT_READY handling visible and there are no more logs from modbus.
SUPLA: slave create tcp
mb_driver: Start of driver task.
SUPLA: slave start tcp
SUPLA: Modbus slave started
Steps to reproduce the behavior
I use following code:
mb_communication_info_t tcpSlaveConfig = {};
tcpSlaveConfig.tcp_opts.port = 502;
tcpSlaveConfig.tcp_opts.mode = MB_TCP;
tcpSlaveConfig.tcp_opts.addr_type = MB_IPV4;
tcpSlaveConfig.tcp_opts.ip_addr_table = NULL;
tcpSlaveConfig.tcp_opts.ip_netif_ptr = wifi->getStaNetIf();
tcpSlaveConfig.tcp_opts.uid = 1;
ESP_ERROR_CHECK(mbc_slave_create_tcp(&tcpSlaveConfig, &mbcSlaveHandleTcp));
esp_err_t err = mbc_slave_start(mbcSlaveHandleTcp);
if (err != ESP_OK) {
// log error here;
}
Which is started from a task:
xTaskCreate(&cpp_main, "cpp_main", 8192, NULL, 5, NULL);
Project release version
v2.0.2 on esp-idf 5.4.1
System architecture
Intel/AMD 64-bit (modern PC, older Mac)
Operating system
Linux
Operating system version
Ubuntu 24.02
Shell
Bash
Additional context
Problem with starting is not reported back by mbc_slave_create_tcp nor by mbc_slave_start - they are both returning ESP_OK