问题
I have a problem with an Edge device that I have. Even though no devices are sending any data, the message quota is seeing a lot of traffic even though no messages are beeing sent. For example 14000 messages will be accumulated during 7 hrs or so.
Is there any way to debug the internal messages?
I've checked with docker logs edgeHub
and docker logs edgeAgent
but nothing out of the ordinary there.
回答1:
If it can help someone, I had this kind of problem yesterday, sending message from my edge device with a Python test app and never find it on the cloud. I missed the async behaviour of the send_message function.
You should have something like :
# 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)
Your Python app should use asyncio. If you forgot await
for send_message, your code will not produce errors but it just won't work.
If it works, you should see a bunch of azure sdk debug logs with a docker logs
of your Python app, like :
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
About this :
Even though no devices are sending any data, the message quota is seeing a lot of traffic even though no messages are beeing sent
Take care of the bad interpretation of Total number of messages used
. The real value you should look at is Telemetry messages sent
来源:https://stackoverflow.com/questions/48947709/azure-iot-edge-message-quota