#include < ModbusMaster.h >
#include < SoftwareSerial.h >
// Định nghĩa chân cho module RS485
const int DE_RE_PIN = D2;
const int RX_PIN = D3;
const int TX_PIN = D4;
// Khởi tạo SoftwareSerial cho giao tiếp RS485
SoftwareSerial rs485Serial(RX_PIN, TX_PIN);
// Khởi tạo ModbusMaster node
ModbusMaster node;
// Cấu hình Modbus
#define MODBUS_BAUDRATE 9600 // Thay đổi nếu cần
// Địa chỉ các cảm biến
byte sensorAddresses[] = { 1, 2, 3, 4}; // Thay đổi bằng địa chỉ thực tế của bạn
const int numSensors = sizeof(sensorAddresses) / sizeof(sensorAddresses[0]);
// Địa chỉ các thanh ghi
#define HOLDING_REG_HUMIDITY 0x0000