1

I am using OPC publisher to read values from an OPC ua server (siemens s7-1200) at a given interval, this works fine but when there is no connection between the server and the client I don't recieve any messages in iot hub.

I want to keep sending messages with a message of some sort that says that there is no connection between the server and OPC publisher device. How can I do this? The only thing I currently have is a log file.

Settings:

"Cmd": [
        "-c",
        "--PkiRootPath=/mount/pki",
        "--pf=/mount/published_nodes.json",
        "--lf=/mount/publisher.log",
        "--mm=PubSub",
        "--me=Json",
        "--fd=false",
        "--bs=100",
        "--bi=1000",
        "--di=20"
        "--aa"
    ],

Opc endpoint connected? : False

I can only see in the log file that the endpoint is not connected. I want to recieve messages in IotHub that says it is not connected.

Victor Pieper
  • 540
  • 2
  • 17
  • Did you try the **SessionStatusChanged** event of the OPC UA client in the OPC Publisher code to detect the connection loss? – SatishBoddu Mar 09 '23 at 16:27
  • @SatishBoddu do you think you could elaborate this? I am not sure what you mean by this and I can't find anything about this – Victor Pieper Mar 10 '23 at 08:29
  • // initialize the OPC UA client session 'm_session = new Session(m_configuration); m_session.SessionStatusChanged += Session_SessionStatusChanged;' and in the function 'Session_SessionStatusChanged' do the check as shown below! ' if (reason == SessionEventReason.ConnectionLost) { Console.WriteLine("OPC UA client connection lost."); // insert your code here to handle the connection loss }' – SatishBoddu Mar 15 '23 at 07:02
  • If the client is unable to establish a connection to the server at startup, the event will not be raised, that what i assume here, so we may need to make use of checking heartbeat!!! – SatishBoddu Mar 15 '23 at 07:04

1 Answers1

0

You can use the heartbeat mechanism for this purpose by configuring HeartbeatIntervals. You can do this globally for all the nodes in configuration by setting a DefaultHeartbeatInterval via command line as described here: https://github.com/Azure/Industrial-IoT/blob/main/docs/modules/publisher-commandline.md. Alternatively, you can enable HeartbeatInterval per selected nodes in the published_nodes.json configuration file like described here: https://github.com/Azure/Industrial-IoT/blob/main/docs/modules/publishednodes_2.8.json.

  • The heartbeat mechanism does indeed keep send messages when there is no message recieved. However if the connection between the device and the OPC ua server is no more. It still stops sending messages to iothub. – Victor Pieper Apr 13 '23 at 07:57