2

I am trying to set up a system to save historic data with the flow like this: Prosys OPC-UA Server Simulation -> OPC-UA FIWARE IoT Agent -> Orion Context Broker -> FIWARE Cygnus Connector -> PostgreSQL database.

Here is the document I used to compose the docker-compose file:

Historic-Context-Flume

OPC-UA IoT Agent

Here is the docker-compose and .env file I used

docker-compose.yml

version: "3"
#secrets:
#   age_idm_auth:
#      file: age_idm_auth.txt

services:
  iotage:
    hostname: iotage
    image: iotagent4fiware/iotagent-opcua:1.3.4
    networks:
      - hostnet
      - iotnet
    ports:
      - "${AGENT_SERVER_PORT}:${AGENT_SERVER_PORT}"
      - "4081:8080"
    extra_hosts:
      - "iotcarsrv:192.168.50.167"
      - "HP:192.168.50.167"
    depends_on:
      - iotmongo
      - orion
    volumes:
      - ./AGECONF:/opt/iotagent-opcua/conf
      - ./certificates/charm:/opt/iotagent-opcua/certificates
    command: /usr/bin/tail -f /var/log/lastlog

  iotmongo:
    hostname: iotmongo
    image: mongo:3.4
    networks:
      - iotnet
    volumes:
      - iotmongo_data:/data/db
      - iotmongo_conf:/data/configdb

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

  orion:
    hostname: orion
    image: fiware/orion:latest
    networks:
      - hostnet
      - ocbnet
    ports:
      - "${ORION_PORT}:${ORION_PORT}"
    depends_on:
      - orion_mongo
    #command: -dbhost mongo
    entrypoint: /usr/bin/contextBroker -fg -multiservice -ngsiv1Autocast -statCounters -dbhost mongo -logForHumans -logLevel DEBUG -t 255

  orion_mongo:
    hostname: orion_mongo
    image: mongo:3.4
    networks:
      ocbnet:
        aliases:
          - mongo
    volumes:
      - orion_mongo_data:/data/db
      - orion_mongo_conf:/data/configdb
    command: --nojournal

  ############### CYGNUS ###############

  cygnus:
    image: fiware/cygnus-ngsi:${CYGNUS_VERSION}
    hostname: cygnus
    container_name: fiware-cygnus
    networks:
      - hostnet
    depends_on:
      - postgres-db
    expose:
      - "${CYGNUS_POSTGRESQL_SERVICE_PORT}" # 5055
      - "${CYGNUS_API_PORT}" # 5080
    ports:
      - "${CYGNUS_POSTGRESQL_SERVICE_PORT}:${CYGNUS_POSTGRESQL_SERVICE_PORT}"
      - "${CYGNUS_API_PORT}:${CYGNUS_API_PORT}"
    environment:
      - "CYGNUS_POSTGRESQL_SERVICE_PORT=${CYGNUS_POSTGRESQL_SERVICE_PORT}"      
      - "CYGNUS_POSTGRESQL_HOST=postgres-db" # Hostname of the PostgreSQL server used to persist historical contex
      - "CYGNUS_POSTGRESQL_PORT=${POSTGRES_DB_PORT}" # Port that the PostgreSQL server uses to listen to commands
      - "CYGNUS_POSTGRESQL_DATABASE=postgres"
      - "CYGNUS_POSTGRESQL_USER=postgres" # Username for the PostgreSQL database user
      - "CYGNUS_POSTGRESQL_PASS=password" # Password for the PostgreSQL database user
      - "CYGNUS_POSTGRESQL_ENABLE_CACHE=true" # Switch to enable caching within the PostgreSQL configuration
      - "CYGNUS_SERVICE_PORT=${CYGNUS_POSTGRESQL_SERVICE_PORT}" # Notification Port that Cygnus listens when subcr
      - "CYGNUS_API_PORT=${CYGNUS_API_PORT}" # Port that Cygnus listens on for operational reasons
      - "CYGNUS_LOG_LEVEL=DEBUG" # The logging level for Cygnus


  postgres-db:
    image: postgres
    hostname: postgres-db
    expose:
      - "${POSTGRES_DB_PORT}"
    ports:
      - "${POSTGRES_DB_PORT}:${POSTGRES_DB_PORT}"
    networks:
      - hostnet
    environment:
      - "POSTGRES_PASSWORD=password"
      - "POSTGRES_USER=postgres"
      - "POSTGRES_DB=postgres"
    volumes:
      - postgres-db:/var/lib/postgresql/data

volumes:
  iotmongo_data:
  iotmongo_conf:
  orion_mongo_data:
  orion_mongo_conf:
  postgres-db:

networks:
  hostnet:
  iotnet:
  ocbnet:

.env

# Orion
ORION_PORT=1026

# PostgreSQL
POSTGRES_DB_PORT=5432

# OPCUA IoT Agent
AGENT_SERVER_PORT=4001

# Cygnus
CYGNUS_VERSION=2.10.0
CYGNUS_API_PORT=5080
CYGNUS_MYSQL_SERVICE_PORT=5050
CYGNUS_MONGO_SERVICE_PORT=5051
CYGNUS_CKAN_SERVICE_PORT=5052
CYGNUS_HDFS_SERVICE_PORT=5053
CYGNUS_CARTO_SERVICE_PORT=5054
CYGNUS_POSTGRESQL_SERVICE_PORT=5055
CYGNUS_ORION_SERVICE_PORT=5056
CYGNUS_POSTGIS_SERVICE_PORT=5057
CYGNUS_ELASTICSEARCH_SERVICE_PORT=5058
CYGNUS_ARCGIS_SERVICE_PORT=5059

I can see the system is up and no error informed from docker docker ps -a result

However, when I use pgAdmin or docker exec to examine the postgres database there was nothing in it. \dt command of psql gave me Did not find any relation which means there was nothing logged into the database.

Please provide help to combine these two components of FIWARE (the IoT OPCUA agent and the Cygnus). It was also not clear for me if the Cygnus connector would create the database for us.

[EDIT] The component seems to be working: Simulation Server enter image description here

All services enter image description here

Cynus only infor me that 'Configuration has no change', when I used docker exec to get into the container, from Cygnus I was able to ping both orion, postgresql database containers enter image description here

enter image description here

In postgresql: I don't see the desired database or table enter image description here

My system from the Simulation Server -> OPCUA IoT Agent -> Orion was working well because from docker logs I was still able to get the updated value of Simulation Server: enter image description here enter image description here

Navurt
  • 45
  • 4

1 Answers1

3

You have a complex scenario here, composed of an end-to-end chain of 5 components:

  • Prosys OPC-UA Server Simulation
  • OPC-UA FIWARE IoT Agent
  • Orion Context Broker
  • FIWARE Cygnus Connector
  • PostgreSQL database

My recomendation here would be to check every step in the chain (looking in logs, etc.) to ensure everything is correct before of checking the next step.

fgalan
  • 11,732
  • 9
  • 46
  • 89
  • Will Cygnus create the table for my data ? Or I have to create the a database and table manually with the same name I set in the environment parameter of `docker-compose` `- "CYGNUS_POSTGRESQL_DATABASE=postgres"` ? – Navurt Sep 05 '21 at 05:43
  • I'd suggest to post that question as an independent question in StackOverflow – fgalan Sep 06 '21 at 06:23
  • The problem was solved. The errors related to incorrect service path, IP address of components and the curl command for my subscription was not correct. – Navurt Sep 15 '21 at 05:41
  • @Navurt i am doing the same project but I have doubts how you have solved the IP problem I have locally running an OPC server with Prosys OPC-UA Server Simulation which gives me my URN: opc.tcp://p:5001/UA/CarServer to which I have created a client in nodejs to query I retrieve the data and I have to replace p with localhost. My problem is when filling in the docker-compose I don't understand these two extra_hosts lines: - "iotcarsrv:192.168.50.167" - "HP:192.168.50.167" Could you explain me how to configure them correctly? as I have my opc in local the containers don't have access. – Manolait Oct 25 '21 at 15:48
  • @Manolait those two extra lines are for host-name resolving. Basically, it means if I replace `192.168.50.167` with either `iotcarsrv` or `HP`, docker-compose still know which IP I am referring to. – Navurt Oct 27 '21 at 04:46
  • @Manolait if you are in Linux, `cat /etc/hosts` lists the host-names in your system. – Navurt Oct 27 '21 at 04:51