<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>MQTT on Much Ado About IT</title><link>https://it.knightnet.org.uk/tags/mqtt/</link><description>
Recent content about MQTT from Much Ado About IT |
Ramblings and rantings from IT Architect &amp; Designer, Julian Knight</description><generator>Hugo | gohugo.io | Theme twenty-sixteen</generator><language>en-gb</language><copyright>This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</copyright><lastBuildDate>Mon, 24 Apr 2023 21:27:28 +0000</lastBuildDate><atom:link href="https://it.knightnet.org.uk/tags/mqtt/feed.xml" rel="self" type="application/rss+xml"/><item><title>Node-RED communications protocols</title><link>https://it.knightnet.org.uk/kb/nr-qa/nr-comms/</link><guid isPermaLink="true">https://it.knightnet.org.uk/kb/nr-qa/nr-comms/</guid><pubDate>Thu, 20 Aug 2020 17:53:20 +0000</pubDate><guid>https://it.knightnet.org.uk/kb/nr-qa/nr-comms/</guid><description><div>Node-RED has an excellent choice of communications protocols available to it. This article looks at the main options and their strengths and weaknesses. It also gives suggestions as to when you may wish to use them.</div><div>&lt;p>Node-RED is renown for its MQTT support since that is where it started - as an IBM demonstrator for their experteese on IoT.&lt;/p>
&lt;p>However, this is only one of many ways to send/receive data between Node-RED and other systems or services. Each of tese protocols has its own advantages and disadvantages.&lt;/p>
&lt;h2 id="the-protocols">The protocols&lt;/h2>
&lt;p>In rough order of descending order of ease of use (very rough!):&lt;/p>
&lt;ul>
&lt;li>MQTT&lt;/li>
&lt;li>Websocket&lt;/li>
&lt;li>HTTP&lt;/li>
&lt;li>TCP&lt;/li>
&lt;li>UDP&lt;/li>
&lt;li>UNIX Pipes&lt;/li>
&lt;/ul>
&lt;h3 id="mqtt">MQTT&lt;/h3>
&lt;p>This is likely to be the easiest to use even though it requires an extra service to be running, a &amp;ldquo;Broker&amp;rdquo;.&lt;/p>
&lt;p>There is even a custom node available that lets you run a broker from within Node-RED itself. However, I don&amp;rsquo;t recommend doing that because it adds significant overheads that are easily avoided. The most commonly used broker is &amp;ldquo;Mosquito&amp;rdquo; which has low resource overheads, is fast, secure and capable. It is easily installed and configured.&lt;/p>
&lt;p>While MQTT data payloads are just strings, Node-RED lets you send and receive more complex data structures (JSON).&lt;/p>
&lt;p>The things that put MQTT at the top of the list are:&lt;/p>
&lt;ul>
&lt;li>The ability to easily handle more complex data&lt;/li>
&lt;li>The availability of MQTT libraries and clients for many platforms&lt;/li>
&lt;/ul>
&lt;h3 id="websocket">Websocket&lt;/h3>
&lt;h3 id="http">HTTP&lt;/h3>
&lt;h3 id="tcp">TCP&lt;/h3>
&lt;h3 id="udp">UDP&lt;/h3>
&lt;h3 id="unix-pipes">UNIX Pipes&lt;/h3></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/development">Development</category><category domain="https://it.knightnet.org.uk/tags/node-red">Node-RED</category><category domain="https://it.knightnet.org.uk/tags/communications">Communications</category><category domain="https://it.knightnet.org.uk/tags/protocols">Protocols</category><category domain="https://it.knightnet.org.uk/tags/mqtt">MQTT</category><category domain="https://it.knightnet.org.uk/tags/websockets">Websockets</category><category domain="https://it.knightnet.org.uk/tags/tcp">TCP</category><category domain="https://it.knightnet.org.uk/tags/udp">UDP</category></item><item><title>Mosquitto MQTT Server on a Raspberry Pi</title><link>https://it.knightnet.org.uk/2015/11/mosquitto-mqtt-server-on-a-raspberry-pi.html</link><guid isPermaLink="true">https://it.knightnet.org.uk/2015/11/mosquitto-mqtt-server-on-a-raspberry-pi.html</guid><pubDate>Sun, 29 Nov 2015 23:10:53 +0000</pubDate><guid>https://it.knightnet.org.uk/2015/11/mosquitto-mqtt-server-on-a-raspberry-pi.html</guid><description><div>To access an MQTT broker direct from the browser, you need websockets support. On a Raspberry Pi, this used to require a custom build from source. That is no longer required. You can now install direct from the mosquitto.org repository and add a simple config change. This article explains the details.</div><div>&lt;p>&lt;!-- raw HTML omitted -->MQTT&lt;!-- raw HTML omitted --> is a messaging protocol for the “Internet of Things” (IoT). It allows devices to communicate easily with minimal overheads. The Raspberry Pi of course makes an excellent low cost platform for managing IoT. Not only is it cheap to buy, it is also cheap to keep running.&lt;/p>
&lt;p>To use MQTT, you need a “broker” which is simply a service running in the background. &lt;!-- raw HTML omitted -->Mosquitto&lt;!-- raw HTML omitted --> is one of the more popular brokers, partly because it is pretty small and therefore ideal for running on a Pi.&lt;/p>
&lt;p>If you want to use MQTT from the browser however, you also need the broker to support something called “&lt;!-- raw HTML omitted -->websockets&lt;!-- raw HTML omitted -->” since browsers cannot directly talk using the MQTT protocol. In the past, Mosquitto didn’t have websockets compiled in by default and compiling your own version on a Pi is painful to say the least.&lt;/p>
&lt;p>Thankfully, this is no longer a problem since the authors of Mosquitto now &lt;!-- raw HTML omitted -->provide a repository&lt;!-- raw HTML omitted --> containing ARM versions which work fine on the Pi. See mosquitto.org for the details.&lt;/p>
&lt;p>Once installed from the repository, you will need to add a suitable configuration since websockets are not part of the default configuration.&lt;/p>
&lt;p>To turn it on, you should add a new file to &lt;code>/etc/mosquitto/conf.d/&lt;/code> containing something like:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># See: http://mm011106.github.io/reference/mosquitto_conf.html&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Standard Listener&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">listener &lt;span class="m">1883&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">protocol mqtt
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">allow_anonymous &lt;span class="nb">false&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">password_file /etc/mosquitto/passwords.txt
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Websockets Listener&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">listener &lt;span class="m">9001&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">http_dir
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Set the protocol to accept &lt;span class="k">for&lt;/span> this listener. Can be mqtt &lt;span class="o">(&lt;/span>the default&lt;span class="o">)&lt;/span>, or websockets.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">protocol websockets
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Note that you can create more than one listener of the same type. You might, for example, want to create another listener that is restricted to a subset of topics so that you can allow access to that over the Internet. Perhaps you would restrict it to listing only sensor data but not control messages for your home automation project for example.&lt;/p>
&lt;p>Once you have enabled websockets access to Mosquitto, you can do some interesting things directly from web pages. Get hold of &lt;!-- raw HTML omitted -->MQTT.js&lt;!-- raw HTML omitted --> for the browser and you can both listen to and send messages from/to the broker. Combined with a framework such as &lt;!-- raw HTML omitted -->REACT&lt;!-- raw HTML omitted --> allows you to, with only a few lines of code, display all the messages that arrive at your broker.&lt;/p>
&lt;p>Updated 2018-04-24 21:20:16 - Tidy output after migration from WordPress.&lt;/p></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/development">Development</category><category domain="https://it.knightnet.org.uk/categories/home-automation-ha">Home Automation (HA)</category><category domain="https://it.knightnet.org.uk/categories/internet-of-things-iot">Internet of Things (IoT)</category><category domain="https://it.knightnet.org.uk/categories/software">Software</category><category domain="https://it.knightnet.org.uk/tags/home-automation">Home Automation</category><category domain="https://it.knightnet.org.uk/tags/internet-of-things">Internet of Things</category><category domain="https://it.knightnet.org.uk/tags/iot">IoT</category><category domain="https://it.knightnet.org.uk/tags/mqtt">MQTT</category><category domain="https://it.knightnet.org.uk/tags/node-red">Node-Red</category><category domain="https://it.knightnet.org.uk/tags/raspberry-pi">Raspberry Pi</category><category domain="https://it.knightnet.org.uk/tags/react">REACT</category></item></channel></rss>