Difference between revisions of "Automation - MQTT"

From Da Nerd Mage Wiki
Jump to navigation Jump to search
Line 1: Line 1:
{{{!}} class="wikitable" style="float: right; width: 322px;" border="2"
{{{!}} class="wikitable" style="float: right; width: 322px;" border="2"
{{!}}+ Proven on:
{{!}}+ Proven on:
{{!}}-  
{{!}}- <!-- Debian -->
{{!}} style="text-align: center; width: 72.1125px;" {{!}} [[File:Logo Debian.png{{!}}60px{{!}}link=https://www.debian.org/{{!}}center{{!}}middle{{!}}frameless]]
{{!}} 11 (bullseye)
{{!}} ([[#Debian / Version Caveat{{!}}caveat]])
<br>
{{!}}- <!-- LMDE -->
{{!}} style="text-align: center; width: 65.675px;" {{!}} [[File:Logo LMDE.png{{!}}60px{{!}}link=https://linuxmint.com/edition.php?id=279{{!}}center{{!}}middle{{!}}frameless]]
{{!}} 4
{{!}} ([[#Debian / Version Caveat{{!}}caveat]])
<br>
{{!}}- <!-- Linux Mint -->
{{!}} style="text-align: center; width: 67.5125px;" {{!}} [[File:Logo Mint.png{{!}}60px{{!}}link=https://linuxmint.com{{!}}center{{!}}middle{{!}}frameless]]
{{!}} style="text-align: center; width: 67.5125px;" {{!}} [[File:Logo Mint.png{{!}}60px{{!}}link=https://linuxmint.com{{!}}center{{!}}middle{{!}}frameless]]
{{!}} style="text-align: center; width: 65.675px;" {{!}} [[File:Logo LMDE.png{{!}}60px{{!}}link=https://linuxmint.com/edition.php?id=279{{!}}center{{!}}middle{{!}}frameless]]
{{!}} 19.3 / 20.3
{{!}} style="text-align: center; width: 72.1125px;" {{!}} [[File:Logo Debian.png{{!}}60px{{!}}link=https://www.debian.org/{{!}}center{{!}}middle{{!}}frameless]]
{{!}}
<br>
{{!}}- <!-- Ubuntu -->
{{!}} style="text-align: center; width: 65.7px;" {{!}} [[File:Logo Ubuntu.png{{!}}60px{{!}}link=https://ubuntu.com/{{!}}center{{!}}middle{{!}}frameless]]
{{!}} style="text-align: center; width: 65.7px;" {{!}} [[File:Logo Ubuntu.png{{!}}60px{{!}}link=https://ubuntu.com/{{!}}center{{!}}middle{{!}}frameless]]
{{!}} 20.04.3
{{!}}
<br>
{{!}}- <!-- Sparky Linux -->
{{!}} style="text-align: center; width: 65.7px;" {{!}} [[File:Logo Sparky.png{{!}}60px{{!}}link=https://sparkylinux.org/{{!}}center{{!}}middle{{!}}frameless]]
{{!}} style="text-align: center; width: 65.7px;" {{!}} [[File:Logo Sparky.png{{!}}60px{{!}}link=https://sparkylinux.org/{{!}}center{{!}}middle{{!}}frameless]]
{{!}}-
{{!}} 5.11
{{!}} style="width: 67.5125px;" {{!}} 19.3 / 20.3
{{!}} ([[#Debian / Version Caveat{{!}}caveat]])
{{!}} style="width: 65.675px;" {{!}} 4
<br>
{{!}} style="width: 72.1125px;" {{!}} 11 (bullseye)
{{!}} style="width: 65.7px;" {{!}} 20.04.3
{{!}} style="width: 65.7px;" {{!}} 5.11
{{!}}-
{{!}} style="width: 67.5125px;" {{!}}
{{!}} style="width: 65.675px;" {{!}}
{{!}} style="width: 72.1125px;" {{!}} ([[#Debian / Version Caveat{{!}}caveat]])
{{!}} style="width: 65.7px;" {{!}}
{{!}} style="width: 65.7px;" {{!}}
{{!}}}
{{!}}}



Revision as of 20:55, 14 January 2022

Proven on:
Logo Debian.png
11 (bullseye) (caveat)


Logo LMDE.png
4 (caveat)


Logo Mint.png
19.3 / 20.3


Logo Ubuntu.png
20.04.3


Logo Sparky.png
5.11 (caveat)


Mosquitto MQTT Broker

As always...

Start with:

  • sudo apt update
  • sudo apt upgrade

Installing Mosquitto

  • sudo apt-get install mosquitto

Pretty simple, eh?

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...

  • 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

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