feature-requests
feature-requests copied to clipboard
Add Modbus slave support (RTU and TCP)
Describe the problem you have/What new integration you would like
It would be great to be able to use ESPhome on ESP32 as a Modbus slave.
I would like to use Modbus RTU via RS-485, but Modbus TCP would also suffice.
Please describe your use case for this integration and alternatives you've tried:
I asked at Discord and ESPhome can only use Modbus master.
Additional context
/
actually I'm interested in modbus slave RTU too. Any hints how it can be implemented?
I have also been wanting Modbus RTU on esphome. Y have many devices that are far away and y don't want wire a long cable to a PLC to monitor these devices. Is Modbus RTU master already possible? I couldn't find that anywhere.
Hello:
I'm interested in this question, does anyone already have the solution?
Thank you.
If anybody does start this, i suggest you base yourself on a real library instead of doing some partial solution in esphome. Using for example m-bus or libmodbus.
It has recently been integrated into the main ESPhome repository. https://esphome.io/components/modbus_controller.html We have to thank https://github.com/martgras. He did the integration, many people tested it and now it works with a lot of devices.
Version 2021.10.0 of ESPHome (see https://github.com/esphome/esphome/pull/1779) introduced Modbus client support (props to @martgras) for talking to Modbus servers (previously known as slaves) but support for making ESPHome itself act as a Modbus slave/server is still not available.
What are the complexities with creating a generic server device support? From the outside it seems like mapping sensors/state to coil/registry values might be the most complicated part due to the different ways these values could be represented in the Modbus payload. Are there other things I'm missing?
Just to reinforce the request for modbus slave functionality.
+1 for this...
@kasparsd: It depends. I would say some people want to just use any commercially available modbus controller and hook an esp32 in slave mode to it. But in some cases it would be nice to have some auto-mapping, if you want to use modbus instead of api/mqtt (still dreaming that it would be possible to use Zigbee, LoRa,ESP-Now,... instead of WiFi). All esp32's could be wired, only in case of OTA you will need to enable WiFi.
Hello all,
I just wrote a component that allows you to expose your ESPHome as a RTU modbus slave. The documentation is pending, but it is straightforward to use with the example provided.
https://github.com/epiclabs-io/esphome-modbus-server
Please let me know your feedback.
@jpeletier sorry for stupid question, is it possible to expose your modbus slave implementation with RS485 (serial).
Hello @bademux.
This implementation already and actually only works over RS485.
In the example you will see that first a serial uart has to be defined by specifying gpio pins where your RS485 serial adapter is connected:
uart:
- id: my_uart
tx_pin: 13
rx_pin: 16
baud_rate: 9600
stop_bits: 1
data_bits: 8
parity: NONE
debug:
direction: BOTH
Then, you instantiate modbus_server
linking to the above defined uart:
modbus_server:
- id: modbuserver
uart_id: my_uart
# [...]
Let me know if this clarifies. Cheers
Excellent!!! We need thorough documentation, please. Let's not just point people towards MODBus standards literature, let's explain in a few words how it works and how registers build up, and provide examples for each type of registers (Coil, Discrete Input, Input Register, Holding Register).
Moreover it would be nice to show an example where two ESPHome nodes talk to each other via MODBus.
Excellent!!! We need thorough documentation, please. Let's not just point people towards MODBus standards literature, let's explain in a few words how it works and how registers build up, and provide examples for each type of registers (Coil, Discrete Input, Input Register, Holding Register).
Moreover it would be nice to show an example where two ESPHome nodes talk to each other via MODBus.
Nagyrobi, i actually have an implementation of 2 esp32 talking in modbus with @jpeletier component, basically works but master and slave codes need some tweak in order to avoid crc errors ( i think that the esphome master sends too many requests to the slve), i will buy some rs485-ttl adapters to rule out hardware malfunctioning
btw, thank you @jpeletier :)