Dear community:
I have a UNO R4 WIFI that I just bought and I want to use it as a remote Input/Output station using the ModbusTCP server over my home LAN network. I have an Opta WIFI working as a MODBUS TCP MASTER and I can see the UNO R4 WIFI in the same network as the Opta and I can even send and receive data using Modbus Poll simulation tool, however I get connection timeouts. So in other words It is an intermittent connection to the UNO R4 WIFI and it takes like 5-10 Tx request to get one Rx the it repeat again.
I have tried different libraries but nothing seems to work 100%.
The Sketch below is the closest one working.
Any suggestions on how to solve this issue?
In the following pictures I show the FW version I'm using and the Modbus Poll behavior:
#include <Arduino.h>
//#include <esp_system.h>
//
#ifdef ESP8266
#include <ESP8266WiFi.h>
#else //ESP32
#include <WiFi.h>
#endif
#include <ModbusIP_ESP8266.h>
//Modbus Registers Offsets
const int SENSOR_IREG = 0;
//ModbusIP object
ModbusIP mb;
//Registers
const int numRegisters = 10;
uint16_t registers[numRegisters] = {0};
long ts;
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("Arduino Board Info:");
//Serial.println(ARDUINO_BOARD);
WiFi.begin("ATT34X58s7", "244+vci8jrc5"); // "Your_SSID" --> ATT34X58s7 "Your_PASSWORD" --> 244+vci8jrc5
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
mb.server(); //Start Modbus IP
// Add SENSOR_IREG register - Use addIreg() for analog Inputs
mb.addIreg(SENSOR_IREG);
ts = millis();
}
void loop() {
//Call once inside loop() - all magic here
mb.task();
// Example: Update the first holding register
static uint16_t counter = 0;
registers[0] = counter++;
//Serial.print(registers[0] );
//Serial.print("\n"); //Serial.print("\r\n");
//Read each two seconds
if (millis() > ts + 2000) {
ts = millis();
//Setting raw value (0-1024)
//mb.Ireg(SENSOR_IREG, analogRead(A0));
mb.Ireg(SENSOR_IREG,registers[0] );
}
delay(10);
if (counter >= 100){
counter = 0;
}
}


