Esp32 modbus tcp slave
#include <Modbus.h> #include <WiFi.h> #define BUFFER_SIZE 128 // Modbus TCP object Modbus modbus; // TCP/IP interface object WiFiServer server(502); // Modbus slave ID const int SLAVE_ID = 1; // Modbus function codes const int FC_READ_COILS = 0x01; const int FC_READ_INPUT_REGISTERS = 0x03; const int FC_WRITE_MULTIPLE_COILS = 0x0F; const int FC_WRITE_MULTIPLE_REGISTERS = 0x10; // Modbus status codes const int STATUS_OK = 0x00; const int STATUS_ILLEGAL_FUNCTION = 0x01; const int STATUS_ILLEGAL_DATA_ADDRESS = 0x02; const int STATUS_ILLEGAL_DATA_VALUE = 0x03; const int STATUS_SLAVE_DEVICE_FAILURE = 0x