Hands-On MQTT Programming with Python
Work with the lightweight IoT protocol in Python
Gaston C. Hillar
BIRMINGHAM - MUMBAI
Hands-On MQTT Programming with Python
Copyright 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Kunal Choudhari
Acquisition Editor: Reshma Raman
Content Development Editor: Aditi Gour
Technical Editor: Sushmeeta Jena
Copy Editor: Safis Editing
Project Coordinator: Hardik Bhinde
Proofreader: Safis Editing
Indexer: Tejal Daruwale Soni
Graphics: Jason Monteiro
Production Coordinator: Shraddha Falebhai
First published: May 2018
Production reference: 1180518
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78913-854-2
www.packtpub.com
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and, as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details.
At www.PacktPub.com , you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
About the Author
Gaston C. Hillar is Italian and has been working with computers since he was 8 years old. Gaston has a bachelor's degree in computer science (graduated with honors) and an MBA. He is the CTO of Mapgenix, a freelance author, and a speaker.
He has been a senior contributing editor at Dr. Dobb's and has written more than a hundred articles on software development topics. He has received the prestigious Intel Black Belt Software Developer award eight times.
He lives with his wife, Vanesa, and his two sons, Kevin and Brandon.
Acknowledgements:
While writing this book, I was fortunate to work with an excellent team at Packt, whose contributions vastly improved the presentation of this book. Reshma Raman allowed me to provide her ideas to write a book dedicated to MQTT programming with Python, and I jumped into this exciting project. Aditi Gour helped me realize my vision for this book and provided many sensible suggestions regarding the text, the format, and the flow. The reader will notice her great work. It s been great working with Reshma on another project and I can't wait to work with Reshma and Aditi again. I would like to thank my technical reviewers and proofreaders for their thorough reviews and insightful comments. I was able to incorporate some of the knowledge and wisdom they have gained in their many years in the software development industry. This book was possible because they gave valuable feedback.
The entire process of writing a book requires a huge number of lonely hours. I wouldn't be able to write an entire book without dedicating some time to play soccer against my sons, Kevin and Brandon, and my nephew, Nicolas. Of course, I never won a match. However, I did score a few goals! Of course, I'm talking about real-life soccer, but I must also include virtual soccer when the weather didn't allow us to kick a real-life ball.
About the reviewer
Ben Howes is the founder and lead consultant at Zoetrope Ltd, a specialist IoT consultancy
and product development firm in the UK. Ben has been creating connected hardware for
over 10 years and has worked across projects spanning from start-ups to multinational
deployments.
I'd like to thank Richard Webb, my cofounder, for starting Zoetrope with me.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Preface
MQTT is the preferred IoT publish-subscribe lightweight messaging protocol. Python is definitely one of the most popular programming languages. It is open source, multiplatform, and you can use it to develop any kind of application. If you develop IoT, web applications, mobile apps, or a combination of these solutions, you must learn how MQTT and its lightweight messaging system works. The combination of Python and MQTT makes it possible to develop powerful applications that communicate with sensors, different devices, and other applications. Of course, it is extremely important to take security into account when working with this protocol.
Most of the time, when you work with complex IoT solutions coded in modern Python 3.6, you will use different IoT boards that might use diverse operating systems. MQTT has its own specific vocabulary and different working modes. Learning MQTT is challenging, because it includes too many abstract concepts that require real-life examples to be easy to understand.
This book will allow you to dive deep in to the latest version of the MQTT protocol: 3.1.1. You will learn to work with the most recent Mosquitto MQTT server, command-line tools, and GUI tools to allow you to understand how everything works with MQTT and the possibilities that this protocol provides for your projects. You will learn security best practices and use them for a Mosquitto MQTT server.
Next page