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.76k stars 846 forks source link

[BUG] Write method doesn't allow! #1439

Open zlwjzf opened 5 months ago

zlwjzf commented 5 months ago

Describe the bug After kepware is connected to an Omron device and the opcua configuration of kepware is enabled, the tb-gateway is connected through the opcua protocol. Point values can be collected but cannot be modified. (The test point has read and write permissions)

opcua.json:

{ "server": { "name": "OPC-UA-Test1", "url": "42.64.26.253:49320", "timeoutInMillis": 5000, "scanPeriodInMillis": 5000, "disableSubscriptions": false, "subCheckPeriodInMillis": 100, "showMap": true, "security": "Basic128Rsa15", "identity": { "username": "username", "password": "password" }, "mapping": [ { "deviceNodePattern": "${ns=2;s=SM1.GJYB}", "deviceNamePattern": "GJYB", "deviceTypePattern": "GJYB", "attributes": [], "timeseries": [ { "key": "Z1_ZA1_ONI", "path": "${ns=2;s=SM1.GJYB.Z1_ZA1_ONI}" }, { "key": "Z1_ZA1_ONO", "path": "${ns=2;s=SM1.GJYB.Z1_ZA1_ONO}" } ] } ] } }

tb-gateway log: ` - |DEBUG| - [opcua_connector.py] - opcua_connector - datachange_notification - 661 - [SUBSCRIPTION] Data to ThingsBoard: {'deviceName': 'GJYB', 'deviceType': 'GJYB', 'attributes': [], 'telemetry': [{'ts': 1719391815118, 'values': {'Z1_ZA1_ONO': 'False'}}]}"

operation procedure: Calls the rpc-v-2-controller interface in swagger-ui with the following parameters: { "method": "set", "params": "ns=2;s=SM1.GJYB.Z1_ZA1_ONO;value=true" , "persistent": true, "timeout": 5000 }

Versions (please complete the following information):

zlwjzf commented 4 months ago

Hello, I have found the cause of the problem. When calling the RPC set method, replace node.set_value(value) in the source opcua_connector.py file with the following code to achieve the simulated opcua point in kepware to write values dv = ua.DataValue(ua.Variant(int(value), ua.VariantType.Int16)) dv.ServerTimestamp = None dv.SourceTimestamp = None node.set_value(dv) Can you adapt these changes to the latest version?

zlwjzf commented 4 months ago

https://github.com/FreeOpcUa/opcua-asyncio/issues/30

shanjunying commented 3 months ago

I also encountered the same problem, writing to the opcua service provided by kepserver resulted in the error "opcua. ua. uaerrors. auto. BadWriteNotSupported:" The server does not support writing the combination of value, status, and timestamps provided. "(BadWriteNotSupported) but writing to the service provided by Prosys OPC UA Simulation Server did not cause any problems

shanjunying commented 3 months ago

dv = ua.DataValue(ua.Variant(int(value), ua.VariantType.Int16)) dv.ServerTimestamp = None dv.SourceTimestamp = None node.set_value(dv)

Where should these codes be added?Please tell me, thank you!

zlwjzf commented 2 months ago

thingsboard_gateway/connectors/opcua/opcua_connector.py In method server_side_rpc_handler if rpc_method == 'get': self.__gateway.send_rpc_reply(content['device'], content['data']['id'], {content['data']['method']: node.get_value(), 'code': 200}) else: ...... Load in else