Fixed findings
This commit is contained in:
90
test-mqtt.sh
Normal file → Executable file
90
test-mqtt.sh
Normal file → Executable file
@@ -1,69 +1,73 @@
|
||||
#!/bin/bash
|
||||
|
||||
# MQTT Test Script - Sendet Test-Nachrichten an verschiedene Topics
|
||||
# ===================================================================
|
||||
set -euo pipefail
|
||||
|
||||
COMPOSE_CMD=${COMPOSE_CMD:-"docker compose"}
|
||||
CONTAINER_NAME="mosquitto"
|
||||
|
||||
if [ ! -f .env ]; then
|
||||
echo "❌ Fehler: .env nicht gefunden. Bitte kopiere .env.example und setze die Passwörter."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -a
|
||||
source .env
|
||||
set +a
|
||||
|
||||
ADMIN_USER=${MQTT_ADMIN_USERNAME:-}
|
||||
ADMIN_PASS=${MQTT_ADMIN_PASSWORD:-}
|
||||
|
||||
if [ -z "$ADMIN_USER" ] || [ -z "$ADMIN_PASS" ]; then
|
||||
echo "❌ Fehler: MQTT_ADMIN_USERNAME und MQTT_ADMIN_PASSWORD müssen in .env gesetzt sein."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! docker ps --format '{{.Names}}' | grep -qx "$CONTAINER_NAME"; then
|
||||
echo "❌ Fehler: Mosquitto Container läuft nicht!"
|
||||
echo " Starte mit: docker compose up -d"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
publish() {
|
||||
local topic=$1
|
||||
local payload=$2
|
||||
echo " → $topic : $payload"
|
||||
$COMPOSE_CMD exec -T "$CONTAINER_NAME" mosquitto_pub -h localhost -t "$topic" -m "$payload" -u "$ADMIN_USER" -P "$ADMIN_PASS"
|
||||
}
|
||||
|
||||
echo "================================================"
|
||||
echo "MQTT Server Test"
|
||||
echo "================================================"
|
||||
echo ""
|
||||
|
||||
# Prüfe ob Container läuft
|
||||
if ! docker ps | grep -q mosquitto; 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 mosquitto_pub -h localhost -t "public/message" -m "Hallo von public!"
|
||||
echo " ✅ Gesendet"
|
||||
echo ""
|
||||
echo "1️⃣ Temperature Sensor: sensors/temperature"
|
||||
publish "sensors/temperature" "22.5"
|
||||
|
||||
# Test 2: Temperature Sensor (MIT Authentifizierung)
|
||||
echo "2️⃣ Temperature Sensor: sensors/temperature"
|
||||
docker exec mosquitto mosquitto_pub -h localhost -t "sensors/temperature" -m "22.5" -u admin -P admin123
|
||||
echo " ✅ Gesendet: 22.5°C"
|
||||
echo ""
|
||||
echo "2️⃣ Humidity Sensor: sensors/humidity"
|
||||
publish "sensors/humidity" "65"
|
||||
|
||||
# Test 3: Humidity Sensor
|
||||
echo "3️⃣ Humidity Sensor: sensors/humidity"
|
||||
docker exec mosquitto mosquitto_pub -h localhost -t "sensors/humidity" -m "65" -u admin -P admin123
|
||||
echo " ✅ Gesendet: 65%"
|
||||
echo ""
|
||||
echo "3️⃣ CPU Usage: system/cpu"
|
||||
publish "system/cpu" "45"
|
||||
|
||||
# Test 4: CPU Usage
|
||||
echo "4️⃣ CPU Usage: system/cpu"
|
||||
docker exec mosquitto mosquitto_pub -h localhost -t "system/cpu" -m "45" -u admin -P admin123
|
||||
echo " ✅ Gesendet: 45%"
|
||||
echo ""
|
||||
echo "4️⃣ Device Power: devices/device1/power"
|
||||
publish "devices/device1/power" "ON"
|
||||
|
||||
# Test 5: Device Power Toggle
|
||||
echo "5️⃣ Device Power: devices/device1/power"
|
||||
docker exec mosquitto 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 mosquitto_pub -h localhost -t "devices/device1/brightness" -m "75" -u admin -P admin123
|
||||
echo " ✅ Gesendet: 75%"
|
||||
echo ""
|
||||
echo "5️⃣ Device Brightness: devices/device1/brightness"
|
||||
publish "devices/device1/brightness" "75"
|
||||
|
||||
echo "================================================"
|
||||
echo "✅ Test abgeschlossen!"
|
||||
echo "================================================"
|
||||
echo ""
|
||||
echo "🌐 Öffne das Dashboard: http://localhost:8080"
|
||||
echo "🌐 Öffne das Dashboard: http://localhost:5000"
|
||||
echo " Die Test-Daten sollten jetzt in den Widgets sichtbar sein."
|
||||
echo ""
|
||||
echo "📊 Subscribe auf alle Topics:"
|
||||
echo " docker exec mosquitto mosquitto_sub -h localhost -t '#' -v -u admin -P admin123"
|
||||
echo " $COMPOSE_CMD exec -T mosquitto mosquitto_sub -h localhost -t '#' -v -u $ADMIN_USER -P <ADMIN_PASSWORD>"
|
||||
echo ""
|
||||
echo "📡 Subscribe auf öffentliche Topics (ohne Auth):"
|
||||
echo " docker exec mosquitto mosquitto_sub -h localhost -t 'public/#' -v"
|
||||
echo " $COMPOSE_CMD exec -T mosquitto mosquitto_sub -h localhost -t 'public/#' -v"
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user