#!/bin/bash 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 "" echo "📡 Sende Test-Nachrichten..." echo "" echo "1️⃣ Temperature Sensor: sensors/temperature" publish "sensors/temperature" "22.5" echo "2️⃣ Humidity Sensor: sensors/humidity" publish "sensors/humidity" "65" echo "3️⃣ CPU Usage: system/cpu" publish "system/cpu" "45" echo "4️⃣ Device Power: devices/device1/power" publish "devices/device1/power" "ON" echo "5️⃣ Device Brightness: devices/device1/brightness" publish "devices/device1/brightness" "75" echo "================================================" echo "✅ Test abgeschlossen!" echo "================================================" echo "" 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 " $COMPOSE_CMD exec -T mosquitto mosquitto_sub -h localhost -t '#' -v -u $ADMIN_USER -P " echo "" echo "📡 Subscribe auf öffentliche Topics (ohne Auth):" echo " $COMPOSE_CMD exec -T mosquitto mosquitto_sub -h localhost -t 'public/#' -v" echo ""