iotagent-json 使用 MQTT 在发送命令时不发布任何内容
iotagent-json using MQTT not publishing anything when command is sent
在我的服务器上,我有 Orion 上下文代理和一个在 docker 容器中工作的 IoT 代理。我可以使用 MQTT 协议注册和更新我的实体,没问题。但我希望能够使用 IoT 代理中的命令系统向我的设备发送命令。在 Documentation 中,它表示在注册命令时,物联网代理会在 /apiKey/EntityID/cmd 中发布一些内容。但是,当我这样做时,我没有发布任何内容。实体已正确更新(我可以看到命令状态变为 PENDING,并且积极的日志告诉我一切正常。但是我的 MQTT 主题上没有发布任何内容。
这是我的 docker-compose.yml 文件:
version: '3.3'
services:
iot-mongo:
image: mongo:3.2
ports:
- "27017:27017"
volumes:
- ./data/mongo:/data/db
iot-agent:
image: fiware/iotagent-json
ports:
- "4041:4041"
links:
- iot-mongo
- orion
- mosquitto
volumes:
- ./config.js:/opt/iotajson/config.js
mosquitto:
image: toke/mosquitto
ports:
- "1883:1883"
- "9001:9001"
orion:
image: fiware/orion:1.9.0
links:
- iot-mongo
ports:
- "1026:1026"
command: -dbhost iot-mongo
我这样创建我的实体:
curl -X POST http://127.23.64.163:4041/iot/devices \
-i \
-H "Content-Type: application/json" \
-H "Fiware-Service: proj" \
-H "Fiware-ServicePath: /proj" \
-d ' { "devices": [
{ "device_id": "iotsensor10", "entity_name": "iotsensor10", "entity_type": "sensorping", "timezone": "America/Santiago",
"commands": [
{ "name": "ping", "type": "command", "value": ""}
],
"attributes": [
{ "object_id": "title", "name": "title", "type": "Text" },
{ "object_id": "percentage", "name": "percentage", "type": "Text" }
],
"static_attributes": [ { "name": "att_name", "type": "string", "value": "value" } ] }
]
}'
我可以使用以下命令更新我的实体:
mosquitto_pub -h 127.23.64.163 -t /1234/iotsensor10/attrs -m '{"title": "mqtttitle", "percentage": "31.5"}'
并创建如下命令:
curl --request POST http://127.23.64.163:1026/v1/updateContext \
-i \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Fiware-Service: proj" \
-H "Fiware-ServicePath: /proj" \
-d ' {"updateAction": "UPDATE", "contextElements": [
{"id": "iotsensor10", "type": "sensorping", "isPattern": "false",
"attributes": [
{"name": "ping", "type": "command", "value": "ALIVE" }
]
}
]}'
我订阅了:
mosquitto_sub -h 127.23.64.163 -t /# -v
但是当我创建一个命令时我没有看到任何东西。
但是,如果我 运行 :
mosquitto_pub -h 127.23.64.163 -t /1234/iotsensor10/cmdexe -m '{"ping": "kebab"}'
我可以验证命令并在我的实体上查看结果。我遇到的唯一问题是,当我希望在 /apikey/sensor10/cmd 上发布某些内容时,创建命令时没有发布任何内容。知道为什么以及如何解决它吗?
更新 1
我尝试对图像进行相同的操作 fiware/iotagent-ul 但得到的结果完全相同。未发布任何内容。
问题出在我如何在我的 IoT 代理上创建我的设备。我必须指定传输字段,即 MQTT。所以为了让它工作,我必须创建一个这样的设备:
curl -X POST -H "Fiware-Service: MyService" -H "Fiware-ServicePath: /MyService" -H "Content-Type: application/json" -d '{
"devices": [
{
"device_id": "iotsensor6",
"entity_name": "iotsensor6",
"entity_type": "sensorping",
"transport": "MQTT",
"commands": [ { "name": "ping", "type": "command", "value": ""} ],
"attributes": [
{ "object_id": "title", "name": "title", "type": "text" },
{ "object_id": "percentage", "name": "percentage", "type": "text" }
]
}
]
}' 'http://127.23.64.163:4041/iot/devices'
现在,当我创建命令时,我在主题 /1234/iotsensor6/cmd
中创建了条目
在我的服务器上,我有 Orion 上下文代理和一个在 docker 容器中工作的 IoT 代理。我可以使用 MQTT 协议注册和更新我的实体,没问题。但我希望能够使用 IoT 代理中的命令系统向我的设备发送命令。在 Documentation 中,它表示在注册命令时,物联网代理会在 /apiKey/EntityID/cmd 中发布一些内容。但是,当我这样做时,我没有发布任何内容。实体已正确更新(我可以看到命令状态变为 PENDING,并且积极的日志告诉我一切正常。但是我的 MQTT 主题上没有发布任何内容。
这是我的 docker-compose.yml 文件:
version: '3.3'
services:
iot-mongo:
image: mongo:3.2
ports:
- "27017:27017"
volumes:
- ./data/mongo:/data/db
iot-agent:
image: fiware/iotagent-json
ports:
- "4041:4041"
links:
- iot-mongo
- orion
- mosquitto
volumes:
- ./config.js:/opt/iotajson/config.js
mosquitto:
image: toke/mosquitto
ports:
- "1883:1883"
- "9001:9001"
orion:
image: fiware/orion:1.9.0
links:
- iot-mongo
ports:
- "1026:1026"
command: -dbhost iot-mongo
我这样创建我的实体:
curl -X POST http://127.23.64.163:4041/iot/devices \
-i \
-H "Content-Type: application/json" \
-H "Fiware-Service: proj" \
-H "Fiware-ServicePath: /proj" \
-d ' { "devices": [
{ "device_id": "iotsensor10", "entity_name": "iotsensor10", "entity_type": "sensorping", "timezone": "America/Santiago",
"commands": [
{ "name": "ping", "type": "command", "value": ""}
],
"attributes": [
{ "object_id": "title", "name": "title", "type": "Text" },
{ "object_id": "percentage", "name": "percentage", "type": "Text" }
],
"static_attributes": [ { "name": "att_name", "type": "string", "value": "value" } ] }
]
}'
我可以使用以下命令更新我的实体:
mosquitto_pub -h 127.23.64.163 -t /1234/iotsensor10/attrs -m '{"title": "mqtttitle", "percentage": "31.5"}'
并创建如下命令:
curl --request POST http://127.23.64.163:1026/v1/updateContext \
-i \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Fiware-Service: proj" \
-H "Fiware-ServicePath: /proj" \
-d ' {"updateAction": "UPDATE", "contextElements": [
{"id": "iotsensor10", "type": "sensorping", "isPattern": "false",
"attributes": [
{"name": "ping", "type": "command", "value": "ALIVE" }
]
}
]}'
我订阅了:
mosquitto_sub -h 127.23.64.163 -t /# -v
但是当我创建一个命令时我没有看到任何东西。
但是,如果我 运行 :
mosquitto_pub -h 127.23.64.163 -t /1234/iotsensor10/cmdexe -m '{"ping": "kebab"}'
我可以验证命令并在我的实体上查看结果。我遇到的唯一问题是,当我希望在 /apikey/sensor10/cmd 上发布某些内容时,创建命令时没有发布任何内容。知道为什么以及如何解决它吗?
更新 1
我尝试对图像进行相同的操作 fiware/iotagent-ul 但得到的结果完全相同。未发布任何内容。
问题出在我如何在我的 IoT 代理上创建我的设备。我必须指定传输字段,即 MQTT。所以为了让它工作,我必须创建一个这样的设备:
curl -X POST -H "Fiware-Service: MyService" -H "Fiware-ServicePath: /MyService" -H "Content-Type: application/json" -d '{
"devices": [
{
"device_id": "iotsensor6",
"entity_name": "iotsensor6",
"entity_type": "sensorping",
"transport": "MQTT",
"commands": [ { "name": "ping", "type": "command", "value": ""} ],
"attributes": [
{ "object_id": "title", "name": "title", "type": "text" },
{ "object_id": "percentage", "name": "percentage", "type": "text" }
]
}
]
}' 'http://127.23.64.163:4041/iot/devices'
现在,当我创建命令时,我在主题 /1234/iotsensor6/cmd
中创建了条目