1

我的 Edge 设备有问题。即使没有设备发送任何数据,即使没有发送任何消息,消息配额也会看到大量流量。例如 14000 条消息将在 7 小时左右累积。

有没有办法调试内部消息?

我已经检查过 docker logs edgeHubdocker logs edgeAgent 但那里没有任何异常。

4

1 回答 1

0

如果它可以帮助某人,我昨天遇到了这种问题,从我的边缘设备使用 Python 测试应用程序发送消息,但从未在云上找到它。我错过了 send_message 函数的异步行为。

你应该有类似的东西:

# At the beginning of you code

# Create an IoT Hub client
client = IoTHubModuleClient.create_from_edge_environment()
# connect the client.
await client.connect()

# ... and in your main loop

# Send the message.
await client.send_message(message)

你的 Python 应用应该使用 asyncio。如果您忘记await了 send_message,您的代码不会产生错误,但它不会工作。

docker logs如果它有效,您应该会在您的 Python 应用程序中看到一堆 azure sdk 调试日志,例如:

2020-04-29 08:00:13,032 - async_clients - azure.iot.device.iothub.aio.async_clients - INFO - Sending message to Hub...
2020-04-29 08:00:13,032 - pipeline_thread - azure.iot.device.common.pipeline.pipeline_thread - DEBUG - Starting run_op in pipeline thread
2020-04-29 08:00:13,033 - pipeline_ops_base - azure.iot.device.common.pipeline.pipeline_ops_base - DEBUG - SendD2CMessageOperation: creating worker op of type MQTTPublishOperation
2020-04-29 08:00:13,033 - pipeline_stages_base - azure.iot.device.common.pipeline.pipeline_stages_base - INFO - AutoConnectStage(MQTTPublishOperation): Connected.  Sending down and adding callback to check result
2020-04-29 08:00:13,033 - pipeline_stages_mqtt - azure.iot.device.common.pipeline.pipeline_stages_mqtt - INFO - MQTTTransportStage(MQTTPublishOperation): publishing on devices/<DEVICE NAME>/modules/<MODULE_NAME>/messages/events/<PROPERTIES>
2020-04-29 08:00:13,033 - mqtt_transport - azure.iot.device.common.mqtt_transport - INFO - publishing on devices/<DEVICE NAME>/modules/<MODULE_NAME>/messages/events/<PROPERTIES>
2020-04-29 08:00:13,033 - client - paho - DEBUG - Sending PUBLISH (d0, q1, r0, m8), 'b'devices/<DEVICE NAME>/modules/<MODULE_NAME>/messages/events/<PROPERTIES>'', ... (65 bytes)
2020-04-29 08:00:13,033 - mqtt_transport - azure.iot.device.common.mqtt_transport - DEBUG - _mqtt_client.publish returned rc=0
2020-04-29 08:00:13,033 - mqtt_transport - azure.iot.device.common.mqtt_transport - DEBUG - Waiting for response on MID: 8
2020-04-29 08:00:13,046 - client - paho - DEBUG - Received PUBACK (Mid: 8)
2020-04-29 08:00:13,047 - mqtt_transport - azure.iot.device.common.mqtt_transport - INFO - payload published for 8
2020-04-29 08:00:13,047 - mqtt_transport - azure.iot.device.common.mqtt_transport - DEBUG - Response received for recognized MID: 8 - triggering callback
2020-04-29 08:00:13,048 - pipeline_thread - azure.iot.device.common.pipeline.pipeline_thread - DEBUG - Starting on_published in pipeline thread
2020-04-29 08:00:13,048 - pipeline_stages_mqtt - azure.iot.device.common.pipeline.pipeline_stages_mqtt - DEBUG - MQTTTransportStage(MQTTPublishOperation): PUBACK received. completing op.
2020-04-29 08:00:13,049 - pipeline_ops_base - azure.iot.device.common.pipeline.pipeline_ops_base - DEBUG - MQTTPublishOperation: completing without error
2020-04-29 08:00:13,049 - pipeline_ops_base - azure.iot.device.common.pipeline.pipeline_ops_base - DEBUG - SendD2CMessageOperation: Worker op (MQTTPublishOperation) has been completed
2020-04-29 08:00:13,050 - pipeline_ops_base - azure.iot.device.common.pipeline.pipeline_ops_base - DEBUG - SendD2CMessageOperation: completing without error
2020-04-29 08:00:13,050 - pipeline_thread - azure.iot.device.common.pipeline.pipeline_thread - DEBUG - Starting on_complete in callback thread
2020-04-29 08:00:13,051 - async_adapter - azure.iot.device.common.async_adapter - DEBUG - Callback completed with result None
2020-04-29 08:00:13,051 - async_clients - azure.iot.device.iothub.aio.async_clients - INFO - Successfully sent message to Hub

对这个 :

即使没有设备发送任何数据,消息配额也会看到大量流量,即使没有发送消息

照顾不好的解释Total number of messages used。你应该看的真正价值是Telemetry messages sent

于 2020-04-29T08:08:53.600 回答