Engineering-Research-and-Development / iotagent-opcua

IoT Agent for OPC UA protocol
https://iotagent-opcua.rtfd.io/
GNU Affero General Public License v3.0
41 stars 21 forks source link

Support of Scorpio Context Broker? #82

Closed IngMiad closed 1 year ago

IngMiad commented 1 year ago

Hello,

I have a question regarding the support of Scorpio Context Broker. Actually it seems that iotagent-opcua only supports Orion Context Broker - is it planned to also support Scorpio in the future?

Greetings!

MattiaMarzano-Eng commented 1 year ago

Hello, actually we're already compliant with NGSI-ld. You can try to setup (if you haven't done it yet)

 "contextBroker": {
        "host": "scorpioHostname",
        "port": scorpioPort
    }

in config.js to forward the requests to Scorpio Context Broker. Never had experience with that, but my expectation is that we're ready to use that CB since we support NGSI-ld

rosieks commented 1 year ago

Actually I'm also trying to work with Scorpio. What about different URLs. I think that right now agent call /v2/entities while scorpio/ngsi-ld assumes it will be ngsi-ld/v1/entities

MattiaMarzano-Eng commented 1 year ago

You can solve that issue using the config.json template provided as example where you can find the additional fields

"ngsiVersion": "ld",
"jsonLdContext": "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld",

allowing you to call ngsi-ld/v1/entities enpoint

IngMiad commented 1 year ago

Hello,

thank you for the quick response. Yes after some experiments it seems to work also with scorpio. I thought that registration URLs might differ in case of Scorpio, but this is not the case.

The differences I recognized is that it is hard to use mapping tool and auto-configuration. Scorpio needs much more time to start than Orion context broker, so that the automatic registrations at context broker fail (at least in my case). I tried to use docker-compose 'depends_on', but Scorpio needs around 20-30 seconds to 'really start', so that the IoT-Agent can't connect to broker for device registration.

So you have to add a wait-for-scorpio-to-be-ready mechanism or use REST API for device/registration configuration.

Anupamskd7 commented 1 year ago

Hi,

I tried as suggested by @MattiaMarzano-Eng by making necessary changes in the conf/config.json:

{ "logLevel" : "INFO", "multiCore" : true, "relaxTemplateValidation":true, "contextBroker" : { "host" : "gateway.default.svc.cluster.local", "port" : 9090 }, "server" : { "port" : 4001, "baseRoot" : "/" }, "deviceRegistry" : { "type" : "memory" }, "mongodb" : { "host" : "iotmongo", "port" : "27017", "db" : "iotagent_opcua", "retries" : 5, "retryTime" : 5 }, "types" : { "Device" : { "service" : "opcua_car", "subservice" : "/demo", "active" : [{ "name" : "EngineBrake", "type" : "Number" }, { "name" : "Acceleration", "type" : "Number" }, { "name" : "EngineStopped", "type" : "Boolean" }, { "name" : "Engine_Temperature", "type" : "Number" }, { "name" : "Engine_Oxigen", "type" : "Number" }, { "name" : "DataBlocksGlobal_3_dbRfidCntr_3_ID1_3_xBusy", "type" : "String" }, { "name" : "DataBlocksGlobal_3_dbRfidCntr_3_ID1_3_xBusyStatus", "type" : "Boolean" }, { "name" : "DataBlocksGlobal_3_dbRfidCntr_3_ID1_3_xDone", "type" : "String" }, { "name" : "DataBlocksGlobal_3_dbRfidCntr_3_ID1_3_xDoneStatus", "type" : "Boolean" }], "lazy" : [{ "name": "Speed", "type": "Number" }], "commands" : [{ "name" : "Error", "type" : "command" }, { "name" : "Stop", "type" : "command" }, { "name" : "Accelerate", "type" : "command" }, { "name" : "ActivateSensor", "type" : "command" }, { "name" : "DeactivateSensor", "type" : "command" }, { "name" : "ToggleSensorActivation", "type" : "command" }] } }, "browseServerOptions" : null, "service" : "opcua_car", "subservice" : "/demo", "providerUrl" : "http://iotage:4001", "pollingExpiration" : "200000", "pollingDaemonFrequency" : "20000", "deviceRegistrationDuration" : "P1M", "defaultType" : null, "contexts" : [ { "id" : "age01_Car", "type" : "Device", "service" : "opcua_car", "subservice" : "/demo", "polling" : false, "mappings" : [{ "ocb_id" : "Error", "opcua_id" : "ns=3;s=Error", "object_id" : null, "inputArguments" : [ ] },{ "ocb_id" : "Acceleration", "opcua_id" : "ns=3;s=Acceleration", "object_id" : null, "inputArguments" : [ ] }, { "ocb_id" : "EngineStopped", "opcua_id" : "ns=3;s=EngineStopped", "object_id" : null, "inputArguments" : [ ] }, { "ocb_id" : "Engine_Temperature", "opcua_id" : "ns=3;s=Temperature", "object_id" : null, "inputArguments" : [ ] }, { "ocb_id" : "Engine_Oxigen", "opcua_id" : "ns=3;s=Oxigen", "object_id" : null, "inputArguments" : [ ] }, { "ocb_id" : "DataBlocksGlobal_3_dbRfidCntr_3_ID1_3_xBusy", "opcua_id" : "ns=3;s=DataBlocksGlobal_3_dbRfidCntr_3_ID1_3_xBusy", "object_id" : null, "inputArguments" : [ ] }, { "ocb_id" : "DataBlocksGlobal_3_dbRfidCntr_3_ID1_3_xBusyStatus", "opcua_id" : "ns=3;s=DataBlocksGlobal_3_dbRfidCntr_3_ID1_3_xBusyStatus", "object_id" : null, "inputArguments" : [ ] }, { "ocb_id" : "DataBlocksGlobal_3_dbRfidCntr_3_ID1_3_xDone", "opcua_id" : "ns=3;s=DataBlocksGlobal_3_dbRfidCntr_3_ID1_3_xDone", "object_id" : null, "inputArguments" : [ ] }, { "ocb_id" : "DataBlocksGlobal_3_dbRfidCntr_3_ID1_3_xDoneStatus", "opcua_id" : "ns=3;s=DataBlocksGlobal_3_dbRfidCntr_3_ID1_3_xDoneStatus", "object_id" : null, "inputArguments" : [ ] }] } ], "contextSubscriptions" : [ { "id" : "age01_Car", "type" : "Device", "mappings" : [ { "ocb_id" : "Error", "opcua_id" : "ns=3;s=Error", "object_id" : "ns=3;i=1000", "inputArguments" : [ { "dataType" : 12, "type" : "Error Type" } ] }, { "ocb_id": "Speed", "opcua_id": "ns=3;s=Speed", "object_id": "ns=3;i=1000", "inputArguments" : [ ] }, { "ocb_id" : "Stop", "opcua_id" : "ns=3;s=Stop", "object_id" : "ns=3;i=1000", "inputArguments" : [ ] }, { "ocb_id" : "Accelerate", "opcua_id" : "ns=3;s=Accelerate", "object_id" : "ns=3;i=1000", "inputArguments" : [ { "dataType" : 6, "type" : "Intensity" } ] }, { "ocb_id" : "ActivateSensor", "opcua_id" : "ns=3;s=ActivateSensor", "object_id" : "ns=3;i=1000", "inputArguments" : [ { "dataType" : 6, "type" : "SensorIndex" } ] }, { "ocb_id" : "DeactivateSensor", "opcua_id" : "ns=3;s=DeactivateSensor", "object_id" : "ns=3;i=1000", "inputArguments" : [ { "dataType" : 6, "type" : "SensorIndex" } ] }, { "ocb_id" : "ToggleSensorActivation", "opcua_id" : "ns=3;s=ToggleSensorActivation", "object_id" : "ns=3;i=1000", "inputArguments" : [ { "dataType" : 6, "type" : "SensorIndex" } ] } ] } ] }

