我使用“mqttasgi”作为 Django justo 的库来监听和发布许多消息。然而,由于某种原因,几天后就无法再继续发布消息了。应该注意的是,我使用带有“mqttasgi”和 1 级 QO 的亚马逊登录(因为 AWS 不允许 2 级 QO)。
这是我的程序文件
mqttasgi -H $MQTT_URL -p $MQTT_PORT -v 2 -C $TLS_CERT -K $TLS_KEY -S $TLS_CA iot_stracontech.asgi:application```
这是我的消费者.py
from mqttasgi.consumers import MqttConsumer
from mqtt_handler.tasks import processmqttmessage
import json
class MyMqttConsumer(MqttConsumer):
async def connect(self):
await self.subscribe('tpx/things/+/uplink', 0)
await self.channel_layer.group_add("stracontech", self.channel_name)
async def receive(self, mqtt_message):
print('Received a message at topic:', mqtt_message['topic'])
print('With payload', mqtt_message['payload'])
print('And QOS:', mqtt_message['qos'])
dictresult = json.loads(mqtt_message['payload'])
jsonresult = json.dumps(dictresult)
processmqttmessage.delay(jsonresult, mqtt_message['topic'])
pass
async def publish_results(self, event):
data = event['result']
await self.publish("stracontech/procesed/" + event['result']['device_id'] + "/result",
json.dumps(data).encode('utf-8'), qos=1, retain=False)
async def disconnect(self):
await self.unsubscribe('tpx/things/+/uplink')
我想知道是否存在一种方法来了解为什么它停止发布消息,无论如何进行调试或查看日志?
Pd:@Santiago Ivulich 也许你可以帮我一下。
我也遇到了和你一样的问题。这个问题你解决了吗?