MQTT Server on the Arduino YUN
Back to the beginning BYOB Party #1, "Bring you own Bulbs" - The Internet of Holiday Lights
In this episode leading up to the final party of the year we look at running the MQTT Server directly on the YUN, there are numerous posts where this is running on a VM on a PC or on another more capable device but truth be known, it will run perfectly well on the YUN OpenWRT Linux kernel directly, With the help from Mrs YUN, ill show you how
A video if you prefer (Oh, and I kept it under a half hour )
Or the text version for those so inclined to read , you know who you are
First thing is to update the Yun, use a wireless device or connect via the Ethernet port
(Wireless you look for the YUN SSID and connect, no code needed, then browse to "arduino")
(Ethernet, browse to the ip address or connect to arduino.local )
log in with the default password "arduino", the following screen is after the upgrade (Sorry, the video contains the original )
click configure and fill in for your local network
Set your time zone (Apparently Canada is part of America... who knew, so to find Toronto you need to select "America, Toronto), you don't need to change the password but do so if you wish
If your planning on using the REST interface and don't want it to be secure (No Password prompt when you try to access the rest interface), then also check "OPEN"
Then click on "Configure & restart"
I had to repeat this a few times before it stuck (Or I finally got the WIFI password right, one or the other )
anyway, once it is connecting to the local intranet (Home network), you should be able to connect using the url "HTTP://arduino.local", if this does not work, you may need to look at your router so see the IP address assigned to it and connect directly via the IP address "HTTP://192.168.nnn.nnn" or what ever your network is configured for. once you connect you will see a screen similar to that shown above, you may have different IP address of course.
After setting up the YUN via the WEB browser to configure it to connect to your local internet connection via WIFI or use the Ethernet port (Where's the fun in that)
Given your successful you should be able to SSH into the Linux side of the board. I use a program called PUTTY (Down load from PuTTY: a free telnet/ssh client ), the screen below show the start screen and how I configure it for my instance of a YUN. Saving the setting makes life so much easier later on
on connection you will be presented with a logon prompt, enter "root" for the logon name followed by "arduino" for the password
you should have a screen like the one below but without the mosquitto (MQTT) stuff at the bottom, note the date of the core version
BusyBox v1.19.4 (2014-11-13 19:03:47 CET), if yours is not at this level or newer, you may need to upgrade, I have two YUN's and one would work without upgrade, one would not, neither where at this date revision but all had the same version (v1.19.4) so I guess they don't update the version numbers for over a years worth of updates.so if things don't work and your not at this version, upgrade, it is very painless and I will have a video below (To Follow) to show how easy it is.
So once were here we can proceed to install the required software, this is available at the Mosquitto.org website "Mosquitto on OpenWrt | Mosquitto" simply follow the instructions
opkg update opkg install mosquitto mosquitto-client libmosquitto
and your ready to roll, just type "mosquitto" at the command prompt and your broker is ready and running
here is the screen show of those steps
using the samples provided on the mosquitto MQTT site, it is easy to test the servers operation (See here: Documentation | Mosquitto )
once subscribers and publishers start to use the server, it will print messages on the console as shown below
I set up a raspberry pi with MQTT client and published a few events to the YUN as shown here, it also had a second console subscribed to only the humidity topic (Was on temperature to start with)
The YUN console subscribed to a wild card topic using "oakesclan/#" and received every publication as shown (# is a wild card for MQTT topics)
So, there you have it, the Arduino YUN does not need a separate server to support MQTT, it is more than able to host the server itself and have numerous consoles running at the same time, in the next post I will be getting the Arduino side of the YUN to subscribe to the Linux side MQTT server and have it react to commands sent to the MQTT broker, at a later stage I will also try to configure the server to bridge to the Eclipse sandbox, extending the reach of the party.
Now Mrs YUN is ready to relay messages between all the guest who want to talk and those who will listen, now we need radios for the none network connected guests.