Difference between revisions of "Automation - MQTT"
(7 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
{{!}}+ Proven on: | {{!}}+ Proven on: | ||
{{!}}- <!-- Debian --> | {{!}}- <!-- Debian --> | ||
{{!}} style="text-align: center; width: | {{!}} style="text-align: center; width: 60px;" {{!}} [[File:Logo Debian.png{{!}}60px{{!}}link=https://www.debian.org/{{!}}center{{!}}middle{{!}}frameless]] | ||
{{!}} 11 (bullseye) | {{!}} style="text-align: center; width: 40px;" {{!}} 11 (bullseye) | ||
{{!}} ([[#Debian / Version Caveat{{!}}caveat]]) | {{!}} ([[#Debian / Version Caveat{{!}}caveat]]) | ||
<br> | <br> | ||
Line 30: | Line 30: | ||
[https://mosquitto.org/ Mosquitto MQTT Broker] | [https://mosquitto.org/ Mosquitto MQTT Broker] | ||
{{{!}} class="wikitable" style="border-collapse: collapse; width: 33%; left;" | |||
{{!}}- style="text-align: center;" | |||
! style="width: 50%;" colspan="2" {{!}} As always... | |||
{{!}}- | |||
{{!}} {{!}} | |||
Start with: | Start with: | ||
{{!}} {{!}} | |||
*<code>sudo apt update</code> | *<code>sudo apt update</code> | ||
*<code>sudo apt upgrade</code> | *<code>sudo apt upgrade</code> | ||
{{!}}} | |||
= Installing Mosquitto = | = Installing Mosquitto = | ||
Line 42: | Line 46: | ||
Pretty simple, eh? | Pretty simple, eh? | ||
(Tho... If you want the latest & gratest and you're feeling adventurous... There's a [[Mosquitto from Source|CopyPasta page here]].) | |||
== Ensure that Mosquitto broker is running == | == Ensure that Mosquitto broker is running == | ||
Line 47: | Line 52: | ||
expected result is <u><code>Active: active (running)</code></u> | expected result is <u><code>Active: active (running)</code></u> | ||
== Note: | == Note: Ubuntu repositories have an outdated version == | ||
If you want to know which version you've installed... | If you want to know which version you've installed... | ||
*<code>mosquitto</code> | *<code>sudo mosquitto</code> | ||
(Ignore the error message "Error: Address already in use". It's already running as a service.) | |||
(Ignore the error message "Error: Address already in use". | |||
= Install client tools for testing etc = | = Install client tools for testing etc = | ||
Line 75: | Line 79: | ||
= Debian / Version Caveat = | = Debian / Version Caveat = | ||
(Ignore this if you built from source. It's apparently a repo thing...) | |||
During an install on a raw Debian system, I discovered that Mosquitto refused connection when I tried to access it with anything other than "localhost" as the hostname... | During an install on a raw Debian system, I discovered that Mosquitto refused connection when I tried to access it with anything other than "localhost" as the hostname... | ||
Latest revision as of 00:00, 3 March 2024
11 (bullseye) | (caveat)
| |
4 | (caveat)
| |
19.3 / 20.3 |
| |
20.04.3 |
| |
5.11 | (caveat)
|
As always... | |
---|---|
Start with: |
|
Installing Mosquitto
sudo apt-get install mosquitto
Pretty simple, eh?
(Tho... If you want the latest & gratest and you're feeling adventurous... There's a CopyPasta page here.)
Ensure that Mosquitto broker is running
sudo service mosquitto status
expected result is Active: active (running)
Note: Ubuntu repositories have an outdated version
If you want to know which version you've installed...
sudo mosquitto
(Ignore the error message "Error: Address already in use". It's already running as a service.)
Install client tools for testing etc
(Do this on any machine expected to manually use MQTT)
sudo apt install mosquitto-clients
Testing
In a terminal:
mosquitto_sub -h localhost -t "mqtt" -v
In another terminal:
mosquitto_pub -h localhost -t "mqtt" -m "Hello MQTT"
Now the message “mqtt Hello MQTT
” will be displayed in the first terminal where the topic “mqtt” is subscribed.
Subscribing to #
gives you a subscription to everything except for topics that start with a $
(these are normally control topics anyway).
Debian / Version Caveat
(Ignore this if you built from source. It's apparently a repo thing...)
During an install on a raw Debian system, I discovered that Mosquitto refused connection when I tried to access it with anything other than "localhost" as the hostname...
Apparently, mosquitto 2.0 binds only to the loopback interface unless specifically told otherwise.
& Debian installs v2.0 or higher...
But for now, It's a simple matter of editing the config file for Mosquitto.
sudo vi /etc/mosquitto/mosquitto.conf
& add in:
listener 1883 allow_anonymous true
Then,
sudo service mosquitto restart