Code and Config files for a Raspberry Pi MQTT bridge
- Install docker
sudo apt install docker
- Pull the eclipse-mosquitto image
docker pull eclipse-mosquitto
- Create the necessary directories
mkdir -p /var/mosquitto/log
mkdir -p /var/mosquitto/data
chmod ugo+w /var/mosquitto
- Create the configuration and passwd files
wget https://raw.githubusercontent.com/DETImotica/Sensor_Gateway/master/configuration/var/mosquitto/mosquitto.conf -P /var/mosquitto
wget https://raw.githubusercontent.com/DETImotica/Sensor_Gateway/master/configuration/var/mosquitto/data/passwd -P /var/mosquitto/data
- Start a docker container in daemon mode
docker run -d -it -p 1883:1883 -p 9001:9001 -v /var/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf -v /var/mosquitto/data:/mosquitto/data -v /var/mosquitto/log:/mosquitto/log eclipse-mosquitto
- (Optional) Install mosquitto-clients package to be able to subscribe and publish to topics via the CLI
sudo apt install mosquitto-clients
Username: detimotic
Password: testpw
Using mosquitto-clients:
mosquitto_sub -h <address> -v -t "<topic>" -u detimotic -P testpw
Replace <topic> for the desired topic
Replace <address> for the IP address of the gateway or localhost if done on the gateway itself
Using mosquitto-clients:
mosquitto_pub -h <address> -t "<topic>" -u detimotic -P testpw -m "<message>"
Replace <topic> for the desired topic
Replace <address> for the IP address of the gateway or localhost if done on the gateway itself