Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Practical Python Programming for IoT

You're reading from   Practical Python Programming for IoT Build advanced IoT projects using a Raspberry Pi 4, MQTT, RESTful APIs, WebSockets, and Python 3

Arrow left icon
Product type Paperback
Published in Nov 2020
Publisher Packt
ISBN-13 9781838982461
Length 516 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Gary Smart Gary Smart
Author Profile Icon Gary Smart
Gary Smart
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Section 1: Programming with Python and the Raspberry Pi
2. Setting Up your Development Environment FREE CHAPTER 3. Getting Started with Python and IoT 4. Networking with RESTful APIs and Web Sockets Using Flask 5. Networking with MQTT, Python, and the Mosquitto MQTT Broker 6. Section 2: Practical Electronics for Interacting with the Physical World
7. Connecting Your Raspberry Pi to the Physical World 8. Electronics 101 for the Software Engineer 9. Section 3: IoT Playground - Practical Examples to Interact with the Physical World
10. Turning Things On and Off 11. Lights, Indicators, and Displaying Information 12. Measuring Temperature, Humidity, and Light Levels 13. Movement with Servos, Motors, and Steppers 14. Measuring Distance and Detecting Movement 15. Advanced IoT Programming Concepts - Threads, AsyncIO, and Event Loops 16. IoT Visualization and Automation Platforms 17. Tying It All Together - An IoT Christmas Tree 18. Assessments 19. Other Books You May Enjoy

What this book covers

Chapter 1, Setting Up Your Development Environment, explores the Python ecosystem in the context of the Raspberry Pi OS and teaches you how to correctly set up a Python development project for success. You will also learn alternative ways of starting Python programs and how to configure your Raspberry Pi for GPIO interfacing.

Chapter 2, Getting Started with Python and IoT, teaches you the basics of electronics and GPIO interfacing with Python. You will build and experiment with simple electronic circuits that are controlled using Python, and combine this learning to build a simple yet complete internet-controllable IoT application from the ground up using the dweet.io platform.

Chapter 3, Networking with RESTful APIs and Web Sockets Using Flask, explores how to build network servers in Python using two approaches – RESTful APIs and Web Sockets. You will learn how to use these servers in conjunction with Python and an HTML/JavaScript user interface to control electronic circuits over a network from a web browser.

Chapter 4, Networking with MQTT, Python, and the Mosquitto MQTT Broker, teaches networking approaches using Message Queue Telemetry Transport, a popular choice for distributed IoT applications. You will learn how to use MQTT in conjunction with Python and an HTML/JavaScript user interface to control electronic circuits over a network and from a web browser.

Chapter 5, Connecting Your Raspberry Pi to the Physical World, explores different Python-based software options and techniques used to interface and control electronics using a Raspberry Pi's GPIO pins. You will also build and learn to use an ADS1115 analog-to-digital converter module to expand your Raspberry Pi's native interfacing options, and be introduced to Pulse Width Modulation (PWM), an important electronic and interfacing concept that you'll be using in later chapters.

Chapter 6, Electronics 101 for the Software Engineer, teaches you core electronic concepts and fundamentals. You will learn the essential how and why behind common electronic and interfacing circuits and how they are used practically to correctly and safely interface sensors and actuators to your Raspberry Pi. You will also learn the differences between digital and analog electronics and how each applies to and influences interfacing circuit requirements. Many of the fundamentals you learn about in this chapter are seen applied practically in subsequent chapters as we work with different electronic components and modules. 

Chapter 7, Turning Things On and Off, teaches you how to use optocouplers, MOSFET transistors, and relays to turn other circuits on and off using your Raspberry Pi and Python. You will also learn about circuit loads, how they are measured, and how this influences the choice and use of optocouplers, MOSFET transistors, and relays in circuits.

Chapter 8, Lights, Indicators, and Displaying Information, teaches you how to use an APA102 LED lighting strip, RGB LEDs, OLED displays, and buzzers in conjunction with Python to create visual and auditable orientated circuits and applications.

Chapter 9, Measuring Temperature, Humidity, and Light Levels, teaches you how to measure common environmental attributes with your Raspberry Pi and Python. You will build a circuit using a DHT11/22 temperature and humidity sensor and learn about and use Light-Dependent-Resistors (LDRs) to detect the presence or absence of light. In this chapter, you will also deepen your practical understanding and experience of analog electronics, and apply the basic principle to build a moisture detection circuit and application.

Chapter 10, Movement with Servos, Motors, and Steppers, teaches you how to create movement using popular mechanical devices together with your Raspberry Pi and Python. You will learn how to control a servo using PWM to create angular movement, use an H-bridge IC circuit together with a motor to control its speed and direction of rotation. Plus, you will learn how to adapt the H-bridge IC circuit for use with a stepper motor for those projects where you need precise control over movement.

Chapter 11, Measuring Distance and Detecting Movement, teaches you the principles behind distance measurements using an HC-SR04 ultrasonic distance sensor and how to use an HC-SR501 PIR sensor to detect movement on a macro scale. You will also learn how to use both a ratiometric and switch-type Hall-effect sensor to detect movement and measure relative distance on micro scales.

Chapter 12, Advanced IoT Programming Concepts – Threads, AsyncIO, and Event Loops, is an advanced programming chapter that looks at alternative approaches to structuring complex Python programs. You will learn about Python threading, asynchronous I/O, classic event loops, and publisher-subscriber patterns, all within the context of electronic interfacing. By the end of the chapter, you will have experimented with and understood four functionally equivalent applications that are written in four very different ways.

Chapter 13, IoT Visualization and Automation Platforms, is a journey into the world of IoT-related online services and integration. You will be creating two environmental-monitoring applications based on the DHT11/22 temperature and humidity circuit from Chapter 9, Measuring Temperature, Humidity, and Light Levels. First, you will leverage your MQTT understanding from Chapter 4, Networking with MQTT, Python, and the Mosquitto MQTT Broker, to create an online dashboard at ThingSpeak.com to display and graph both temperature and humidity data. Then, you will also apply RESTful API concepts from Chapter 4, Networking with MQTT, Python, and the Mosquitto MQTT Broker, and build an If-This-Then-That (IFTTT.com) workflow Applet that sends you an email whenever the temperature rises above or falls below a certain point.

Chapter 14, Tying It All Together – An IoT Christmas Tree, pulls together many of the themes and concepts you have learned about in earlier chapters with a multifaceted example centered around an internet-connected Christmas tree. From an electronics perspective, you will revisit the APA102 LED strip from Chapter 8, Lights, Indicators, and Displaying Information (this will be the Christmas tree lights), and servos from Chapter 10, Movement with Servos, Motors, and Steppers (this is used to provide a mechanism to shake or rock the tree). From a networking perspective, you will revisit dweet.io from Chapter 2, Getting Started with Python and IoT; RESTful-APIs from Chapter 3, Networking with RESTful APIs and Web Sockets Using Flask; and MQTT from Chapter 4, Networking with MQTT, Python, and the Mosquitto MQTT Broker, and learn how to combine techniques to achieve complex integrations that need to bridge different technologies. Finally, you will revisit IFTTT from Chapter 13, IoT Visualization and Automation Platforms, and create two Applets that let you control your tree's lights and make the tree shake or rock over the internet. These three Applets include email control, and voice-activated control using Google Assistant.

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 $19.99/month. Cancel anytime
Banner background image