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

External hosts OPCUA #60

Closed manolait closed 2 years ago

manolait commented 2 years ago

Hello,

I have a local OPC server which I access via opc.tcp://localhost:5001/UA/CarServer. I have a nodejs client that queries this server to check that it works correctly.

I am following your tutoral to create the IoTAgent to that server but I have doubts when configuring the extra_hosts files:

In this case, how should I configure it? Also I do not understand the need to enter here the OPC server when in the AGECONF/config.properties file it is necessary to put the endpoint of the OPC server.

Best regards and thanks

MattiaMarzano-Eng commented 2 years ago

Hello, just committed the new compose to use the Agent with an external server. Here you can find the new version, just run it replacing your local ip address in: `extra_hosts:

Obviously you can rename also the server as you prefer changing the name also in AGECONF/config.properties

manolait commented 2 years ago

thanks for the update but could you tell me what is iotcarsrv? the name of the server?

extra_hosts: - "iotcarsrv:localhost".

On the other hand I am following your tutorial (https://github.com/Engineering-Research-and-Development/iotagent-opcua/blob/master/docs/user_and_programmers_manual.md) and it indicates The first line of the extra_hosts section is used by the Agent during the communication with the OPC UA Server. The second one is needed when the OPC UA Server responds to the mapping tool by returning its hostname. is this correct?

MattiaMarzano-Eng commented 2 years ago

iotcarsrv is the hostname of the server we provide, in your case opc.tcp://localhost:5001/UA/CarServer the server name/hostname is localhost. Better to use the ip address of the machine where the server is running, so extra_hosts: - "iotcarsrv:SERVER_IP_ADDRESS".

About the question related to extra_hosts you got the point, the first line is used during the communication with OPC UA Server. If in your test you're using the car server provided as example then you don't need to add the second line, but in case you're using another server you must change according to your needs the AGECONF/config.json and AGECONF/config.properties.

Last option is "you decided" to run the agent without a config.json, in this scenario the mapping tool generates the config.json (not provided) related to your server. Only in that case is needed the second line in extra_hosts because as you wrote the mapping tool needs the server hostname.

manolait commented 2 years ago

Thanks for the help, but I still don't understand how your extra_hosts URL works.

In the case of using the external opc server as follows opc.tcp://opcuaserver.com:48010

What would be this configuration?

extra_hosts: - "XXXX:SERVER_IP_ADDRESS".

On the other hand it is not clear to me the use of the mapping tool is necessary to delete the configuration file of the path AGECONF/config.json and when changing the configuration of AGECONF/config.properties the AGECONF/config.json file is generated again?

if I comment the line ## CONFIGURATION configuration=api of the AGECONF/config.propertie file what effect does it have?

MattiaMarzano-Eng commented 2 years ago

You have 2 options:

  1. Change extra_hosts in this way: extra_hosts: - "opcuaserver.com:SERVER_IP_ADDRESS"

Then in AGECONF/config.properties you need to change only: endpoint=opc.tcp://opcuaserver.com:48010

For AGECONF/config.json you can decide to define a new json following the structure like we have already done for the OPC-UA Car Server mapping your entities, attributes and so on.

  1. Add just the second line in extra_hosts like that: `extra_hosts:
    • "iotcarsrv:SERVER_IP_ADDRESS>"
    • "opcuaserver.com:SERVER_IP_ADDRESS"`

Then delete AGECONF/config.json, the mapping tool will produce the json file instead of you.

manolait commented 2 years ago

Thank you I will keep trying to make it work..... what I have understood is necessary the two extra_hosts to be able to do the mapping

this error is normal?

services.iotage.extra_hosts contains non-unique items, please remove duplicates from ['localhost:127.0.0.1', 'localhost:127.0.0.1'] This part is complicated and the documentation gives the impression that two OPC servers are required. One with iotcarsrv to bring the information from your opcserver and another one generated by us..... I don't understand the need to have two

Reviewing your index.js gives me the impression that the file to modify for the mapping is the conf/config.properties I suppose that when creating the volume the data will be moved.

I don't understand how your system works, it always tries to connect to opc.tcp://iotcarsrv:5001/UA/CarServer

I don't have iotcarsrv anywhere but it always tries. currently it has no config.json files as the mapping doesn't work I launch the docker and it doesn't get access to the server attached images

my docker

version: "3"

services:

  iotage:
    hostname: iotage
    image: iotagent4fiware/iotagent-opcua:latest
    networks:
      - hostnet
      - iotnet
    ports:
      - "4001:4001"
      - "4081:8080"
    extra_hosts:
      - "localhost:192.168.1.130"
    depends_on:
      - iotmongo
      - orion
    volumes:
      - ./AGECONF:/opt/iotagent-opcua/conf
      - ./certificates:/opt/iotagent-opcua/certificates
    environment:
      - IOTA_REGISTRY_TYPE=memory #Whether to hold IoT device info in memory or in a database
      - IOTA_LOG_LEVEL=DEBUG # The log level of the IoT Agent
      - IOTA_MONGO_HOST=iot_mongo # The host name of MongoDB
      - IOTA_MONGO_DB=iotagent_opcua # The name of the database used in mongoDB
      #comment if you mind using NGSI-ld
      #- IOTA_CB_NGSI_VERSION=ld
      - IOTA_FALLBACK_TENANT=opcua_car
      - IOTA_RELAX_TEMPLATE_VALIDATION=true

  iotmongo:
    hostname: iot_mongo
    image: mongo:4.2
    networks:
      - iotnet
    volumes:
      - iot_mongo_data:/data/db
      - iot_mongo_conf:/data/configdb

  ################ OCB ################

  orion:
    hostname: orion
    #replace fiware/orion:latest with fiware/orion-ld:0.7.0 if you mind using NGSI-ld
    image: fiware/orion:latest
    #image: fiware/orion-ld:0.7.0
    networks:
      - hostnet
      - ocbnet
    ports:
      - "1026:1026"
    depends_on:
      - orion_mongo
    # add -forwarding if using NGSI-ld
    #command: -statCounters -dbhost orion_mongo -logLevel INFO -forwarding
    command: -statCounters -dbhost orion_mongo -logLevel INFO

  orion_mongo:
    hostname: orion_mongo
    image: mongo:4.2
    networks:
      - ocbnet
    ports:
      - "27017:27017"
    volumes:
      - orion_mongo_data:/data/db
      - orion_mongo_conf:/data/configdb
    command: --nojournal

volumes:
  iot_mongo_data:
  iot_mongo_conf:
  orion_mongo_data:
  orion_mongo_conf:

networks:
  hostnet:
  iotnet:
  ocbnet:

My config.propierties

## SOUTHBOUND CONFIGURATION (OPC UA)
namespace-ignore=0,2,7
endpoint=opc.tcp://localhost:5001/UA/CarServer

## NORTHBOUND CONFIGURATION (ORION CONTEXT BROKER)
context-broker-host=orion
context-broker-port=1026
fiware-service=opcua_car
fiware-service-path=/demo

## AGENT CONFIGURATION
server-base-root=/
server-port=4001
provider-url=http://iotage:4001

device-registration-duration=P1M
device-registry-type=memory

log-level=DEBUG

namespaceIndex=3
namespaceNumericIdentifier=1000

# MONGO-DB CONFIGURATION (required if device-registry-type=mongodb)
mongodb-host=iotmongo
mongodb-port=27017
mongodb-db=iotagent
mongodb-retries=5
mongodb-retry-time=5

## DATATYPE MAPPING OPCUA --> NGSI
OPC-datatype-Number=Number
OPC-datatype-Decimal128=Number
OPC-datatype-Double=Number
OPC-datatype-Float=Number
OPC-datatype-Integer=Integer
OPC-datatype-UInteger=Integer
OPC-datatype-String=Text
OPC-datatype-ByteString=Text
#END DATATYPE MAPPING OPCUA --> NGSI

## SESSION PARAMETERS
requestedPublishingInterval=10
requestedLifetimeCount=1000
requestedMaxKeepAliveCount=10
maxNotificationsPerPublish=100
publishingEnabled=true
priority=10

#SubscriptionsStrategy
uniqueSubscription=true

## MONITORING PARAMETERS
samplingInterval=1
queueSize=10000
discardOldest=false

## SERVER CERT E AUTH
securityMode=None
securityPolicy=None
userName=
password=

#securityMode=SIGNANDENCRYPT
#securityPolicy=1Basic256
#password=password1
#userName=user1

#api-ip=192.168.13.153

## ADMINISTRATION SERVICES
api-port=8080

## POLL COMMANDS SETTINGS
polling=false
polling-commands-timer=30000
pollingDaemonFrequency=20000
pollingExpiration=200000

## AGENT ID
agent-id=age01_
entity-id=age01_Car # used only during tests

## CONFIGURATION
# configuration=api

## CHECK TIMER POLLING DEVICES
checkTimer=2000
Captura de pantalla 2021-10-25 a las 21 40 15 Captura de pantalla 2021-10-25 a las 21 46 37
manolait commented 2 years ago

please could you help me. Thank you

MattiaMarzano-Eng commented 2 years ago

Your set up is correct, but please replace "HOSTNAME" in the following parts, with a name you want to use for your server

endpoint=opc.tcp://HOSTNAME:5001/UA/CarServer in config.properties

and

`extra_hosts:

