Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Hands-On MQTT Programming with Python

You're reading from  Hands-On MQTT Programming with Python

Product type Book
Published in May 2018
Publisher Packt
ISBN-13 9781789138542
Pages 228 pages
Edition 1st Edition
Languages
Author (1):
Gaston C. Hillar Gaston C. Hillar
Profile icon Gaston C. Hillar

Table of Contents (9) Chapters

Preface 1. Installing an MQTT 3.1.1 Mosquitto Server 2. Using Command-Line and GUI Tools to Learn How MQTT Works 3. Securing an MQTT 3.1.1 Mosquitto Server 4. Writing Code to Control a Vehicle with Python and MQTT Messages 5. Testing and Improving Our Vehicle Control Solution in Python 6. Monitoring a Surfing Competition with Cloud-Based Real-Time MQTT Providers and Python 7. Solutions 8. Other Books You May Enjoy

Publishing messages with a command-line tool

We will use the mosquitto_pub command-line utility included in Mosquitto to generate a simple MQTT client that publishes a message to a topic. Open a Terminal in macOS or Linux, or a Command Prompt in Windows, go to the directory in which Mosquitto is installed, and run the following command:

mosquitto_pub -V mqttv311 -t sensors/octocopter01/altitude -m  "25 f" -d

The previous command will create an MQTT client that will establish a connection with the local MQTT server and then will make the client publish a message to the topic specified after the -t option: sensors/octocopter01/altitude. We specify the payload for the message after the -m option: "25 f". We specify the version of the MQTT protocol that we want to use when the client establishes the connection with -V mqttv311. This way, we indicate to the MQTT...

lock icon The rest of the chapter is locked
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 $15.99/month. Cancel anytime}