import sys
import time                                  #import the time module
sys.path.insert(0, "..")
from opcua import Client
from opcua import ua
############################################################
class SubHandler(object):

	"""
	Subscription Handler. To receive events from server for a subscription
	data_change and event methods are called directly from receiving thread.
	Do not do expensive, slow or network operation there. Create another 
	thread if you need to do such a thing
	"""

	def datachange_notification(self, node, val, data):			#self, node, val, data
		aaa=str(val)             
	def event_notification(self, event):
		print("New event", event)
##############################################################
client = Client("opc.tcp://localhost:4840")
client.connect()
root = client.get_root_node()
root.get_children()
abcL = root.get_child(["0:Objects", "2:DeviceSet", "4:CODESYS Control for Raspberry Pi SL", "4:Resources", "4:Application", "3:Programs", "4:VAROPC", "4:abcL"])

handler = SubHandler()
sub = client.create_subscription(100, handler)
handle = sub.subscribe_data_change(abcL)
	


##########################################################################

cc=1

while cc == 1 :
	ctrl=abcL.get_value()
	time.sleep(2)
	print( 'ctrl= ',ctrl)