and in docker-compose please use v1.3.4 for the agent, we're investigating the issue related to the docker image for which the mapping tool doesn't start.

image: iotagent4fiware/iotagent-opcua:1.3.4

manolait commented 2 years ago

Hello,

thanks for the help I was going crazy with the mapping tool. It was a version problem.

My connection address is: opc.tcp://MacBook-Pro.local:5001/UA/CarServer

endpoint=opc.tcp://MacBook-Pro.local:5001/UA/CarServer

I don't know what to put in the second extra_hosts can't be the same because it gives error. What should I put?

I have added extra_hosts:

I still don't understand the need to have different HOST names for the mapping.

For now it seems to be getting better I deleted the config.json file by commenting out the configuration=api parameter and it generates the new config.json file but "contexts" : [ ], "contextSubscriptions" : [ ] are empty, it should take all the information from opcua no?

On the other hand is the config.json file necessary or could I do it through the API?

Thanks for everything. little by little I am getting to success.

MattiaMarzano-Eng commented 2 years ago

Don't need to use second line in extra_host if you have already edited endpoint=opc.tcp://MacBook-Pro.local:5001/UA/CarServer, then you can delete it.

The mapping tool is under improvements and will be released in the next months, by the way it generates a good starting point for your config.json, you can edit it as you prefer and restart the agent.

You can also use the API to add what mapping tool missed, but the config.json is mandatory to run the agent.

manolait commented 2 years ago

Hello,

Could you leave the config.json file with the basic configuration without the devices without contexts and be able to do it by the api of /4001/iot/devices ?

{
  "logLevel" : "DEBUG",
  "contextBroker" : {
    "host" : "orion",
    "port" : 1026
  },
  "server" : {
    "port" : 4001,
    "baseRoot" : "/"
  },
  "deviceRegistry" : {
    "type" : "memory"
  },
  "mongodb" : {
    "host" : "iotmongo",
    "port" : "27017",
    "db" : "iotagent",
    "retries" : 5,
    "retryTime" : 5
  },
  "types" : { },
  "browseServerOptions" : null,
  "service" : "opcua_car",
  "subservice" : "/demo",
  "providerUrl" : "http://iotage:4001",
  "pollingExpiration" : "200000",
  "pollingDaemonFrequency" : "20000",
  "deviceRegistrationDuration" : "P1M",
  "defaultType" : null,
  "contexts" : [ ],
  "contextSubscriptions" : [ ]
}
MattiaMarzano-Eng commented 2 years ago

It's already one of the possible scenarios in AGECONF folder. I will close the thread as it has been solved