thingsboard / thingsboard-gateway

Open-source IoT Gateway - integrates devices connected to legacy and third-party systems with ThingsBoard IoT Platform using Modbus, CAN bus, BACnet, BLE, OPC-UA, MQTT, ODBC and REST protocols
https://thingsboard.io/docs/iot-gateway/what-is-iot-gateway/
Apache License 2.0
1.7k stars 823 forks source link

I can connect to OPCUA Server from Thingsboard Iot Gateway, but device not getting created. [HELP] #529

Closed jainabhishekindia closed 2 years ago

jainabhishekindia commented 3 years ago

Hi,

I am using below for opcua.json:

{ "server": { "name": "OPC-UA Default Server", "url": "xxxxxxxxxx:4840/", "timeoutInMillis": 5000, "scanPeriodInMillis": 5000, "disableSubscriptions":false, "subCheckPeriodInMillis": 100, "showMap": false, "security": "Basic128Rsa15", "identity": { "type": "anonymous" }, "mapping": [ { "deviceNodePattern": "Root.Objects.Device1", "deviceNamePattern": "Device ${Root.Objects.Device1.serialNumber}", "attributes": [ { "key": "Humidity", "path": "${ns=2;i=5}" } ], "timeseries": [ { "key": "Temperature", "path": "${ns=2;i=4}" } ], "attributes_updates": [ { "attributeOnThingsBoard": "deviceName", "attributeOnDevice": "Root.Objects.Device1.serialNumber" } ] } ] } }

=============================================================================================== And I am using below as my opcuaServer:

import sys import time

from opcua import ua, Server

if name == "main":

server = Server() server.set_endpoint("opc.tcp://0.0.0.0:4840/")

name = "OPC_SIMULATION_SERVER" idx = server.register_namespace(name)

device = server.nodes.objects.add_object(idx, "Device1") name = server.nodes.objects.add_variable(idx, "serialNumber", "OPCUADevice") name.set_writable() temperature_and_humidity = device.add_object(idx, "TemperatureAndHumiditySensor") temperature = temperature_and_humidity.add_variable(idx, "Temperature", 56.7) humidity = temperature_and_humidity.add_variable(idx, "Humidity", 68.7)

server.start()

try: count = 0 while True: time.sleep(1) count += 0.1

temperature.set_value(count)

finally: server.stop()

I am getting below WARNING:

""2021-06-15 07:44:38" - INFO - [tb_loader.py] - tb_loader - 66 - Import OpcUaConnector from /usr/local/lib/python3.7/site-packages/thingsboard_gateway-2.6-py3.7.egg/thingsboard_gateway/connectors/opcua." ""2021-06-15 07:44:38" - INFO - [opcua_connector.py] - opcua_connector - 99 - Starting OPC-UA Connector" ""2021-06-15 07:44:38" - INFO - [opcua_connector.py] - opcua_connector - 124 - OPC-UA connector OPC-UA Connector connected to server xx.xx.xx.xx:4840/" ""2021-06-15 07:44:39" - WARNING - [opcua_connector.py] - opcua_connector - 411 - Device name node - not found, skipping device..."

I also don't see the device getting created.

I followed instructions on https://thingsboard.io/docs/iot-gateway/install/source-installation/ link for installation of iot gateway. Can anyone please help.

OS: Amazon EC2 Linux.

imbeacon commented 3 years ago

Hi @jainabhishekindia ,

it looks like "serialNumber" variable not in the "Device1" object.

jainabhishekindia commented 3 years ago

I have below line in code:

name = server.nodes.objects.add_variable(idx, "serialNumber", "OPCUADevice")

jainabhishekindia commented 3 years ago

Do I need to add object inside Device1. Something like below:

serialNumber= device.add_object(idx, "serialNumber") serialNumber= serialNumber.add_variable(idx, "serialNumber", "OPCUADevice")

imbeacon commented 2 years ago

Hi @jainabhishekindia ,

yes, you can do like you told. Please create a new issue, if you cannot solve your problem.