0
votes

I want to use Azure to connect to an existing OPC at my place of work. From what I can see it requires setting up an azure iot hub. I have found tutorials describing how to set up an iot hub but nothing that demonstrates how to communicate with an existing OPC. Essentially I want to read data from the OPC to run machine learning tools (with azure ml) then send that info back to the OPC. Any help or ideas to point me in the right direction would be great!

1
what does OPC mean in your context?silent

1 Answers

0
votes

There is a project called OPC-UA publisher.

OPC-UA publisher is an application that acts as a bridge between your OPC server and IoT Hub. It can subscribe to the certain nodes(that you select in the configuration), and publish them to the IoT Hub in the desired format.

You can run it as a console application, as a container, or as a container in the combination with IoT Edge.

How to set up and how does it work: https://github.com/Azure/iot-edge-opc-publisher

An Example how to build and run locally:

  1. Navigate in the terminal to the folder where you downloaded the project
  2. docker build -t your_container_registry/opcpublisher .
  3. Do not forget the dot in the last command
  4. docker run your_container_registry/opcpublisher --dc="device_connection_string_retrieved_from_iot_hub" --ns=true --ih=Http1 --pf="C:\\Users\\User\\Desktop\\OPC\\publishednodes.json"

ns - no shutdown, publisher runs for the time being

publishednodes.json example:

[
    {
    // example for an EnpointUrl is: opc.tcp://192.168.178.26:62541/Quickstarts/ReferenceServer
    "EndpointUrl": "opc.tcp://192.168.16.183:4840/freeopcua/server",
    // allows to access the endpoint with SecurityPolicy.None when set to 'false' (no signing and encryption applied to the OPC UA communication), default is true
    "UseSecurity": false,
    "OpcNodes": [
      {
        // identifies the OPC node to publish in either NodeId format (contains "ns=") or ExpandedNodeId format (contains "nsu=")
        "Id": "nsu=http://example.proof.com;i=2",
        // specifies the sampling interval OPC Publisher requests the server to sample the node value
        "OpcSamplingInterval": 500,
        // specifies the publishing interval OPC Publisher requests the server to publish the node value, it will only be published if the value has changed
        "OpcPublishingInterval": 500,
        // specifies that there should be a heartbeat generated by OPC Publisher, this means that after the given interval the last message will be sent again with an updated SourceTimestamp value.
        "HeartbeatInterval": 1000,
        // specifies that the first event will not generate a telemetry event, this is useful when publishing a large amount of data to prevent a event flood at startup of OPC Publisher
        "SkipFirst": true
      },
      {
        // identifies the OPC node to publish in either NodeId format (contains "ns=") or ExpandedNodeId format (contains "nsu=")
        "Id": "nsu=http://example.proof.com;i=3",
        // specifies the sampling interval OPC Publisher requests the server to sample the node value
        "OpcSamplingInterval": 500,
        // specifies the publishing interval OPC Publisher requests the server to publish the node value, it will only be published if the value has changed
        "OpcPublishingInterval": 500,
        // specifies that there should be a heartbeat generated by OPC Publisher, this means that after the given interval the last message will be sent again with an updated SourceTimestamp value.
        "HeartbeatInterval": 1000,
        // specifies that the first event will not generate a telemetry event, this is useful when publishing a large amount of data to prevent a event flood at startup of OPC Publisher
        "SkipFirst": true
      }
    ]
  }
  // the format below (NodeId format) is only supported for backward compatibility. you need to ensure that the
  // OPC UA server on the configured EndpointUrl has the namespaceindex you expect with your configuration.
  // please use the ExpandedNodeId format as in the examples above instead.
  /* {
        "EndpointUrl": "opc.tcp://<your_opcua_server>:<your_opcua_server_port>/<your_opcua_server_path>",
        "NodeId": {
            "Identifier": "ns=0;i=2258"
        }
    } */
  // please consult the OPC UA specification for details on how OPC monitored node sampling interval and OPC subscription publishing interval settings are handled by the OPC UA stack.
  // the publishing interval of the data to Azure IoTHub is controlled by the command line settings (or the default: publish data to IoTHub at least each 1 second).
]