Internet of Things with Python

Interact with the world and rapidly prototype IoT applications using Python

Gastón C. Hillar


e-books shop
e-books shop
Purchase Now !
Just with Paypal



Book Details
 Price
 2.50 USD
 Pages
 388 p
 File Size
 9,457 KB
 File Type
 PDF format
 ISBN
 978-1-78588-138-1
 Copyright   
 2016 Packt Publishing 

About the Author
Gastón C. Hillar is Italian and has been working with computers since he was eight. He began programming with the legendary Texas TI-99/4A and Commodore 64 home computers in the early 80s. He has a bachelor's degree in computer science, in which he graduated with honors, and an MBA, in which he graduated with an outstanding thesis. At present, Gastón is an independent IT consultant and freelance author who is always looking for new adventures around the world.
He has been a senior contributing editor at Dr. Dobb's and has written more than a hundred articles on software development topics. Gaston was also a Microsoft MVP in technical computing. He has received the prestigious Intel® Black Belt Software Developer award seven times.
He is a guest blogger at Intel® Software Network (http://software.intel.com). You can reach him at gastonhillar@hotmail.com and follow him on Twitter at http://twitter.com/gastonhillar.
He lives with his wife, Vanesa, and his two sons, Kevin and Brandon.

About the Reviewer
Navin Bhaskar has over 4 years of experience in embedded systems, having written code ranging from device drivers to firmware for smart cards. He won the Distinctive Excellence award in the mbed design challenge for his Reconfigurable Computing for Embedded System project and the third prize for his EvoMouse in the OpenWorld contest. You can find his blog at https://navinbhaskar.wordpress.com/, where you can find tutorials on IoT and related topics.   

Preface
Internet of Things, also known as IoT, is changing the way we live and represents one of the biggest challenges in the IT industry. Developers are creating low-cost devices that collect huge amounts of data, interact with each other, and take advantage of cloud services and cloud-based storage. Makers all over the world are working on fascinating projects that transform everyday objects into smart devices with sensors and actuators.

A coffee cup is not a simple object anymore—it can send a message to your smartwatch indicating that the liquid inside has the right temperature so that you can drink it without worrying about checking whether it is too hot. In case you move the coffee cup before you receive the message, your wearable vibrates to indicate that you don't have to drink it yet.

You can check the coffee level of the coffee dispenser in your smartphone, and you won't have to worry about ordering more coffee: the coffee dispenser will automatically place an online order to request coffee when the coffee level is not enough to cover the rest of the day. You just need to approve the online order that the coffee dispenser suggests from your smartwatch. Based on certain statistical algorithms, the coffee dispenser will know the appropriate time to make the order.

What happens when more usual visitors arrive at the office? Their smartwatches or smartphones will communicate with the coffee dispensers and they will place orders in case the probable consumption of decaffeinated coffee increases too much. We have smart coffee cups, smart coffee dispensers, smartwatches, smartphones, and wearables. All of them take advantage of the cloud to create a smart ecosystem capable of providing us with all the different types of coffees we need for our day.

The Intel Galileo Gen 2 board is an extremely powerful and versatile minicomputer
board for IoT projects. We can boot a Linux version and easily execute Python scripts
that can interact with the different components included on the board. This book will
teach you to develop IoT prototypes, from selecting the hardware to all the necessary
stacks with Python 2.7.3, its libraries, and tools. In case you need a smaller board or
an alternative, all the examples included in the book are compatible with Intel Edison
boards, and therefore, you can switch to this board in case you need to.

Python is one of the most popular programming languages. It is open source,
multiplatform, and you can use it to develop any kind of application, from websites
to extremely complex scientific computing applications. There is always a Python
package that makes things easier for us in order to avoid reinventing the wheel and
solve problems faster. Python is an ideal choice for developing a complete IoT stack.
This book covers all the things you need to know to transform everyday objects into IoT projects.

This book will allow you to prototype and develop IoT solutions from scratch with
Python as the programming language. You will leverage your existing Python
knowledge to capture data from the real world, interact with physical objects,
develop APIs, and use different IoT protocols. You will use specific libraries to easily
work with low-level hardware, sensors, actuators, buses, and displays. You will learn
how to take advantage of all the Python packages with the Intel Galileo Gen 2 board.
You will be ready to become a maker and to be a part of the exciting IoT world.

Table of Contents
Preface v
Chapter 1: Understanding and Setting up the Base IoT Hardware 1
Understanding the Intel Galileo Gen 2 board and its components 2
Recognizing the Input/Output and the Arduino 1.0 pinout 8
Recognizing additional expansion and connectivity capabilities 12
Understanding the buttons and the LEDs 17
Checking and upgrading the board's firmware 20
Test your knowledge 25
Summary 26
Chapter 2: Working with Python on Intel Galileo Gen 2 27
Setting up the board to work with Python as the
programming language 27
Retrieving the board's assigned IP address 34
Connecting to the board's operating system 39
Installing and upgrading the necessary libraries to interact
with the board 44
Installing pip and additional libraries 50
Invoking the Python interpreter 52
Test your knowledge 53
Summary 54
Chapter 3: Interacting with Digital Outputs with Python 55
Turning on and off an onboard component 55
Prototyping with breadboards 62
Working with schematics to wire digital outputs 65
Counting from 1 to 9 with LEDs, Python code and the mraa library 73
Taking advantage of object-oriented code to control digital outputs 78
Improving our object-oriented code to provide new features 81
Isolating the pin numbers to improve wirings 82
Controlling digital outputs with the wiring-x86 library 87
Test your knowledge 89
Summary 90
Chapter 4: Working with a RESTful API and Pulse
Width Modulation 91
Printing numbers in LEDs with a RESTful API 91
Composing and sending HTTP requests 98
Wiring pins with PWM capabilities 103
Using PWM to generate analog values 107
Generating analog values via HTTP requests 114
Preparing the RESTful API for Web application requirements 117
Using PWM plus a RESTful API to set colors for an RGB LED 119
Controlling PWM with the wiring-x86 library 124
Test your knowledge 126
Summary 127
Chapter 5: Working with Digital Inputs, Polling and Interrupts 129
Understanding pushbuttons and pullup resistors 130
Wiring digital input pins with pushbuttons 135
Reading pushbutton statuses with digital inputs and the mraa library 138
Reading pushbutton statuses and running a RESTful API 142
Reading digital inputs with the wiring-x86 library 148
Using interrupts to detect pressed pushbuttons 151
Test your knowledge 159
Summary 160
Chapter 6: Working with Analog Inputs and Local Storage 161
Understanding the analog inputs 161
Wiring an analog input pin with a voltage source 163
Measuring voltage with analog inputs and the mraa library 166
Wiring a photoresistor to an analog input pin 167
Determining the darkness level with analog inputs and the
mraa library 171
Firing actions when the environment light changes 174
Controlling analog inputs with the wiring-x86 library 180
Logging to files in the local storage 183
Working with USB attached storage 186
Test your knowledge 190
Summary 191
Chapter 7: Retrieving Data from the Real World with Sensors 193
Understanding sensors and their connection types 194
Working with accelerometers 199
Wiring an analog accelerometer to the analog input pins 200
Measuring three axis acceleration with an analog accelerometer 203
Wiring a digital accelerometer to the I2C bus 207
Measuring three axis acceleration with a digital accelerometer 211
Using the I2C bus to control a digital accelerometer with the
mraa library 214
Wiring an analog temperature sensor 221
Measuring ambient temperature with an analog sensor 224
Wiring a digital temperature and humidity sensor to the I2C bus 226
Measuring temperature and humidity with a digital sensor 229
Test your knowledge 232
Summary 233
Chapter 8: Displaying Information and Performing Actions 235
Understanding LCD displays and their connection types 235
Wiring an LCD RGB backlight to the I2C bus 238
Displaying text on an LCD display 241
Wiring an OLED dot matrix to the I2C bus 246
Displaying text on an OLED display 249
Wiring a servo motor 252
Positioning a shaft to indicate a value with a servo motor 256
Test your knowledge 259
Summary 260
Chapter 9: Working with the Cloud 261
Publishing data to the cloud with dweepy 261
Building a web-based dashboard with Freeboard 269
Sending and receiving data in real-time through Internet with PubNub 275
Publishing messages with commands through the PubNub cloud 283
Working with bi-directional communications 289
Publishing messages to the cloud with a Python PubNub client 296
Using MQTT with Mosquitto and Eclipse Paho 303
Publishing messages to a Mosquitto broker with a Python client 311
Test your knowledge 316
Summary 317
Chapter 10: Analyzing Huge Amounts of Data with
Cloud-based IoT Analytics 319
Understanding the relationship between Internet of Things
and Big Data 319
Understanding the Intel IoT Analytics structure 321
Setting up devices in Intel IoT Analytics 324
Setting up components in Intel IoT Analytics 328
Collecting sensor data with Intel IoT Analytics 336
Analyzing sensor data with Intel IoT Analytics 344
Triggering alerts with rules in Intel IoT Analytics 349
Test your knowledge 354
Summary 355
Appendix: Exercise Answers 357
Index 361

Bookscreen
e-books shop

What you need for this book
In order to work with the different tools required to connect to the Intel Galileo Gen
2 board and launch the Python samples, you will need any computer with an Intel
Core i3 or higher CPU and at least 4 GB of RAM. You can work with any of the
following operating systems:
• Windows 7 or higher (Windows 8, Windows 8.1, or Windows 10)
• Mac OS X Mountain Lion or higher
• Any Linux version capable of running Python 2.7.x
• Any modern browser with JavaScript support.
You will also need an Intel Galileo Gen 2 board and a breadboard with 830 tie points
(holes for connections) and 2 power lanes.
In addition, you will need different electronic components and breakout boards to
build the examples included in many chapters.

Who this book is for
This book is ideal for Python programmers who want to explore the tools available
in the Python ecosystem in order to build their own IoT web stack and IoT-related
projects. People from creative and designing backgrounds will also find this book
equally useful.
Loading...
DMCA.com Protection Status