Running Mosquitto MQTT on Windows 10 super easy

29 Mar 2018 | Running Mosquitto MQTT on Windows 10 super easy |

TTGO esp32 LoRa Modules using MQTT

So I’ve been playing with all things Arduino , Raspberry Pi and IoT lately, when it comes to be able to easily link all these devices, the de facto standard is to use a MQTT  server and protocol  . But finding a Windows 10 version is complicated. This post I’ll describe the super-easy steps to getting it p and running with Windows 10 . The trick on Windows 10 (yes only on Windows 10 or later) is to Install Windows Linux Subsytem (WSL)

One very popular implementation of the MQTT Broker is the Eclipse Mosquitto™ An open source MQTT broker, it runs on multiple platforms, Linux is by far the preferred platform, and while it does have a Windows variation unfortunately it requires too many dependencies  to make it practical to just run the install script and get it up and running.

Challenges of Running Mosquitto on earlier Windows Vista,7 ,8 …

Basically if you have a version of Windows prior to Windows 10, you will need to perform the following steps  , or a variation of these (Some sites use Cywin for the Linux layer)..

  1. Download and install Mosquitto for Windows from official source Eclipse Paho
  2. . Download and install OpenSSL for Windows , make sure you grab the older version Win32 OpenSSL v1.0.2o as newer versions are missing critical dll.
  3. Download and unzip Win32  Pthread dll , and copy them to you mosquitto binary folder,  remember double check my links, be careful and make sure these are from reputable sources,  I inadvertently downloaded some virus just blindly clicking other sites  links,..
  4. Run and test mosquitto Server..

As you can see it’s a bit of an involved process., plus some of those binaries or dll’s  must be a certain 32bit version for overall library compatibility so it’s a hassle, again be careful where you get the binaries/dll from some are compromised. For complete details visit this post.4 steps to install Mosquitto MQTT server on Windows

Windows 10 Runs  Linux shell  via Windows 10’s Windows Subsystem for Linux (WSL)

The reason things are much easier in Windows 10, is because Microsoft has made it so you can install a Windows Subsytem for Linux  .   Simply run the command below as an administrator in Powershell and then reboot.

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Installing Ubuntu (or other Linux) from Microsoft Store (free)

Once your system reboots, no head on over to the Microsoft Store (a trusted source)

Microsoft Store available linux packages

and choose a Linux distribution, that is available and you prefer, I went with Ubuntu .

After that installs , just run it  and it will put you into the Ubuntu Linux Shell, and from here you can proceed to install good ole Linux Mosquitto,best to  Uudate the distribution first..

sudo apt-get update

then install mosquitto. and run it, it will run on the default port 1883. You can of course configure it just refer to the usual  Linux Mosquitto docs.

sudo apt-get install mosquitto

Run Mosquitto in Linux Subsystem

We’re almost done! we need to do one more step. You need to  open up your ports to allow the Linux subsystem to be reachable from the outside and act as a server. Steps are…

Windows 10 Firewall Advanced settings

  • Go to Windows Firewall with Advanced Security  (choose Advanced Settings in Firewall prompt)
  • Click Inbound Rules then on right hand pane  add a New Rule 
  • This will bring up a  New Rules wizard, just follow the prompt entering the following
  • Set rule type as Port.
  • Enter a Specific local port your server is running under WSL, in this case, 1883
  • Choose TCP port
  • in the next tab Action tab, choose Allow the connection
  • next where this rule Applies choose all appropriate Domains, such as Public (entire Internet) or Private (just my local LAN traffic) or check all for complete access from outside.
  • and finally just name the Rule (Mosquitto port 1883) or something similar and press Finish.

Now all MQTT traffic to this server should be responded to as expected.  Also you can access  Windows Drives.folders check under the /mnt/  folder.

Note: this approach has  one drawback, running it as a server after rebooting, that is the server because its part of the Windows Linux Subsystem will need to be started automatically each time windows re-boots, and this may require more fiddling, I found a post here that may be of help.  Starting a linux bash application as a service, since you need to have windows automatically boot the WSL for mosquitto to run in this environment, I gather its possible , but requires more tweaking.. if any windows folks have any good suggestions let me know.

Conclusion

While it may seem like a lot of steps , I can tell you it will only take a few minutes compared to all the time needed to try and get Mosquitto running as a native windows application.. Hope this helps some of you guys, leave comments and share your experiences.

5 (100%) 1 vote

2 thoughts on “Running Mosquitto MQTT on Windows 10 super easy

  1. Reply RajTowdry Apr 17,2018 6:32 pm

    Excellent works perfectly for me and so much easier than other examples

  2. Reply sanjayPtel Apr 21,2018 3:11 pm

    Awesome, yes , finally a straightforward way to run Mosquitto on Windows, thanks abrandao.com you saved me a bunch of time

Leave a Reply