С этим отредактированным docker составным файлом из https://github.com/FIWARE/tutorials.IoT-over-MQTT/blob/master/docker-compose.yml я смог успешно выполнить свои тесты. Команда развертывания:
docker stack deploy -c docker-compose.yml fiware
docker -compose.yml:
version: "3.5"
services:
orion:
image: fiware/orion
hostname: orion
container_name: fiware-orion
depends_on:
- mongo-db
networks:
- default
ports:
- "1026:1026"
command: -dbhost mongo-db -logLevel DEBUG
healthcheck:
test: curl --fail -s http://orion:1026/version || exit 1
iot-agent:
image: fiware/iotagent-ul
hostname: iot-agent
container_name: fiware-iot-agent
depends_on:
- mongo-db
- mosquitto
networks:
- default
expose:
- "4061"
- "7896"
ports:
- "4061:4061"
- "7896:7896"
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=4061
- IOTA_REGISTRY_TYPE=mongodb #Whether to hold IoT device info in memory or in a database
- IOTA_LOG_LEVEL=DEBUG # 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_HOST=mongo-db # The host name of MongoDB
- IOTA_MONGO_PORT=27017 # The port mongoDB is listening on
- IOTA_MONGO_DB=iotagentul # The name of the database used in mongoDB
- IOTA_MQTT_HOST=mosquitto # 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:4061
healthcheck:
test: curl --fail -s http://iot-agent:4061/iot/about || exit 1
mongo-db:
image: mongo:3.6
hostname: mongo-db
container_name: db-mongo
expose:
- "27017"
ports:
- "27017:27017" # localhost:27017
networks:
- default
command: --bind_ip_all --smallfiles
volumes:
- mongo-db:/data
mosquitto:
image: eclipse-mosquitto
hostname: mosquitto
container_name: mosquitto
expose:
- "1883"
- "9001"
ports:
- "1883:1883"
- "9001:9001"
volumes:
- ./mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf
networks:
- default
networks:
default:
ipam:
config:
- subnet: 172.18.1.0/24
volumes:
mongo-db: ~
Это успешно выполняемые шаги:
0) проверка работоспособности
curl http://localhost:4061/iot/about
1) создать сервисную группу
curl -iX POST \
'http://localhost:4061/iot/services' \
-H 'Content-Type: application/json' \
-H 'fiware-service: testservice' \
-H 'fiware-servicepath: /iot_ul' \
-d '{
"services": [
{
"apikey": "hallo",
"cbroker": "http://orion:1026",
"entity_type": "multiSensor",
"resource": "/iot/d"
}
]
}'
2) создать датчик
curl -X POST \
'http://localhost:4061/iot/devices' \
-H "Content-Type: application/json" \
-H "fiware-service: testservice" \
-H "fiware-servicepath: /iot_ul" \
-d '{
"devices": [
{
"device_id": "sensor01",
"entity_name": "LivingRoomSensor1",
"entity_type": "multiSensor",
"protocol": "PDI-IoTA-UltraLight",
"transport": "MQTT",
"attributes": [
{ "object_id": "t", "name": "Temperature", "type": "Integer" },
{ "object_id": "l", "name": "Luminosity", "type": "Integer" }
]
}
]
}'
3) обновить значения с помощью curl
curl --location --request POST 'http://localhost:7896/iot/d?i=sensor01&k=hallo' \
--header 'Content-Type: text/plain' \
--header 'fiware-service: testservice' \
--header 'fiware-servicepath: /iot_ul' \
--data-raw 't|1|l|3'
4) проверить, было ли обновлено значение
curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -H "Fiware-Service: testservice" -H "Fiware-ServicePath: /iot_ul" -d '{
"entities": [
{
"isPattern": "false",
"id": "LivingRoomSensor1",
"type": "multiSensor"
}
]
}' 'http://localhost:1026/v1/queryContext'
5) обновить значение через mqtt (работает также с другого компьютера - добавить параметры -h "hostaddress")
mosquitto_pub -m "t|2|l|5" -t "/hallo/sensor01/attrs"