通过REST API调用将设备添加到OPC-UA IoT Agent



我正在努力尝试通过API调用添加设备。如果我用docker-compse.yml启动docker容器,我可以通过以下REST API调用将设备加载到本地OPC-UA服务器。

curl http://localhost:4001/iot/devices -H "fiware-service: opcua_car" -H "fiware-servicepath: /demo" -H "Content-Type: application/json" -d @testCommands/add_device_NGSIv2.json

但是,如果我用docker-compse-external-server.yml启动docker容器,而不是iotagent4fiware/iotagent-opcua:latest使用iotagent4fiware/iotagent-opcua:1.3.4,并且我使用相同的API调用,我得到以下错误:

{"name":"WRONG_SYNTAX","message":"Wrong syntax in request: Errors found validating request."}

从Docker日志:

"op":"IoTAgentNGSI.RestUtils","time":"2022-05-12T19:47:59.467Z","lvl":"DEBUG","msg":"Errors found validating request: {
"valid":false,"errors": [
{"attribute":"pattern","property":"devices.0.commands.1.object_id","expected":"^([^<>();'="]+)+$","actual":"ns=3;s=Accelerate","message":"invalid input"},
{"attribute":"pattern","property":"devices.0.commands.0.object_id","expected":"^([^<>();'="]+)+$","actual":"ns=3;s=Stop","message":"invalid input"},
{"attribute":"pattern","property":"devices.0.attributes.4.object_id","expected":"^([^<>();'="]+)+$","actual":"ns=3;s=Oxigen","message":"invalid input"},
{"attribute":"pattern","property":"devices.0.attributes.3.object_id","expected":"^([^<>();'="]+)+$","actual":"ns=3;s=Temperature","message":"invalid input"},
{"attribute":"pattern","property":"devices.0.attributes.2.object_id","expected":"^([^<>();'="]+)+$","actual":"ns=3;s=EngineStopped","message":"invalid input"},
{"attribute":"pattern","property":"devices.0.attributes.1.object_id","expected":"^([^<>();'="]+)+$","actual":"ns=3;s=Acceleration","message":"invalid input"},
{"attribute":"pattern","property":"devices.0.attributes.0.object_id","expected":"^([^<>();'="]+)+$","actual":"ns=3;s=EngineBrake","message":"invalid input"},
{"attribute":"pattern","property":"devices.0.lazy.0.object_id","expected":"^([^<>();'="]+)+$","actual":"ns=3;s=Speed","message":"invalid input"}
]
}

然后,如果我在Node.js中运行代理,我得到相同的错误:

{"name":"WRONG_SYNTAX","message":"Wrong syntax in request: Errors found validating request."}

如果我尝试使用iotagent4fiware/iotagent-opcua:latest,这应该与在Node.js中运行克隆存储库相同,它似乎忽略了configuration.properties文件中存在的endpointUrl,并且它尝试始终连接到opc.tcp://iotcarsrv:5001/UA/CarServer。当然,连接失败…

我很困惑的行为,我不能添加任何东西到IoTAgent。

请尝试使用此curl添加新设备

curl --location --request POST 'http://localhost:4001/iot/devices' 
--header 'fiware-service: opcua_car' 
--header 'fiware-servicepath: /demo' 
--header 'Content-Type: application/json' 
--data-raw '{
"devices": [
{
"device_id": "age03_Car",
"entity_name": "age03_Car",
"entity_type": "Device",
"attributes": [
{
"object_id": "ns=3;s=EngineBrake",
"name": "EngineBrake",
"type": "Number"
}, {
"object_id": "ns=3;s=Acceleration",
"name": "Acceleration",
"type": "Number"
}, {
"object_id": "ns=3;s=EngineStopped",
"name": "EngineStopped",
"type": "Boolean"
}, {
"object_id": "ns=3;s=Temperature",
"name": "Engine_Temperature",
"type": "Number"
}, {
"object_id": "ns=3;s=Oxigen",
"name": "Engine_Oxigen",
"type": "Number"
}, {
"object_id": "ns=3;s=DataBlocksGlobal_3_dbRfidCntr_3_ID1_3_xBusy",
"name": "DataBlocksGlobal_3_dbRfidCntr_3_ID1_3_xBusy",
"type": "String"
}, {
"object_id": "ns=3;s=DataBlocksGlobal_3_dbRfidCntr_3_ID1_3_xBusyStatus",
"name": "DataBlocksGlobal_3_dbRfidCntr_3_ID1_3_xBusyStatus",
"type": "Boolean"
}
],
"lazy": [
{
"object_id": "ns=3;s=Speed",
"name": "Speed",
"type": "Number"
}, {
"object_id": "ns=3;s=GPSCoordinates",
"name": "GPSCoordinates",
"type": "Number"
}
],
"commands": [
{
"object_id": "ns=3;s=Stop",
"name": "Stop",
"type": "command"
}, {
"object_id": "ns=3;s=Accelerate",
"name": "Accelerate",
"type": "command"
}, {
"object_id": "ns=3;s=ActivateSensor",
"name": "ActivateSensor",
"type": "command"
}, {
"object_id": "ns=3;s=DeactivateSensor",
"name": "DeactivateSensor",
"type": "command"
}, {
"object_id": "ns=3;s=ToggleSensorActivation",
"name": "ToggleSensorActivation",
"type": "command"
}, {
"object_id": "ns=3;s=LaunchMissiles",
"name": "LaunchMissiles",
"type": "command"
}
]
}
]
}

我找到了一种使其工作的方法,查看了存储库上的另一个问题。使用"*";不是"="one_answers":"我已经克服了语法问题,而不是";"

该语法存在于文件testCommandsMultiDeviceTestadd_device_lazy_attrs.json中,但没有记录。

最新更新