element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Blog Part 1: Setting up a MQTT broker locally
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: pmohan
  • Date Created: 11 Dec 2014 2:47 AM Date Created
  • Views 16996 views
  • Likes 2 likes
  • Comments 2 comments
  • RoadTest
  • wifi_christmas_tree
  • iot_holidaylights
  • arduino_tutorials
  • arduino
Related
Recommended

Part 1: Setting up a MQTT broker locally

pmohan
pmohan
11 Dec 2014

As i mentioned in the introduction i am waiting for parts to arrive. Meanwhile i started to set up my MQTT infrastructure.

 

My initial plan was to use the sandboxed MQTT Broker available at iot.eclipse.org at port 1883. Then i decided to explore more about the MQTT Broker and wanted to run one locally on my PC and use it as the MQTT gateway for all my needs. Since the Mosquitto broker allows bridging, it should be possible for me to selectively choose “topics” to forward to one or more of sandboxes available on the internet.

 

Installation


The sandboxed MQTT broker above is running the Open Source Mosquitto broker in its version 1.3.1. So i got the broker for windows downloaded from http://mosquitto.org/download/ and installed. After the installation is complete, I could see the Mosquitto Broker services in the control panel. I found that the service is not started by default so i started the service.

I also went ahead and installed the Mosquitto broker on my Mac. This way i can test the bridge functionalities locally. In addition this allows me to make my PCs as MQTT Publishers and subscribers. The audio elements in my project will run from my Mac or PC by subscribing to the appropriate MQTT topic.

When i get my Arduino Yun, it should be possible for me to run the Mosquitto broker on the Yun as well since a OpenWrt version is available at the same download url.

 

Verifying the Install


In the install directory, there were two handy utilities that were available.

  • mosquitto_sub  — A command line utility for subscribing to Topics
  • mosquitto_pub  — A command line utility for publishing simple messages one at a time

 

On Mac these were available at:

/usr/local/opt/mosquitto/bin

 

On PC these were available at:

C:\Program Files (x86)\mosquitto

 

Running mosquitto_sub

 

First i ran the mosquitto_sub with the wild card “#” for the topic name in one terminal window. This allowed me to watch every message that is being sent to my gateway. This will be very useful if i run into issues later in the project and need to debug.

mosquitto_sub -h localhost -v -t "#"

-v is for making the output verbose. This will print the Topic name as well along with the actual message payload.

 

Running mosquitto_pub

Then i opened another terminal window and ran the mosquitto_pub to send some test messages out.

mosquitto_pub -t WiFiTree/RGB -m "210,230,0"

mosquitto_pub -t WiFiTree/RGB -m "0,0,0"

mosquitto_pub -t WiFiTree/Sound -m "0.2"


I could see that the setup is working correctly when the outputs started appearing in the subscriber window. Here are the screen shots for both Subscriber and publisher.

 

Mac OSX

image

 

Windows

image

 

Setting up the Bridge on Mac to forward certain topics to MQTT Bridge on PC

 

Before setting up the bridge to sandbox brokers on the net, i wanted to set up the bridge between my broker on Mac and PC. This would allow me to bring these machines also in to my holiday project infrastructure to play sound and other things that i have not thought of yet. There isn’t any specific need for me to run multiple brokers. But i just wanted to test out the capability because some day it might come handy.

 

So on Mac i modified the well documented mosquitto configuration file at

/usr/local/etc/mosquitto/mosquitto.conf

 

and added the following:

connection mywindowsmqttbroker
address 192.168.1.217
topic WiFiTree/ForWindowsPC/Test

 

This configuration should enable the MQTT broker on Mac to forward only the MQTT messages with the topic  "WiFiTree/ForWindowsPC/Test” to my windows PC.

 

After the configuration change I restarted my mosquito demon and sent out some test messages from my mac:

mosquitto_pub -t WiFiTree/ForWindowsPC/Test -m "Test MQTT bridge message for Windows From Mac"

 

Success!!!. i was able to see that my Windows PC was receiving only those topics from mac.

image

 

Now that my MQTT brokers are set up the way i want, each of the modules of my WiFi Christmas Tree project can be individually tested and put together.

 

Some thought for future exploration

 

As many of you might have already done, the routers can be modified to run OpenWrt. Since a openWrt version of MQTT broker is available, the router might be the right place to run a home specific MQTT broker. I hope someday router manufacturers by default will put a MQTT broker on their products making it easier for deploying connected devices. My router is not modified to run openWrt. One day i will get around to do that.

 

Document Links

http://mosquitto.org/documentation/

  • Sign in to reply

Top Comments

  • DAB
    DAB over 10 years ago +1
    Very good description on how to use MQTT between different platforms. DAB
Parents
  • DAB
    DAB over 10 years ago

    Very good description on how to use MQTT between different platforms.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • DAB
    DAB over 10 years ago

    Very good description on how to use MQTT between different platforms.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • pmohan
    pmohan over 10 years ago in reply to DAB

    Thanks DAB.. It's fun exploring and tinkering around..

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube