I created and ran fiware-iot-agent in docker container along with fiware-orion context broker. The mongoDb Im using is a sharded cluster with 2 shards and auth-enabled. I verified that orion is connecting to the cluster. Below is the docker-compose.yml Im using.
version: "3.8"
services:
# Orion is the context broker
orion:
image: fiware/orion:${ORION_VERSION}
hostname: orion
container_name: fiware-orion-pms
networks:
- default
expose:
- "${ORION_PORT}"
ports:
- "${ORION_PORT}:${ORION_PORT}" # localhost:1026
command: -dbhost 192.168.2.5:27030 -dbuser $DB_USER -dbpwd $DB_PWD -dbAuthDb admin -db orion -logLevel DEBUG
healthcheck:
test: curl --fail -s http://orion:${ORION_PORT}/version || exit 1
interval: 5s
restart: always
labels:
maintainer: ino
description: fiware-orion
project: pms
version: v1.0.0
type: fiware
# IoT-Agent is configured for the UltraLight Protocol
#
# This deliberately fixed to v1.7.0
# see: https://github.com/telefonicaid/iotagent-ul/issues/320
#
# For v1.8 and v1.9 a dummy resource must be added when provisioning
#
iot-agent:
image: fiware/iotagent-json
hostname: iot-agent
container_name: fiware-iot-agent-pms
networks:
- default
expose:
- "${IOTA_NORTH_PORT}"
ports:
- "${IOTA_NORTH_PORT}:${IOTA_NORTH_PORT}" # localhost:4041
environment:
- IOTA_CB_HOST=orion # name of the context broker to update context
- IOTA_CB_PORT=1026 # port the context broker listens on to update context
- IOTA_NORTH_PORT=4041
- IOTA_REGISTRY_TYPE=mongodb #Whether to hold IoT device info in memory or in a database
- IOTA_LOG_LEVEL=FATAL # The log level of the IoT Agent
- IOTA_TIMESTAMP=true # Supply timestamp information with each measurement
- IOTA_CB_NGSI_VERSION=v2 # use NGSIv2 when sending updates for active attributes
- IOTA_AUTOCAST=true # Ensure Ultralight number values are read as numbers not strings
- IOTA_MONGO_USER=$DB_USER
- IOTA_MONGO_PASSWORD=$DB_PWD
- IOTA_MONGO_AUTH_SOURCE=admin
- IOTA_MONGO_HOST=192.168.2.5 # The host name of MongoDB
- IOTA_MONGO_PORT=27030 # The port mongoDB is listening on
- IOTA_MONGO_DB=iotagentul # The name of the database used in mongoDB
- IOTA_MQTT_HOST=192.168.2.10 # The host name of the MQTT Broker
- IOTA_MQTT_PORT=1883 # The port the MQTT Broker is listening on to receive topics
- IOTA_DEFAULT_RESOURCE= # Default is blank. I'm using MQTT so I don't need a resource
- IOTA_PROVIDER_URL=http://iot-agent:${IOTA_NORTH_PORT}
- IOTA_DEFAULT_TRANSPORT=MQTT
healthcheck:
interval: 5s
restart: always
labels:
maintainer: ino
description: fiware-orion-agent-json
project: pms
version: v1.0.0
type: fiware
networks:
default:
labels:
org.fiware: 'fiware-networks-pms'
ipam:
config:
- subnet: 172.50.1.0/24
My problem is when I add a new device to the fiware using endpoint http://localhost:4041/iot/devices
it creates a database named iotagentul and a collection named devices in it. The device I added is being saved to this collection. So far so good. But Im expecting another database to be created when I add a new device. In orion docs it says this:
Normally, Orion Context Broker uses just one database at MongoDB level (the one specified with the -db command line option, typically "orion"). However, when multitenant/multiservice is used the behaviour is different and the following databases are used (let be the value of the -db command line option): The database for the default tenant (typically, orion) The database - for service/tenant (e.g. if the tenant is named tenantA and default -db is used, then the database would be orion-tenantA. Per-service/tenant databases are created "on the fly" as the first request involving tenant data is processed by Orion. Finally, in the case of per-service/tenant databases, all collections and administrative procedures (backup, restore, etc.) are associated to each particular service/tenant database.
So according to this there should be other databases which will hold the entities for the devices. But they are not showing up. I tried with a mongo without authorization but its still same. How can I solve this problem? Any help is appreciated.
Edit: My request body is shown below:
{
"devices": [
{
"device_id": "PA_TALASLI1",
"entity_name": "PA_TALASLI1",
"entity_type": "power_analysis",
"transport": "HTTP",
"timezone": "Europe/Istanbul",
"attributes": [
{ "object_id": "Voltage_UL1_N", "name":"Voltage_UL1_N", "type":"Double"},
{ "object_id": "Voltage_UL2_N", "name":"Voltage_UL2_N", "type":"Double"},
{ "object_id": "Voltage_UL3_N", "name":"Voltage_UL3_N", "type":"Double"},
{ "object_id": "Current_L1", "name":"Current_L1", "type":"Double"},
{ "object_id": "Current_L2", "name":"Current_L2", "type":"Double"},
{ "object_id": "Current_L3", "name":"Current_L3", "type":"Double"},
{ "object_id": "Total_Active_Power", "name":"Total_Active_Power", "type":"Double"},
{ "object_id": "Total_Reactive_Power", "name":"Total_Reactive_Power", "type":"Double"},
{ "object_id": "Total_Power_Factor", "name":"Total_Power_Factor", "type":"Double"},
{ "object_id": "Total_Active_Energy_IN_T1", "name":"Total_Active_Energy_IN_T1", "type":"Double"},
{ "object_id": "Total_Active_Energy_IN_T2", "name":"Total_Active_Energy_IN_T2", "type":"Double"},
{ "object_id": "Total_Active_Energy_EX_T1", "name":"Total_Active_Energy_EX_T1", "type":"Double"},
{ "object_id": "Total_Active_Energy_EX_T2", "name":"Total_Active_Energy_EX_T2", "type":"Double"}
],
"lazy":[
{ "object_id": "Voltage_UL1_N", "name":"Voltage_UL1_N", "type":"Double"}
],
"static_attributes": [
{"name":"refStore", "type": "Relationship","value": "urn:ngsi-ld:pa_talasli1:001"}
]
}
]
}
I tried running the container with log level debug but I didnt see anything about the entity creation. If I add a lazy attribute to the body, it creates a table named registerations but there is no entities table. I specifically created an entity through /v2/entities/
but what I need is to have entities be created after I add a new device to /iot/devices
So I found why fiware-iot-agent wasnt able to create entities collection. When I add a new device, there has to be some data being published from that device via MQTT. The collection is being created after first data is being published. The reason I was expecting entities to be created right after adding a new device was because I was misled by my senior team-leader. She told me over and over if I add a new device I'd be able to create that collection.