Ethernet communication via OPC UA

Hello out there,
Screenshot (203)


I have tried to establish communication between Arduino and OPC Server via serial mode and it's working fine. Now I am trying to establish Ethernet communication but not able to do it.
below I am attaching the code and screenshots.
Kindly guide me regarding the same.
Thanks in advance!

#include <SPI.h>
#include <Ethernet.h>
#include <OPC.h>

OPCSerial aOPCSerial;

int ledPin = 13;

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] =
{
  0x90, 0xA2, 0xDA, 0x0F, 0x08, 0xE1
};

IPAddress ip(192, 168, 192, 159);

// telnet defaults to port 23
EthernetServer server(23);

bool callback2(const char *itemID, const opcOperation opcOP, const bool value)
{
  static bool ledValue = false;
  if (opcOP == opc_opwrite)
  {
    ledValue = value;
    if (ledValue == HIGH) {
      digitalWrite(ledPin, HIGH);
      Serial.println("HIGH");
    }
    else {
      digitalWrite(ledPin, LOW);
      Serial.println("LOW");
    }
  }
  else
    return ledValue;
}
void setup()
{
    Ethernet.init(10); 
    // initialize the ethernet device
  Ethernet.begin(mac, ip);
  // put your setup code here, to run once:
  pinMode(ledPin, OUTPUT);

  aOPCSerial.setup();
  aOPCSerial.addItem("DO1", opc_readwrite, opc_bool, callback2);
}

void loop()
{
  // put your main code here, to run repeatedly:
  aOPCSerial.processOPCCommands();
}
1 Like

Please read the documentation of the library you probably use, the first section ("How to use") shows the error you made immediately.

Thank you so much for your reply.

There was a problem in program. I was trying to connect via ETHERNET protocol using Syntax of Serial in the program. I am attaching the code below.
But, This is also working for COM tab not for UA.

kindly enlighten me regarding what I have to do for UA.
Thank you in advance!

#include <OPC.h>
#include <Bridge.h>
#include <SPI.h>
#include <Ethernet.h>
OPCEthernet OPCE;

int p1;
int inputpin=8;
int ledPin = 13;

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] ={0x90, 0xA2, 0xDA, 0x0F, 0x08, 0xE1};

IPAddress ip(192, 168, 192, 157);
//IPAddress myDns(8, 8, 8, 8);
//IPAddress gateway(192, 168, 192, 1);
IPAddress subnet(255, 255, 255, 0);

const int listen_port = 4840;
// telnet defaults to port 23
//EthernetServer server(80);
bool i1(const char *itemID, const opcOperation opcOP, const bool valor)
{
  p1= digitalRead(inputpin);
  return p1;
}
bool o1(const char *itemID, const opcOperation opcOP, const bool valor)
{
  static bool valor_led = false;
  if (opcOP == opc_opwrite)
  {
    valor_led = valor;
    if (valor) {
      digitalWrite(ledPin, HIGH);
      Serial.println("HIGH");
    }
    else {
      digitalWrite(ledPin, LOW);
      Serial.println("LOW");
    }
  }
  else
    return valor_led;
}

void setup()
{

  // put your setup code here, to run once:
  pinMode(ledPin, OUTPUT);
  pinMode(inputpin, OUTPUT);
  OPCE.setup(listen_port,mac,ip);
  OPCE.addItem("DIGITAL_OUTPUT", opc_readwrite, opc_bool, o1);
  OPCE.addItem("DIGITAL_INPUT", opc_readwrite, opc_bool, i1);
}

void loop()
{
  OPCE.processOPCCommands();
}

Hello,
This OPC.h library does not contain any function related UA.
Anyone know about any library for OPC UA or how to use OPC UA protocol for Arduino please guide me.
Thanks in advance!

I don't know where you have a tab here. OPC is using COM for the communication with your Windows device so you might have the term COM from there. But I haven't found out what you mean by "UA" in this context.

I am taking about section(UA) shown in below image.

where I am getting error related to timeout

The IP address doesn't match.

No, there is something wrong with code. I have taken it was for another device having that series.

I think there is problem in program.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.