OPCUA - UaExpert Arduino Ethernet Shield

Questions regarding the use of the UaExpert.

Moderator: uaexpert

Post Reply
Trung21
Jr. Member
Jr. Member
Posts: 1
Joined: 24 Sep 2022, 20:50

OPCUA - UaExpert Arduino Ethernet Shield

Post by Trung21 »

Hello,
I have an Arduino Uno and a Temeprature Sensor. I want to use the Arduino with an Ethernet Sheild as a server and give the data to my PC. I Want to use OPCUA UaExpert. I use the opc.h library and the example code that ist given.

The code ist the following:

Code: Select all

/*
 * A generic sketch for use with the Arduino OPC or Visual OPC Builder from www.st4makers.com
 */
#include <OPC.h>
#include <Bridge.h>
#include <Ethernet.h>
#include <SPI.h>

/*
 * Declaring the OPC object
 */
OPCEthernet myArduinoUno;

/*
 * MAC address from Ethernet shield sticker under board
 */
byte mac[] = { 0xA8, 0x61, 0x0A, 0xAE, 0xAA, 0x8D };

/*
 * Set your network configuration
 */
IPAddress ip(192, 168, X, XX);

IPAddress gateway(192, 168, X, X);
IPAddress dns_server(192,168,X,X);
IPAddress subnet(255,255,255,X);

/*
 * Server listen port
 */
const int listen_port = 80;

opcOperation digital_status_input[14], analog_status_input[6];

bool readwrite_digital(const char *itemID, const opcOperation opcOP, const bool value)
{
  byte port;
  
  port = atoi(&itemID[1]);

  if (opcOP == opc_opwrite) {
    if (digital_status_input[port] == opc_opread) {
      digital_status_input[port] = opc_opwrite;
      pinMode(port,OUTPUT);
    }
      
    digitalWrite(port,value);  
  }
  else
  {
    if (digital_status_input[port] == opc_opwrite) {
      digital_status_input[port] = opc_opread;
     // pinMode(port,INPUT);
    } 

    return digitalRead(port); 
  }  

}

int readwrite_analog(const char *itemID, const opcOperation opcOP, const int value) {
  byte port;
  
  port = atoi(&itemID[1]);

  if (opcOP == opc_opwrite) {
    if (analog_status_input[port] == opc_opread) {
      analog_status_input[port] = opc_opwrite;
      pinMode(port,OUTPUT);   
    }
     
    analogWrite(port,value);  
  }
  else
  {
    if (analog_status_input[port] == opc_opwrite) {
      analog_status_input[port] = opc_opread;
      //pinMode(port,INPUT);   
    } 

    return analogRead(port); 
  }  

}

void setup() {
  byte k;
  for (k=0;k<14;k++) digital_status_input[k] = opc_opread; 
  for (k=0;k<5;k++)  analog_status_input[k] = opc_opread; 
  
  /*
   * OPC Object initialization
   */
  myArduinoUno.setup(listen_port,mac,ip); 

  myArduinoUno.addItem("D0",opc_readwrite, opc_bool, readwrite_digital);
  myArduinoUno.addItem("D1",opc_readwrite, opc_bool, readwrite_digital);
  myArduinoUno.addItem("D2",opc_readwrite, opc_bool, readwrite_digital);
  myArduinoUno.addItem("D3",opc_readwrite, opc_bool, readwrite_digital);
  myArduinoUno.addItem("D4",opc_readwrite, opc_bool, readwrite_digital);
  myArduinoUno.addItem("D5",opc_readwrite, opc_bool, readwrite_digital);

  
  myArduinoUno.addItem("A0",opc_readwrite, opc_int, readwrite_analog);

}

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

I use UaExpert as my client to read the Sensor data. Now I have the problem that I get the Error Code:
"Discovery Findservers on opc.tpc://192.168.X.X failed (BadTimeout)"

opc.tpc://192.168.X.X is the URL that I use to connect to the Arduino uno.

Can someone help me?

User avatar
Support Team
Hero Member
Hero Member
Posts: 3057
Joined: 18 Mar 2011, 15:09

Re: OPCUA - UaExpert Arduino Ethernet Shield

Post by Support Team »

Hi,

most likely the serverside implementation you use is not working properly. Please read the documentation of the server side code base you are using.

The UaExpert will work fine with correctly implemented and correctly configured OPC UA Servers.
Best regards
Unified Automation Support Team

Post Reply