thingsboard gateway opcua写入设备数据实现反控

java | 2021-11-29 17:20:55

1.配置thingsboard gateway

tb_gateway.yaml

thingsboard:
  host: 192.168.1.108
  port: 1883
  remoteShell: false
  remoteConfiguration: false
  statsSendPeriodInSeconds: 3600
  checkConnectorsConfigurationInSeconds: 60
  security:
    accessToken: xqgLVPRFxZC4v2WNFd3W
  qos: 1
storage:
  type: memory
  read_records_count: 100
  max_records_count: 100000

connectors:

 -
   name: OPC-UA Connector
   type: opcua
   configuration: opcua.json

主要配置thingsboard 服务地址和mqtt端口,以及数采使用opcua,数据传到tthingsboard平台会自动创建设备

opcua.json配置

{
  "server": {
    "name": "OPC-UA Default Server",
    "url": "localhost:4840/freeopcua/server/",
    "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": "temperature °C",
            "path": "${ns=2;i=5}"
          }
        ],
        "timeseries": [
          {
            "key": "humidity",
            "path": "${Root\.Objects\.Device1\.TemperatureAndHumiditySensor\.Humidity}"
          },
          {
            "key": "batteryLevel",
            "path": "${Battery\.batteryLevel}"
          }
        ],
        "rpc_methods": [
          {
            "set_value": "multiply"
          }
        ],
        "attributes_updates": [
          {
            "attributeOnThingsBoard": "deviceName",
            "attributeOnDevice": "Root\.Objects\.Device1\.serialNumber"
          }
        ]
      }
    ]
  }
}

配置opcuaserver地址,注意rpc_methods中的set_value,就是我要写到设备数据的方法,也就是这里会写到上面配置的opcserver,那怎么调这个方法?

是通过前面配置的thingsboard mqtt的服务来实现的,下面有两种常见的方法

 

 

 

2.thingsboard平台实现反控

通过tb的部件实现反控

菜单-仪表板库-添加仪表板库-添加部件-选择Control wedgets-选择SENDRPC

数据这里选择设备,高级这里填写对应到opcua rpc_method里面配置得方法名,参数填写点位和数值,就配置完成了

 

3.http调用RPC接口实现反控

默认情况下规则链根节点都有rpc节点,没有就拖一个,这个时候就可以通过http接口调用rpc服务

案例:

http

curl -v -X POST -d @set-gpio-request.json http://localhost:8080/api/plugins/rpc/twoway/$DEVICE_ID 
--header "Content-Type:application/json" 
--header "X-Authorization: $JWT_TOKEN"

json

{
  "method": "set_value",
  "params": {
    "value": ["{ns=1;s=PLC_Off}",1]
  }
}

 

参考:

thingsboard调用rpc:https://thingsboard.io/docs/user-guide/rpc/

thingsboard gateway opcua配置方法:https://thingsboard.io/docs/iot-gateway/config/opc-ua/

 

 

 

 

登录后即可回复 登录 | 注册
    
关注编程学问公众号