Mosquitto/MQTT Testing Cheatsheet

# Create a topic called test:
docker run --network home-assistant-01 -it eclipse-mosquitto:latest mosquitto_sub -h <mosquitto-hostname> -t test

# Create a topic called test whilst providing credentials:
docker run --network home-assistant-01 -it eclipse-mosquitto:latest mosquitto_sub -h <mosquitto-hostname> -t test -u admin -P "<mosquitto-password>"

# Send a message to the test topic:
docker run --network home-assistant-01 -it eclipse-mosquitto:latest mosquitto_pub -h <mosquitto-hostname> -t test -m "hello"

# Send a message to the test topic with credentials:
docker run --network home-assistant-01 -it eclipse-mosquitto:latest mosquitto_pub -h <mosquitto-hostname> -t test -m "hello" -u admin -P "<mosquitto-password>"

# Add a password for a user to the passwd file:
docker exec -it ha_mosquitto-01 mosquitto_passwd -c /mosquitto/config/mosquitto.passwd admin