and AGECONF/config.json.: { "logLevel" : "INFO", "contextBroker" : { "host" : "gateway.default.svc.cluster.local", "port" : 9090 }, "server" : { "port" : 4001, "baseRoot" : "/" }, "deviceRegistry" : { "type" : "memory" }, "mongodb" : { "host" : "mongo-common-0.mongo-common", "port" : "27017", "db" : "iotagent_opcua", "retries" : 5, "retryTime" : 5 }, "types" : { "Device" : { "service" : "opcua_car", "subservice" : "/demo", "active" : [ ], "lazy" : [ ], "commands" : [ ] } }, "browseServerOptions" : null, "service" : "opcua_car", "subservice" : "/demo", "providerUrl" : "http://iotage:4001", "pollingExpiration" : "200000", "pollingDaemonFrequency" : "20000", "deviceRegistrationDuration" : "P1M", "defaultType" : null, "contexts" : [ ], "contextSubscriptions" : [] }

Still I am unable to connect IOTAgent OPC UA with Scorpio broker. Also, When I checked OPC UA logs, the default Context broker URL doesn't seem to change with the changes made in the config files:

"url": "http://orion:1026/ngsi-ld/v1/entityOperations/upsert/?options=update", "method": "POST", "headers": { "fiware-service": "opcua_car", "fiware-servicepath": "/demo", "Content-Type": "application/ld+json", "NGSILD-Tenant": "opcua_car", "NGSILD-Path": "/demo" }, "json": [ { "@context": "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.3.jsonld", "DataBlocksGlobal_3_dbRfidCntr_3_ID1_3_xDoneStatus": { "type": "Property", "value": true }, "id": "urn:ngsi-ld:Device:age01_Car", "type": "Device" } ] }

And the default service that gets provisioned also has cbHost": "orion:1026

@MattiaMarzano-Eng Could you please tell which config files are needed to be changed?

MattiaMarzano-Eng commented 1 year ago

Hello @Anupamskd7, please look at this template to update accordingly your config.json where are missing those fields "ngsiVersion": "ld", "jsonLdContext": "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld",

update also the docker compose ` #################################################################################################################

please comment out if you want to use NGSI-ld, the OPCUA Agent is provided with NGSIv2 as default configuration

  #- IOTA_CB_NGSI_VERSION=ld
  #- IOTA_JSON_LD_CONTEXT=https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.3.jsonld
  #################################################################################################################

` in thi section