feat: add basic app that consumes mqtt uplinks from chirpstack

This commit is contained in:
Alexis Fourmaux 2026-05-07 00:13:17 +02:00
parent 87ffc9cad7
commit 31a1c14831
10 changed files with 570 additions and 0 deletions

6
app/Dockerfile Normal file
View file

@ -0,0 +1,6 @@
FROM python:3.13-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY main.py .
CMD ["python", "main.py"]

30
app/main.py Normal file
View file

@ -0,0 +1,30 @@
import paho.mqtt.client as mqtt
import logging
import sys
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
datefmt="%Y-%m-%dT%H:%M:%S",
stream=sys.stdout, # Docker lit stdout par défaut
force=True
)
log = logging.getLogger(__name__)
def on_connect(client, userdata, flags, reason_code, properties):
log.info(f"Connected with result code {reason_code}")
client.subscribe("application/+/device/+/event/up")
def on_message(client, userdata, msg):
log.info(msg.topic+" "+str(msg.payload))
if __name__ == "__main__":
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
mqttc.on_connect = on_connect
mqttc.on_message = on_message
mqttc.connect("mosquitto", 1883, 60)
mqttc.loop_forever()

1
app/requirements.txt Normal file
View file

@ -0,0 +1 @@
paho-mqtt==v2.1.0