- Details
- Written by: Super Utilizador
- Category: Home Assistant
- Hits: 689
Install Mosquitto and its command line clients
sudo apt-get install mosquitto
sudo apt-get install mosquitto-clients
Check it’s running
sudo service mosquitto status
What you want to see is something like
chip@chip:/etc/apt/sources.list.d$ sudo service mosquitto status
● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
Loaded: loaded (/etc/init.d/mosquitto)
Active: active (running) since Sat 2017-01-14 23:56:42 UTC; 1min 21s ago
CGroup: /system.slice/mosquitto.service
└─17566 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Jan 14 23:56:41 chip mosquitto[17546]: Starting network daemon:: mosquitto.
Jan 14 23:56:42 chip systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker.
To start, stop and restart the broker in future, use the commands
sudo service mosquitto start
sudo service mosquitto stop
sudo service mosquitto restart
Test that it’s working
In your existing terminal, subscribe to the “testtopic” topic
mosquitto_sub -h localhost -t "testtopic" -v
Then open another terminal and send a message on that topic
mosquitto_pub -h localhost -t "testtopic" -m "Testing"
If all goes well then should see the message printed to the first terminal
chip@chip:~$ mosquitto_sub -h localhost -t "testtopic" -v
testtopic Testing
Success! You have a working MQTT broker running on the default port 1883.
Adding Websocket protocol support
Currently we only have MQTT protocol, so to enable Websockets on port 1884, we need to configure and restart Mosquitto. To do this, start by creating a configuration file in the appropriate location. I’ve called mine protocols.conf.
sudo vi /etc/mosquitto/conf.d/protocols.conf
Define the contents like so
listener 1883
protocol mqtt
listener 1884
protocol websockets
And again, restart with
sudo service mosquitto restart
Instalar Home Assistante em container Docker
docker run --init -d --name="home-assistant" -e "TZ=Europe/Lisbon" -v /home/homeassistant:/config --net=host homeassistant/raspberrypi4-64-homeassistant:stable