초기 커밋
This commit is contained in:
26
app/communication/mqtt/client.py
Normal file
26
app/communication/mqtt/client.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi_mqtt import FastMQTT, MQTTConfig
|
||||
|
||||
from app.core.config import settings
|
||||
from app.communication.mqtt.topics import SUBSCRIBE_TOPICS
|
||||
|
||||
mqtt_config = MQTTConfig(
|
||||
host=settings.MQTT_HOST,
|
||||
port=settings.MQTT_PORT,
|
||||
username=settings.MQTT_USERNAME or None,
|
||||
password=settings.MQTT_PASSWORD or None,
|
||||
keepalive=60,
|
||||
)
|
||||
|
||||
mqtt = FastMQTT(config=mqtt_config)
|
||||
|
||||
|
||||
async def mqtt_startup() -> None:
|
||||
await mqtt.mqtt_startup()
|
||||
for topic in SUBSCRIBE_TOPICS:
|
||||
mqtt.client.subscribe(topic)
|
||||
|
||||
|
||||
async def mqtt_shutdown() -> None:
|
||||
await mqtt.mqtt_shutdown()
|
||||
Reference in New Issue
Block a user