<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Raspberry Pi on Much Ado About IT</title><link>https://it.knightnet.org.uk/tags/raspberry-pi/</link><description>
Recent content about Raspberry Pi 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/raspberry-pi/feed.xml" rel="self" type="application/rss+xml"/><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>