Overview of the Modbus Master Example
mainThis example demonstrates how to use the FreeModbus stack port implementation on ESP32-based devices to act as a Modbus Master.
As a master, the device can read and write values from slave devices connected to a Modbus segment. The example uses a data dictionary to map characteristics (names and Characteristic IDs/CIDs) to specific registers on the slave devices. It also implements a simple control algorithm: if a specific parameter (e.g., holding_data0) exceeds a limit, the master triggers an alarm (e.g., activating a relay on the slave device).
Key Concepts:
- Characteristics: Data points identified by a name and a CID (e.g.,
Temperature_1withCID_INP_DATA_1). - Data Dictionary: A mapping used by the master to know which CIDs to poll from which slave addresses.
- Multi-slave segments: The master can communicate with multiple slaves by addressing different
MB_DEVICE_ADDRvalues.