Open jhoggood opened 5 years ago
Turns out KepserverEX 6.7.1046.0 OPC-UA Server doesn't like the client.disconnect() operation for some reason.
Any suggestions on why client.disconnect() fails on KepserverEX would be appreciated. Also, I'm not sure I understand how this subscribe_data_change() operation is working either as even if I then execute a subscription1.unsubscribe(nodehandle1) in the try: block after the subscribe_data_change() operation my code continues to execute.
Environment: Ubuntu 18.04 LTS, Python 2.7.15, Python-OPCUA Kepware KepserverEX 6.7.1046.0
Problem: This code below executes client.get_node(xxx) just fine. The client.create_subscription(xxxxxx) will only work repeatedly if you have the time.sleep() otherwise it fails as follows:
ubuntu@ip-172-31-28-53:~/ProcessDataCollector/Source$ python PDC_Main.py PDC_MAIN-I-MAIN, Logging WARN level enabled PDC_MAIN-I-MAIN, Client instantiated PDC_MAIN-I-MAIN, Client connected
PDC_MAIN-I-MAIN, Root: Node(TwoByteNodeId(i=84)) PDC_MAIN-I-MAIN, Root Name: QualifiedName(0:Root) PDC_MAIN-I-MAIN, Root Children: [Node(TwoByteNodeId(i=85)), Node(TwoByteNodeId(i=86)), Node(TwoByteNodeId(i=87))]
PDC_MAIN-I-MAIN, Objects: Node(TwoByteNodeId(i=85)) PDC_MAIN-I-MAIN, Child Objects: [Node(FourByteNodeId(i=2253)), Node(StringNodeId(ns=2;s=_AdvancedTags)), Node(StringNodeId(ns=2;s=_ConnectionSharing)), Node(StringNodeId(ns=2;s=_CustomAlarms)), Node(StringNodeId(ns=2;s=_DataLogger)), Node(StringNodeId(ns=2;s=_EFMExporter)), Node(StringNodeId(ns=2;s=_IDF_for_Splunk)), Node(StringNodeId(ns=2;s=_IoT_Gateway)), Node(StringNodeId(ns=2;s=_LocalHistorian)), Node(StringNodeId(ns=2;s=_Redundancy)), Node(StringNodeId(ns=2;s=_Scheduler)), Node(StringNodeId(ns=2;s=_SecurityPolicies)), Node(StringNodeId(ns=2;s=_SNMP Agent)), Node(StringNodeId(ns=2;s=_System)), Node(StringNodeId(ns=2;s=_ThingWorx)), Node(StringNodeId(ns=2;s=Channel1)), Node(StringNodeId(ns=2;s=Data Type Examples)), Node(StringNodeId(ns=2;s=Painting)), Node(StringNodeId(ns=2;s=Simulation Examples))]
PDC_MAIN-I-MAIN, Tag1 Name: Node(StringNodeId(ns=2;s=Painting.Oven.Fan)) PDC_MAIN-I-MAIN, Tag1 Value: 10.010052681
PDC_MAIN-I-MAIN, Subscription created
PDC_MAIN-I-SUBHAND, Data Change Event Handler: Node(StringNodeId(ns=2;s=Painting.Oven.Fan)) 10.010052681 PDC_MAIN-I-SUBHAND, Data Change Event Handler: Node(StringNodeId(ns=2;s=Painting.Oven.Fan)) 10.3241558075 PDC_MAIN-I-SUBHAND, Data Change Event Handler: Node(StringNodeId(ns=2;s=Painting.Oven.Fan)) 10.9410829544 PDC_MAIN-I-SUBHAND, Data Change Event Handler: Node(StringNodeId(ns=2;s=Painting.Oven.Fan)) 11.5643444061 PDC_MAIN-I-SUBHAND, Data Change Event Handler: Node(StringNodeId(ns=2;s=Painting.Oven.Fan)) 11.8836870193 PDC_MAIN-I-SUBHAND, Data Change Event Handler: Node(StringNodeId(ns=2;s=Painting.Oven.Fan)) 12.4966344833 PDC_MAIN-I-SUBHAND, Data Change Event Handler: Node(StringNodeId(ns=2;s=Painting.Oven.Fan)) 13.0901699066 PDC_MAIN-I-MAIN, Subscribe done nodehandle1: 1
PDC_MAIN-F-MAIN, Exception occurred PDC_MAIN-I-MAIN, Client disconnected WARNING:opcua.client.ua_client.Socket:ServiceFault from server received while waiting for publish response ERROR:concurrent.futures:exception calling callback for <Future at 0x7f6555e034d0 state=finished returned Buffer> Traceback (most recent call last): File "/home/ubuntu/.local/lib/python2.7/site-packages/concurrent/futures/_base.py", line 331, in _invoke_callbacks callback(self) File "/home/ubuntu/.local/lib/python2.7/site-packages/opcua/client/ua_client.py", line 469, in _call_publish_callback self._uasocket.check_answer(data, "while waiting for publish response") File "/home/ubuntu/.local/lib/python2.7/site-packages/opcua/client/ua_client.py", line 88, in check_answer hdr.ServiceResult.check() File "/home/ubuntu/.local/lib/python2.7/site-packages/opcua/ua/uatypes.py", line 233, in check raise UaStatusCodeError(self.value) BadSessionClosed: The session was closed by the client.(BadSessionClosed) WARNING:opcua.client.ua_client.Socket:ServiceFault from server received while waiting for publish response ERROR:concurrent.futures:exception calling callback for <Future at 0x7f6555e03250 state=finished returned Buffer> Traceback (most recent call last): File "/home/ubuntu/.local/lib/python2.7/site-packages/concurrent/futures/_base.py", line 331, in _invoke_callbacks callback(self) File "/home/ubuntu/.local/lib/python2.7/site-packages/opcua/client/ua_client.py", line 469, in _call_publish_callback self._uasocket.check_answer(data, "while waiting for publish response") File "/home/ubuntu/.local/lib/python2.7/site-packages/opcua/client/ua_client.py", line 88, in check_answer hdr.ServiceResult.check() File "/home/ubuntu/.local/lib/python2.7/site-packages/opcua/ua/uatypes.py", line 233, in check raise UaStatusCodeError(self.value) BadSessionClosed: The session was closed by the client.(BadSessionClosed) Traceback (most recent call last): File "PDC_Main.py", line 76, in
eventhandle1 = subscription1.subscribe_events()
File "/home/ubuntu/.local/lib/python2.7/site-packages/opcua/common/subscription.py", line 210, in subscribe_events
return self._subscribe(sourcenode, ua.AttributeIds.EventNotifier, evfilter, queuesize=queuesize)
File "/home/ubuntu/.local/lib/python2.7/site-packages/opcua/common/subscription.py", line 228, in _subscribe
mids[0].check()
File "/home/ubuntu/.local/lib/python2.7/site-packages/opcua/ua/uatypes.py", line 233, in check
raise UaStatusCodeError(self.value)
opcua.ua.uaerrors._auto.BadMonitoredItemFilterUnsupported: The server does not support the requested monitored item filter.(BadMonitoredItemFilterUnsupported)
Library Imports
import sys sys.path.insert(0, "..") import time import logging from opcua import Client, ua
from opcua import Subscription
OPC-UA Client event handlers
class SubHandler(object):
OPC-UA Server data change event handler
Main routine
if name == "main":
Set Python logging level