我正在尝试将JSON数据从一个模块发送到IoT Edge中的另一个模块。
我部署中的当前路由是:
FROM /messages/* INTO BrokeredEndpoint(\"/modules/target-module/inputs/input1\")从接收方接收消息所需的代码为:
async def input1_listener(module_client):
while True:
try:
input_message = await module_client.receive_message_on_input("input1") # blocking call
except Exception as e:
traceback.print_exc()
print("******************* Exception", flush=True)
print(e)
if not input_message is None and not input_message.data is None:
encoding = 'utf-8'
message_string = input_message.data.decode(encoding)
# data = json.loads(message_string)
print(message_string, flush=True)
else:
print('I have nothing')我部署后得到的响应是:
Jul 17 08:49:01 : DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Starting on_subscribed in pipeline thread
Jul 17 08:49:01 : DEBUG:azure.iot.device.common.pipeline.pipeline_stages_mqtt:MQTTTransportStage(MQTTSubscribeOperation): SUBACK received. completing op.
Jul 17 08:49:01 : DEBUG:azure.iot.device.common.pipeline.pipeline_ops_base:MQTTSubscribeOperation: completing without error
Jul 17 08:49:01 : DEBUG:azure.iot.device.common.pipeline.pipeline_stages_base:OpTimeoutStage(MQTTSubscribeOperation): Cancelling timer
Jul 17 08:49:01 : DEBUG:azure.iot.device.common.pipeline.pipeline_ops_base:EnableFeatureOperation: Worker op (MQTTSubscribeOperation) has been completed
Jul 17 08:49:01 : DEBUG:azure.iot.device.common.pipeline.pipeline_ops_base:EnableFeatureOperation: completing without error
Jul 17 08:49:01 : DEBUG:azure.iot.device.common.pipeline.pipeline_thread:Starting on_complete in callback thread
Jul 17 08:49:01 : DEBUG:azure.iot.device.common.async_adapter:Callback completed with result None
Jul 17 08:49:01 : INFO:azure.iot.device.iothub.aio.async_clients:Successfully enabled feature:input
Jul 17 08:49:01 : INFO:azure.iot.device.iothub.aio.async_clients:Waiting for input message on: input1...就像这样卡住了。所以最后一行告诉我模块没有接收到消息。但是,我知道代码没有错,因为它是Azure提供的示例代码。
它们也在同一个docker网络上:
[
{
"Name": "azure-iot-edge",
"Id": "18879945c844d0518c750b8d6abb8bcb656d59402332e957a21da0e774ab1aa6",
"Created": "2020-07-07T06:19:44.72084088+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"403bf3baf0868542a71247a4bf5945ac34ca7e10ce78a95b53ca6accee6cd3a8": {
"Name": "target-module",
"EndpointID": "41fee1bfeace1c1473ebae9f6cfe039f4f02d2da71ac64a80e2ae192206d2e67",
"MacAddress": "02:42:ac:12:00:05",
"IPv4Address": "172.18.0.5/16",
"IPv6Address": ""
},
"5f2a43021e84033f195db935634022066a179f9e95a8d32d78026f17c6711746": {
"Name": "source-module",
"EndpointID": "ed7518196b8c9d6d1a7079efe2c18cecd73bd04a09b575b27764b205bb0c805b",
"MacAddress": "02:42:ac:12:00:04",
"IPv4Address": "172.18.0.4/16",
"IPv6Address": ""
},
"71f4a9b2796a9fd45509b7535ec4ea7686ae069f190d1f49e97266ce549925f1": {
"Name": "edgeAgent",
"EndpointID": "a771cf3d90e7e7ef4351c03de661ca0e84731b2f196abb37ee592ecf1136db23",
"MacAddress": "02:42:ac:12:00:02",
"IPv4Address": "172.18.0.2/16",
"IPv6Address": ""
},
"830de1ac809f15ee0443610d82a092a0dcbde2dcb84cb49cd241ac6e29ef8e7e": {
"Name": "edgeHub",
"EndpointID": "31b2c932e1b9e45cc157cb8f17fe9373775dd61567960c1922b684e65eb3c1ed",
"MacAddress": "02:42:ac:12:00:03",
"IPv4Address": "172.18.0.3/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]在部署过程中,我也没有弄乱NetworkConfig。
我知道源模块正在发送数据,因为当我将路由更改为:
FROM /messages/* INTO $upstream我开始从Azure IoT资源管理器中的源模块接收遥测。
我在Raspberry Pi 4上运行这个程序,这是我的dockerfile.arm32v7
FROM arm32v7/python:3.7-slim-buster
WORKDIR /app
COPY requirements.txt ./
RUN pip install -r requirements.txt
COPY . .
CMD [ "python3", "-u", "./main.py" ]requirements.txt仅包含azure-iot-device~=2.1.2
这是iotedge check的输出--verbose
Configuration checks
--------------------
√ config.yaml is well-formed - OK
‼ config.yaml has well-formed connection string - Warning
Device not configured with manual provisioning, in this configuration 'iotedge check' is not able to discover the device's backing IoT Hub.
To run connectivity checks in this configuration please specify the backing IoT Hub name using --iothub-hostname switch if you have that information.
If no hostname is provided, all hub connectivity tests will be skipped.
√ container engine is installed and functional - OK
√ config.yaml has correct hostname - OK
√ config.yaml has correct URIs for daemon mgmt endpoint - OK
‼ latest security daemon - Warning
Installed IoT Edge daemon has version 1.0.9 but 1.0.9.3 is the latest stable version available.
Please see https://aka.ms/iotedge-update-runtime for update instructions.
‼ host time is close to real time - Warning
Could not query NTP server
caused by: could not receive NTP server response: Resource temporarily unavailable (os error 11)
√ container time is close to host time - OK
√ DNS server - OK
√ production readiness: certificates - OK
√ production readiness: container engine - OK
‼ production readiness: logs policy - Warning
Container engine is not configured to rotate module logs which may cause it run out of disk space.
Please see https://aka.ms/iotedge-prod-checklist-logs for best practices.
You can ignore this warning if you are setting log policy per module in the Edge deployment.
‼ production readiness: Edge Agent's storage directory is persisted on the host filesystem - Warning
The edgeAgent module is not configured to persist its /tmp/edgeAgent directory on the host filesystem.
Data might be lost if the module is deleted or updated.
Please see https://aka.ms/iotedge-storage-host for best practices.
‼ production readiness: Edge Hub's storage directory is persisted on the host filesystem - Warning
The edgeHub module is not configured to persist its /tmp/edgeHub directory on the host filesystem.
Data might be lost if the module is deleted or updated.
Please see https://aka.ms/iotedge-storage-host for best practices.
Connectivity checks
-------------------
√ host can connect to and perform TLS handshake with DPS endpoint - OK
‼ host can connect to and perform TLS handshake with IoT Hub AMQP port - Warning
skipping because of previous failures
‼ host can connect to and perform TLS handshake with IoT Hub HTTPS / WebSockets port - Warning
skipping because of previous failures
‼ host can connect to and perform TLS handshake with IoT Hub MQTT port - Warning
skipping because of previous failures
‼ container on the default network can connect to IoT Hub AMQP port - Warning
skipping because of previous failures
‼ container on the default network can connect to IoT Hub HTTPS / WebSockets port - Warning
skipping because of previous failures
‼ container on the default network can connect to IoT Hub MQTT port - Warning
skipping because of previous failures
‼ container on the IoT Edge module network can connect to IoT Hub AMQP port - Warning
skipping because of previous failures
‼ container on the IoT Edge module network can connect to IoT Hub HTTPS / WebSockets port - Warning
skipping because of previous failures
‼ container on the IoT Edge module network can connect to IoT Hub MQTT port - Warning
skipping because of previous failures
9 check(s) succeeded.
6 check(s) raised warnings.
9 check(s) were skipped due to errors from other checks.在这一点上,我已经用完了我认为可能导致这个问题的东西。
我遗漏了什么?
发布于 2020-07-25 04:08:11
问题出在你的路线上
将其更改为:
FROM /messages/* INTO BrokeredEndpoint("/modules/target-module/inputs/input1")已解决问题
https://stackoverflow.com/questions/62957212
复制相似问题