from aiogram import Bot, Dispatcher, executor, types
import asyncio
-import asyncio_mqtt
+import aiomqtt
from configparser import ConfigParser
from datetime import datetime, timedelta
import logging
async def mqtt_loop():
- sctx = ssl.SSLContext(ssl.PROTOCOL_TLS)
+ sctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
sctx.verify_mode = ssl.CERT_REQUIRED
sctx.load_cert_chain('/etc/burrow-mqtt/client.crt', '/etc/burrow-mqtt/client.key')
sctx.load_verify_locations(cafile='/etc/burrow-mqtt/ca.crt')
- async with asyncio_mqtt.Client(client_id='telegram', hostname="burrow-mqtt", port=8883, tls_context=sctx) as mqtt:
- async with mqtt.unfiltered_messages() as messages:
+ async with aiomqtt.Client(client_id='telegram', hostname="burrow-mqtt", port=8883, tls_context=sctx) as mqtt:
+ async with mqtt.messages() as messages:
await mqtt.subscribe("burrow/heating/#")
await mqtt.subscribe("burrow/temp/#")
async for msg in messages:
try:
logger.info("Starting MQTT")
await mqtt_loop()
- except asyncio_mqtt.MqttError as error:
+ except aiomqtt.MqttError as error:
logger.error(f"MQTT error: {error}")
await asyncio.sleep(10)