Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
MQTT Essentials - A Lightweight IoT Protocol

You're reading from   MQTT Essentials - A Lightweight IoT Protocol Send and receive messages with the MQTT protocol for your IoT solutions.

Arrow left icon
Product type Paperback
Published in Apr 2017
Publisher Packt
ISBN-13 9781787287815
Length 280 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Gaston C. Hillar Gaston C. Hillar
Author Profile Icon Gaston C. Hillar
Gaston C. Hillar
Arrow right icon
View More author details
Toc

Table of Contents (8) Chapters Close

Preface 1. Lightweight Messaging with MQTT 3.1.1 and Mosquitto FREE CHAPTER 2. Securing an MQTT Mosquitto Server 3. Controlling a Drone with Python 4. Interacting with Sensors in Java 5. Controlling Home Automation in JavaScript 6. Interacting with Actuators in Swift A. Exersise Answers

Installing a Mosquitto broker on macOS

Follow these steps to install a Mosquitto broker on macOS (known as OS X before version Sierra):

  1. In case you don't have Homebrew installed, open a Terminal window and run the command indicated in the Homebrew homepage, http://brew.sh , to install this popular package manager for macOS. The following command will do the job. However, it is convenient to check the Homebrew homepage and check all the detailed instructions that are always updated with the newest versions of macOS that become available. In case you already have Homebrew installed, move to the next step.
    /usr/bin/ruby -e "$(curl -fsSL
    https://raw.githubusercontent.com/Homebrew
    /install/master/install)"
    
  2. Open a Terminal window and run the following command to request Homebrew to install Mosquitto:
          brew install mosquitto
    
  3. The following lines show the last messages shown in the Terminal that indicate that Homebrew has installed Mosquitto and the instructions to start the MQTT server.
          ==> Installing mosquitto 
          ==> Downloading https://homebrew.bintray.com/bottles/mosquitto-      1.4.10.el_capitan.bottle.tar.gz
          ###################################################### 100.0%
          ==> Pouring mosquitto-1.4.10.el_capitan.bottle.tar.gz
          ==> Caveats
          mosquitto has been installed with a default configuration file.
          You can make changes to the configuration by editing:
              /usr/local/etc/mosquitto/mosquitto.conf
          To have launchd start mosquitto now and restart at login:
            brew services start mosquitto
          Or, if you don't want/need a background service you can just run:
            mosquitto -c /usr/local/etc/mosquitto/mosquitto.conf
          ==> Summary
            /usr/local/Cellar/mosquitto/1.4.10: 32 files, 618.3K
    
  4. After the Mosquitto installation has been completed, run the following command in a new Terminal window to launch Mosquitto with the default configuration file. The -c option followed by /usr/local/etc/mosquitto/mosquitto.conf specifies that we want to use this configuration file.
          /usr/local/sbin/mosquitto -c /usr/local/etc/mosquitto/mosquitto.conf
    

    The following is the output after you run the previous command:

          Gastons-MacBook-Pro:~ gaston$ /usr/local/sbin/mosquitto -c       /usr/local/etc/mosquitto/mosquitto.conf
          1482518967: mosquitto version 1.4.10       (build date 2016-08-31 20:09:41+0100) starting
          1482518967: Config loaded from       /usr/local/etc/mosquitto/mosquitto.conf.
          1482518967: Opening ipv4 listen socket on port 1883.
          1482518967: Opening ipv6 listen socket on port 1883.
    

    The last lines indicate the Mosquitto MQTT server has opened an IPv4 and an IPv6 listen socket on port 1883. Leave the Terminal window opened because we need Mosquitto running on the local computer to work with the next examples.

You have been reading a chapter from
MQTT Essentials - A Lightweight IoT Protocol
Published in: Apr 2017
Publisher: Packt
ISBN-13: 9781787287815
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime