Problem connecting Factory IO with Arduino using MODBUS

Hi,

I’m trying to make a communication via Modbus protocol between FactoryIO and Arduino UNO. I’m using an Ethernet shield for this. What I want to do, is to try to control the Factory IO water tank with a PID control from Arduino. Basically, I’m trying to replicate the steps in this tutorial: COMUNICACION MODBUS ARDUINO FACTORY IO - YouTube

I configure the FactoryIO simulation with a Modbus TCP/IP client, in “Configuration” I write the Arduino IP, I’m using the port 502, the slave ID is 1. But every time I click on “Connect”, an error message appears, saying: “Server not available” and that the other part didn’t respond successfully in a certain period of time, or that the connected host could not be able to answer (I’m paraphrasing the error message because it appears me in Spanish despite I have Factory IO configured in English).

In other attempts a similar message appears, saying “Server not available”, and that the connection could not be established because the target device expressly denied the connection. This is an image with both errors messages:

The Arduino code that I’m using is this one:

#include <PID_v1.h>
#include <SPI.h>
#include <Ethernet.h>
#include "MgsModbus.h"

MgsModbus Mb;

// Ethernet settings (depending on MAC and Local network)
byte mac[] = {0x90, 0xA2, 0xDA, 0x0E, 0x94, 0xB5 };
IPAddress ip(192, 168, 0, 100);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);

//Coils
int level;
double Set, In, Out;

//PID settings
double Kp = 20, Ki = 1, Kd = 1;
PID myPID(&In, &Out, &Set, Kp, Ki, Kd, DIRECT);

String dat;

void setup()
{
  // serial setup
  Serial.begin(9600);

  //Pin setup
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  
  // initialize the ethernet device
  Ethernet.begin(mac, ip, gateway, subnet);   // start etehrnet interface

  //PID setup
  myPID.SetMode(AUTOMATIC);
}

void loop()
{
  //Getting Factory I/O data
  level = Mb.MbData[4];
  In = level;
  Set = Mb.MbData[3];

  //PID initialize
  Serial.print(Out);
  Serial.print(", ");
  Serial.print(level);
  Serial.print(",");
  Serial.println(Set);

  delay(100);

  myPID.Compute();
  Mb.MbData[0] = (Out * 200) / 51;

//  Mb.MbmRun();
  Mb.MbsRun();
}

I don’t know If I have to do another extra configuration in order to establish the Modbus communication between the Arduino and FactoryIO. Any help would be really appreciated! Thanks in advance.

Hi @sweetpickle!
Have you tried connecting Arduino to a different Modbus client? This might help you find the problem.
The error displayed in Spanish comes from Windows; a common cause for this is a firewall denying the connection to the socket. You could start by checking if you have any firewall/antivirus software installed.
Please let me know if you find out what’s wrong.