Can I change the Modbus TCP slave listening port at runtime in ESP-IDF?

MrNando
Posts: 8
Joined: Thu Jan 23, 2025 10:37 am

Can I change the Modbus TCP slave listening port at runtime in ESP-IDF?

Postby MrNando » Wed May 07, 2025 12:40 pm

I have a question about Modbus. I’m using the Modbus component in ESP-IDF. I initialize my device as a Modbus TCP slave and load an initial configuration. It runs a FreeRTOS task where it operates as a slave.

In my application, I can receive a new configuration for the slave via MQTT at runtime. I know that some parameters of the Modbus stack can be updated dynamically while the slave is running, but I’m not sure about the TCP port where the slave listens.

My question is: Is it possible to change the TCP port the Modbus TCP slave listens on at runtime, or do I need to destroy the slave instance and create it again with the new port?

Thank you very much in advance!

MrNando
Posts: 8
Joined: Thu Jan 23, 2025 10:37 am

Re: Can I change the Modbus TCP slave listening port at runtime in ESP-IDF?

Postby MrNando » Thu May 08, 2025 2:21 pm

In case someone else encounters the same issue, the only solution I’ve found is to destroy the Modbus stack using mbc_slave_destroy(), and then create it again with the new TCP port. It’s not the most practical approach, but it works reliably. Be careful not to have other tasks using Modbus functions at the same time, as calling slave functions after the stack has been destroyed will result in errors.

If anyone knows of a better solution, I’d really appreciate the information.

Who is online

Users browsing this forum: No registered users and 5 guests