Files
mosquitto-mqtt-broker/test-mqtt.sh
2025-11-03 22:44:47 +00:00

70 lines
2.4 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# MQTT Test Script - Sendet Test-Nachrichten an verschiedene Topics
# ===================================================================
echo "================================================"
echo "MQTT Server Test"
echo "================================================"
echo ""
# Prüfe ob Container läuft
if ! docker ps | grep -q mosquitto-mqtt; then
echo "❌ Fehler: Mosquitto Container läuft nicht!"
echo " Starte mit: docker-compose up -d"
exit 1
fi
echo "📡 Sende Test-Nachrichten..."
echo ""
# Test 1: Öffentliches Topic (OHNE Authentifizierung)
echo "1⃣ Öffentliches Topic (ohne Auth): public/message"
docker exec mosquitto-mqtt mosquitto_pub -h localhost -t "public/message" -m "Hallo von public!"
echo " ✅ Gesendet"
echo ""
# Test 2: Temperature Sensor (MIT Authentifizierung)
echo "2⃣ Temperature Sensor: sensors/temperature"
docker exec mosquitto-mqtt mosquitto_pub -h localhost -t "sensors/temperature" -m "22.5" -u admin -P admin123
echo " ✅ Gesendet: 22.5°C"
echo ""
# Test 3: Humidity Sensor
echo "3⃣ Humidity Sensor: sensors/humidity"
docker exec mosquitto-mqtt mosquitto_pub -h localhost -t "sensors/humidity" -m "65" -u admin -P admin123
echo " ✅ Gesendet: 65%"
echo ""
# Test 4: CPU Usage
echo "4⃣ CPU Usage: system/cpu"
docker exec mosquitto-mqtt mosquitto_pub -h localhost -t "system/cpu" -m "45" -u admin -P admin123
echo " ✅ Gesendet: 45%"
echo ""
# Test 5: Device Power Toggle
echo "5⃣ Device Power: devices/device1/power"
docker exec mosquitto-mqtt mosquitto_pub -h localhost -t "devices/device1/power" -m "ON" -u admin -P admin123
echo " ✅ Gesendet: ON"
echo ""
# Test 6: Device Brightness
echo "6⃣ Device Brightness: devices/device1/brightness"
docker exec mosquitto-mqtt mosquitto_pub -h localhost -t "devices/device1/brightness" -m "75" -u admin -P admin123
echo " ✅ Gesendet: 75%"
echo ""
echo "================================================"
echo "✅ Test abgeschlossen!"
echo "================================================"
echo ""
echo "🌐 Öffne das Dashboard: http://localhost:8080"
echo " Die Test-Daten sollten jetzt in den Widgets sichtbar sein."
echo ""
echo "📊 Subscribe auf alle Topics:"
echo " docker exec mosquitto-mqtt mosquitto_sub -h localhost -t '#' -v -u admin -P admin123"
echo ""
echo "📡 Subscribe auf öffentliche Topics (ohne Auth):"
echo " docker exec mosquitto-mqtt mosquitto_sub -h localhost -t 'public/#' -v"
echo ""