1

I'm using Python for the OPC Client which I run on Node-Red. The OPC Client functions to send sensor data to the Thingsboard. However, after 1 hour of running on Node-Red, an error appears as below

My Code:

from opcua import Client
import paho.mqtt.client as mqtt
import time
import json

url = "opc.tcp://D201002809747:4840"
client = Client(url)
client.connect()
print ("Sudah Connect")

iot_hub = "iothub.toyota.co.id"
port = "" #port PLC
username = "MdduLiSzC787aY8DrYNf"
password = ""
topic = "v1/devices/me/telemetry"

iot_hub_client = mqtt.Client()
iot_hub_client.username_pw_set(username, password)
iot_hub_client.connect(iot_hub, port)
print ("Connected to IoT Hub")

data = dict()
while True:
el = client.get_node("ns=2;s=Device1.DATA.MOTOR_CV3_ALONGATION")
elongation = el.get_value()
print (elongation)

data['Elongation'] = int(elongation)
data_out = json.dumps(data)
iot_hub_client.publish(topic, data_out, 0)
    
time.sleep(2)

My Error:

`exit code: 1, Traceback (most recent call last): File "C:\Users\admin\coba.py", line 25, in <module> elong = el.get_value() ^^^^^^^^^^^^^^

File "C:\Users\admin\AppData\Roaming\Python\Python311\site-packages\opcua\common\node.py", line 155, in get_value result = self.get_data_value() ^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\admin\AppData\Roaming\Python\Python311\site-packages\opcua\common\node.py", line 164, in get_data_value return self.get_attribute(ua.AttributeIds.Value) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\admin\AppData\Roaming\Python\Python311\site-packages\opcua\common\node.py", line 275, in get_attribute result = self.server.read(params) ^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\admin\AppData\Roaming\Python\Python311\site-packages\opcua\client\ua_client.py", line 347, in read data = self._uasocket.send_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File...\

Matteo Zanoni
  • 3,429
  • 9
  • 27

0 Answers0