ilianaboone
- Aug 11, 2023
- 38
- Joined
- Aug 11, 2023
- Messages
- 38
Mosquitto is a lightweight open-source MQTT (Message Queuing Telemetry Transport) message broker, widely used for efficient communication in IoT and distributed systems. Below is a structured guide to its deployment and usage
Core Features
[*]Persistence: Stores messages on disk for session recovery after resta
Installation on Debian 12
Core Features
- Lightweight: Optimized for resource-constrained devices (e.g., Raspberry Pi).
- Cross-Platform: Supports Linux, Windows, macOS.
- QoS Levels:
QoS 0 (At most once)
- QoS 1 (At least once)
- QoS 2 (Exactly once)
[*]Persistence: Stores messages on disk for session recovery after resta
Installation on Debian 12
- Install via APT:
bash
Code:sudo apt-get update && sudo apt-get install mosquitto - Verify Service Status:
bash
Code:sudo systemctl status mosqui
- Edit Config File:
bash
Code:sudo vim /etc/mosquitto/mosquitto.conf - Key Settings:
conf
# Default MQTT port (plaintext)
listener 1883
# WebSocket support
listener 9001
protocol websockets
# Allow anonymous connections (disable in production)
allow_anonymous true
# Log file path
log_dest file /var/log/mosquitto/mosquitto.log
- Restart Service:
bash
Code:sudo systemctl restart mosquitt
- Create Password File:
bash
Code:sudo mosquitto_passwd -c /etc/mosquitto/passwd your_username - Enforce Authentication:
conf
password_file /etc/mosquitto/passwd
allow_anonymous false
- Restart Service:
bash
Code:sudo systemctl restart mosquitt
- Install MQTTX:
Download from MQTTX官网.
- Connect to Broker:
Host: mqtt://your_server_ip:1883
- Username/Password: Set if authentication is enabled.
- Publish/Subscribe:
Publish Topic: sensor/data
- Subscribe Topic: device/comma
- Hardware: Ebyte NE2-D11 serial server (product page).
- Configuration:
Set Work Mode to MQTT.
- Enter broker IP/port and authentication details.
- Define topics for data publishing/command subscription.
- Testing:
Use XCOM (serial tool) to send data → Verify reception in MQTTX.
- Send commands via MQTTX → Confirm receipt in XCOM
- TLS/SSL Encryption:
Uncomment listener 8883 and configure certificates.
- Client ID Prefix:
conf
Code:clientid_prefix iot_device_ - Logging & Debugging:
Monitor logs with:
bash
Code:tail -f /var/log/mosquitto/mosquitto.
- Avoid Root Permissions: Use sudo for service management.
- Disable Anonymous Access in production.
- Buffer Day: Restart devices 1 day before returning to normal operation.