emelianov / modbus-esp8266

Most complete Modbus library for Arduino. A library that allows your Arduino board to communicate via Modbus protocol, acting as a master, slave or both. Supports network transport (Modbus TCP) and Serial line/RS-485 (Modbus RTU). Supports Modbus TCP Security for ESP8266/ESP32.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Blink led on master request

nex2000 opened this issue · comments

Hello
I'm not very good at programming , but i'm using this library with great results it works great, kudos to the author.

i couldn't catch the event to make a led turn on or blink every time the master sends a request. Could anyone help me? I attach the source

Regards

`#include <WiFi.h>
#include <ModbusIP_ESP8266.h>

const int relayCtrlPin = 2;
const int tempPin = A3;

const char ssid []= "--------------------";
const char password []= "--------------";

ModbusIP modbusTCPServer;

void setup() {
Serial.begin(115200);
pinMode(relayCtrlPin, OUTPUT);
digitalWrite(relayCtrlPin, LOW);

Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

modbusTCPServer.slave(502);
modbusTCPServer.addCoil(0x00);
modbusTCPServer.addHreg(0x00);
}

void loop() {
modbusTCPServer.task();
digitalWrite(relayCtrlPin, modbusTCPServer.Coil(0X00));
modbusTCPServer.Hreg(0X00, analogRead(tempPin));

delay(10);
}
`