MQTT Projekt III.: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(→Sensor) |
|||
| (4 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
=Grundaufbau= | =Grundaufbau= | ||
{{#drawio:mqtt-plan1}} | {{#drawio:mqtt-plan1}} | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
=Verschlüsselt mit Passwort= | =Verschlüsselt mit Passwort= | ||
Wir haben eine ca.crt der Auth und ein Certificate mqtt.dkbi.int.crt sowie ein PrivKey mqtt.dkbi.int.key | Wir haben eine ca.crt der Auth und ein Certificate mqtt.dkbi.int.crt sowie ein PrivKey mqtt.dkbi.int.key | ||
| Zeile 74: | Zeile 60: | ||
*cat /usr/local/control-switch/.env | *cat /usr/local/control-switch/.env | ||
MQTT_HOST=mqtt.lab.intern | MQTT_HOST=mqtt.lab.intern | ||
| − | MQTT_PORT= | + | MQTT_PORT=8883 |
MQTT_USER=xinux | MQTT_USER=xinux | ||
MQTT_PASS=123Start$ | MQTT_PASS=123Start$ | ||
| + | MQTT_TLS=true | ||
| + | MQTT_CA=/usr/local/control-switch/ca.crt | ||
*systemctl restart control-switch.service | *systemctl restart control-switch.service | ||
| − | *http:// | + | *http://sensor:3000/ |
;aktor | ;aktor | ||
*cat /usr/local/control/.env | *cat /usr/local/control/.env | ||
MQTT_HOST=mqtt.lab.intern | MQTT_HOST=mqtt.lab.intern | ||
| − | MQTT_PORT= | + | MQTT_PORT=8883 |
MQTT_USER=xinux | MQTT_USER=xinux | ||
MQTT_PASS=123Start$ | MQTT_PASS=123Start$ | ||
| − | *systemctl restart control | + | MQTT_TLS=true |
| − | *http:// | + | MQTT_CA=/usr/local/control/ca.crt |
| + | *systemctl restart control.service | ||
| + | *http://aktor:3000/ | ||
Aktuelle Version vom 24. November 2025, 10:27 Uhr
Grundaufbau
Verschlüsselt mit Passwort
Wir haben eine ca.crt der Auth und ein Certificate mqtt.dkbi.int.crt sowie ein PrivKey mqtt.dkbi.int.key
mqtt
- Benutzer anlegen
- user: xinux
- pass: 123Start$
- mosquitto_passwd -c /etc/mosquitto/passwd xinux
- Konfiguration kopieren
- cp /etc/mosquitto/conf.d/defaults.conf.verschlüsselt /etc/mosquitto/conf.d/defaults.conf
- Konfigurationsdatei
# Öffnet den MQTT-Broker auf Port 8883 und bindet ihn an alle verfügbaren Netzwerkinterfaces. listener 8883 0.0.0.0 # Erlaubt anonyme Verbindungen, d. h. ohne Benutzername und Passwort. allow_anonymous false # Aktiviert alle Log-Typen für eine detaillierte Protokollierung. log_type all # Zeigt Verbindungs- und Trennungsmeldungen von Clients im Log an. connection_messages true #Hier gegen wird authentifiziert. password_file /etc/mosquitto/passwd # Zertifikat certfile /etc/mosquitto/conf.d/mqtt.lab.intern.crt #PrivKey keyfile /etc/mosquitto/conf.d/mqtt.lab.intern.key #Zertifikat der CA cafile /etc/mosquitto/conf.d/ca.crt
- Restarten
- systemctl restart mosquitto.service
- Checken
- systemctl status mosquitto.service
Aktor
Der Aktor abonniert (subscribed) die Nachrichten und reagiert darauf.
- mosquitto_sub -h mqtt.lab.intern -p 8883 --cafile /usr/local/control/ca.crt -u xinux -P 123Start$ -t test
Sensor
Der Sensor sendet (published) die Nachrichten an das Topic.
- mosquitto_pub -h mqtt.lab.intern -p 8883 --cafile /usr/local/control-switch/ca.crt -u xinux -P 123Start$ -t test -m "Hello World"
- mosquitto_pub -h mqtt.lab.intern -p 8883 --cafile /usr/local/control-switch/ca.crt -u xinux -P 123Start$ -t test -m "2 Nachricht"
kali
Hier kann man auf Wireshark mitschneiden. Der Text ist Hexadezimal codiert.
- Schaut mal was man sieht.
Anpassen von node.js
- sensor
- cat /usr/local/control-switch/.env
MQTT_HOST=mqtt.lab.intern MQTT_PORT=8883 MQTT_USER=xinux MQTT_PASS=123Start$ MQTT_TLS=true MQTT_CA=/usr/local/control-switch/ca.crt
- systemctl restart control-switch.service
- http://sensor:3000/
- aktor
- cat /usr/local/control/.env
MQTT_HOST=mqtt.lab.intern MQTT_PORT=8883 MQTT_USER=xinux MQTT_PASS=123Start$ MQTT_TLS=true MQTT_CA=/usr/local/control/ca.crt
- systemctl restart control.service
- http://aktor:3000/
