π‘ Mosquitto MQTT
Mosquitto is een lichtgewicht MQTT message broker voor IoT communicatie.
Algemene Info
| Item | Waarde |
|---|---|
| Type | LXC Container op Proxmox |
| IP Adres | 192.168.20.11 |
| VLAN | 20 (IoT) |
| Poort | 1883 |
| Status | π§ Op te zetten |
Wat is MQTT?
MQTT (Message Queuing Telemetry Transport) is een lightweight publish-subscribe protocol, ideaal voor IoT:
βββββββββββββββ publish βββββββββββββββ subscribe βββββββββββββββ
β Sensor β βββββββββββββββΊ β Mosquitto β βββββββββββββββββΊβ Home β
β (temp) β topic: β Broker β topic: β Assistant β
β β home/temp β β home/temp β β
βββββββββββββββ βββββββββββββββ βββββββββββββββ
Functies
- β Publish/Subscribe - Asynchroon berichtenverkeer
- β Topics - HiΓ«rarchische berichtorganisatie
- β QoS Levels - Betrouwbaarheid opties
- β Retained Messages - Laatst bekende waarde
- β Will Messages - Offline detectie
- β Authentication - Gebruikersnaam/wachtwoord
Configuratie
/etc/mosquitto/conf.d/default.conf
# Luister op alle interfaces
listener 1883
# Authenticatie vereist
allow_anonymous false
password_file /etc/mosquitto/passwd
# Logging
log_dest file /var/log/mosquitto/mosquitto.log
log_type all
# Persistence
persistence true
persistence_location /var/lib/mosquitto/
Gebruiker Aanmaken
# Eerste gebruiker (maakt bestand aan)
mosquitto_passwd -c /etc/mosquitto/passwd mqtt_user
# Extra gebruiker toevoegen
mosquitto_passwd /etc/mosquitto/passwd andere_user
# Service herstarten
systemctl restart mosquitto
Clients
Home Assistant
# configuration.yaml
mqtt:
broker: 192.168.20.11
port: 1883
username: mqtt_user
password: !secret mqtt_password
Frigate
Zigbee2MQTT
# configuration.yaml
mqtt:
server: mqtt://192.168.20.11:1883
user: mqtt_user
password: mqtt_password
Topics Structuur
Aanbevolen HiΓ«rarchie
home/
βββ livingroom/
β βββ temperature
β βββ humidity
β βββ light/
β βββ state
β βββ brightness
βββ kitchen/
β βββ ...
βββ frigate/
βββ events
βββ available
Zigbee2MQTT Topics
zigbee2mqtt/
βββ bridge/
β βββ state
β βββ devices
β βββ log
βββ [device_name]/
βββ state
βββ brightness
βββ ...
Testing
Publish Bericht
# Vanuit container of client met mosquitto-clients
mosquitto_pub -h 192.168.20.11 -u mqtt_user -P wachtwoord \
-t "home/test" -m "Hello World"
Subscribe op Topic
Alle Berichten Zien
Firewall Regels
MQTT moet bereikbaar zijn voor:
| Client | IP | Poort | Regel |
|---|---|---|---|
| Home Assistant | 192.168.20.10 | 1883 | Zelfde VLAN |
| Frigate | 192.168.1.15 | 1883 | Allow Management to IoT |
| Zigbee2MQTT | 192.168.20.12 | 1883 | Zelfde VLAN |
| Z-Wave JS | 192.168.20.13 | 1883 | Zelfde VLAN |
Monitoring
Status Checken
Logs Bekijken
Actieve Connecties
Troubleshooting
Connection refused
Symptomen
- Client kan niet verbinden
- "Connection refused" error
Checklist:
-
Service draait:
-
Luistert op juiste poort:
-
Credentials correct:
-
Firewall:
Authentication error
Symptomen
- "Not authorized"
- "Bad username or password"
Oplossing:
-
Check password file:
-
Regenereer wachtwoord:
Berichten komen niet aan
Debug stappen:
-
Subscribe op alle topics:
-
Check of publisher werkt:
-
Check topic spelling (case-sensitive!)
Hoog geheugengebruik
Oorzaken: - Te veel retained messages - Grote payloads
Oplossing:
# Clear retained messages
mosquitto_pub -h localhost -t "topic" -n -r
# Of herstart met schone database
systemctl stop mosquitto
rm /var/lib/mosquitto/mosquitto.db
systemctl start mosquitto
LXC Container Setup
Container Aanmaken
# Op Proxmox
pct create 102 local:vztmpl/debian-12-standard_12.0-1_amd64.tar.zst \
--hostname mosquitto \
--memory 512 \
--cores 1 \
--net0 name=eth0,bridge=vmbr0,tag=20,ip=192.168.20.11/24,gw=192.168.20.1 \
--storage local-lvm \
--rootfs local-lvm:4
Installatie
pct start 102
pct enter 102
apt update && apt install -y mosquitto mosquitto-clients
systemctl enable mosquitto
# Configureren
nano /etc/mosquitto/conf.d/default.conf
mosquitto_passwd -c /etc/mosquitto/passwd mqtt_user
systemctl restart mosquitto