# MQTT Testing This document describes how to use the `mqtt-test.js` script for monitoring and testing MQTT alerts. ## Environment Variables The script requires MQTT credentials to be set in `backend/.env`: ```bash # MQTT Configuration MQTT_BROKER=mqtt://mqtt.eluxnetworks.net:1883 MQTT_USER=your-mqtt-username MQTT_PASSWORD=your-mqtt-password ``` See `backend/.env.example` for the complete configuration template. ## Usage ### Monitor Mode (Listen for messages) ```bash # Monitor deployment 21 (default) node mqtt-test.js # Monitor specific deployment node mqtt-test.js 42 ``` ### Send Mode (Publish test alert) ```bash # Send test message to deployment 21 node mqtt-test.js send "Test alert message" # Send test message to specific deployment node mqtt-test.js send "Custom message text" ``` ## Message Format MQTT messages follow this JSON structure: ```json { "Command": "REPORT", "body": "Alert message text", "time": 1234567890 } ``` ## Security ⚠️ **IMPORTANT**: - Never commit MQTT credentials to the repository - Always use environment variables from `backend/.env` - The `.env` file is git-ignored for security ## See Also - [MQTT Notifications Architecture](docs/MQTT_NOTIFICATIONS_ARCHITECTURE.md) - [Backend .env Example](backend/.env.example)