Beginning Sensor Networks with XBee, Raspberry Pi, and Arduino: Sensing the World with Python and MicroPython

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Build sensor networks with Python and MicroPython using XBee radio modules, Raspberry Pi, and Arduino boards. This revised and updated edition will put all of these together to form a sensor network, and show you how to turn your Raspberry Pi into a MySQL database server to store your sensor data!

You'll review the different types of sensors and sensor networks, along with new technology, including how to build a simple XBee network. You'll then walk through building an sensor nodes on the XBee, Raspberry Pi, and Arduino, and also learn how to collect data from multiple sensor nodes. The book also explores different ways to store sensor data, including writing to an SD card, sending data to the cloud, and setting up a Raspberry Pi MySQL server to host your data. You'll even learn how to connect to and interact with a MySQL database server directly from an Arduino! Finally you'll see how to put it all together by connecting your sensor nodes to your new Raspberry Pi database server.

If you want to see how well XBee, Raspberry Pi, and Arduino can get along, especially to create a sensor network, then Beginning Sensor Networks with XBee, Raspberry Pi, and Arduino is just the book you need.

What You'll Learn
  • Code your sensor nodes with Python and MicroPython
  • Work with new XBee 3 modules
  • Host your data on Raspberry Pi
  • Get started with MySQL
  • Create sophisticated sensor networks

Who This Book Is For

Those interested in building or experimenting with sensor networks and IoT solutions, including those with little or no programming experience. A secondary target includes readers interested in using XBee modules with Raspberry Pi and Arduino, those interested in controlling XBee modules with MicroPython.

Author(s): Charles Bell
Edition: 2
Publisher: Apress
Year: 2020

Language: English
Commentary: Vector PDF
Pages: 742
City: New York, NY
Tags: Python; Relational Databases; MySQL; Sensor Data; Wireless Networks; Raspberry Pi; Networks; Arduino; SDRAM; MicroPython; Sensors; XBee; Pressure Sensors; Sensor Networks; Temperature Sensors; Hybrid Networks; Mesh Networks

Table of Contents
About the Author
About the Technical Reviewer
Acknowledgments
Introduction
Chapter 1: Introduction to Sensor Networks
Anatomy of a Sensor Network
Examples of Sensor Networks
Automotive
Environment
Atmospheric
Security
The Topology of a Sensor Network
Communication Media
Wired Networks
Wireless Networks
Hybrid Networks
Types of Sensor Nodes
Basic Sensor Nodes
Data Nodes
Aggregator Nodes
Sensors
How Sensors Measure
Analog Sensors
Digital Sensors
Storing Sensor Data
Examples of Sensors
Summary
Chapter 2: Tiny Talking Modules: An Introduction to XBee Wireless Modules
What Is an XBee?
XBee Primer
Choosing XBee Modules
Interacting with an XBee-ZB Module
Pin Layout
Configuring Modules
Addresses
ZigBee Networks
Updating Firmware
Changing Settings with a Terminal Application
For More Information
Introducing MicroPython
An XBee Wireless Chat Room
Loading the Firmware for the Modules
Series 2.5 and Earlier
Series 3
Loading the Firmware for the Coordinator
Loading the Firmware for the Router
Capturing Serial Numbers
Configuring the Coordinator
Configuring the Router
Let the Chat Begin
For More Fun
Building an XBee-ZB Mesh Network
Loading the Firmware for the Modules
Configuring the XBee Modules
Forming Test Messages
Testing the Network
For More Fun
Component Shopping List
Troubleshooting Tips and Common Issues
Things to Check
Common Issues
Summary
Chapter 3: Programming in MicroPython
MicroPython Features and Limitations
MicroPython Features
MicroPython Limitations
Basic Concepts
Code Blocks
Comments
Arithmetic
Output to Screen
Variables and Data Types
Variables
Types
Basic Data Structures
Lists
Tuples
Dictionaries
Flow Control Statements
Conditional Statements
Loops
Modularization: Modules, Functions, and Classes
Including Modules
Functions
Classes and Objects
Object-Oriented Programming (OOP) Terminology
Summary
Chapter 4: XBee-Based Sensor Nodes
How to Host Sensors with XBee
Building an XBee Environment Sensor
Hardware Setup
XBee Hardware Option
Configuring the XBee Sensor Node
Setting Up the Coordinator
Testing the XBee Sensor Node
MicroPython Option
Configuring the XBee Sensor Node
Programming the Sensor Node
Setting Up the Coordinator
Testing the XBee Sensor Node
Example: Using XBee Modules to Gather Data
Hardware Setup
BMP280 with Jumper Wires
BMP280 with Grove Breakout Cable
Grove BMP280 Module Connections
Configuring the XBee Sensor Node
Programming the Sensor Node
Testing the XBee Sensor Node
Component Shopping List
Summary
Chapter 5: Raspberry Pi–Based Sensor Nodes
What Is a Raspberry Pi?
Noble Origins
Models
A Tour of the Board
Required Accessories
Recommended Accessories
Pi Tin
Pibow Coupé
Where to Buy
Raspberry Pi Tutorial
Getting Started
Installing a Boot Image
Choosing the Image
Installing Using NOOBS
Installing Raspbian
Windows
Mac OS X
Linux
Booting Up
Care and Feeding of the SD Card
GPIO Pin Mapping
Required Software
Project: Hardware “Hello, World!”
Hardware Connections
Writing the Script
Testing the Sensor
For More Fun
Hosting Sensors with Raspberry Pi
Project: Building a Raspberry Temperature Sensor Node
Hardware Setup
Testing the Hardware
Software Setup
Testing the Sensor
For More Fun
Project: Building a Raspberry Barometric Pressure Sensor Node
Hardware Setup
Testing the Hardware
Software Setup
Testing the Sensor
For More Fun
Project: Creating a Raspberry Pi Data Collector for XBee Sensor Nodes
XBee Sensor Node
Hardware
Software
Testing the Final Project
For More Fun
Component Shopping List
Summary
Chapter 6: Arduino-Based Sensor Nodes
What Is an Arduino?
Arduino Models
Uno
Leonardo
Due
Mega 2560
Micro
Nano
MKR-Series Boards
Arduino Clones
Arduino Pro Mini
Fio
Seeeduino
Sippino
Prototino
Metro from Adafruit
So, Which Do I Buy?
Where to Buy
Online Retailers
Retail Stores (United States)
Arduino Tutorial
Learning Resources
The Arduino IDE
Project: Hardware “Hello, World!”
Hardware Connections
Writing the Sketch
Compiling and Uploading
Testing the Sensor
Hosting Sensors with Arduino
Project: Building an Arduino Temperature Sensor
Hardware Setup
Software Setup
Writing the Sketch
Test Execution
Project: Using an Arduino As a Data Collector for XBee Sensor Nodes
XBee Sensor Node
Coordinator Node
Arduino with XBee Shield
Hardware Setup
Software Setup
Testing the Final Project
For More Fun
Component Shopping List
Summary
Chapter 7: Methods for Storing Sensor Data
Storage Methods
Local Storage Options for the Arduino
Nonvolatile Memory
SD Card
Project: Saving Data in Nonvolatile Memory
Hardware Setup
Software Setup
Testing the Sketch
For More Fun
Project: Writing Data to an SD Card
Hardware Setup
Software Setup
Testing the Sketch
Local Storage Options for the Raspberry Pi
Project: Writing Data to Files
Remote Storage Options
Storing Data in the Cloud
Getting Started with ThingSpeak
Creating a Channel
Project: Writing Data to ThingSpeak with an Arduino
Hardware Setup
Configuring the Arduino IDE
Write the Sketch
Testing the Sketch
For More Fun
Project: Writing Data to ThingSpeak with a Raspberry Pi
Hardware Setup
Write the Code
Testing the Script
For More Fun
Storing Sensor Data in a Database
Component Shopping List
Summary
Chapter 8: Turning Your Raspberry Pi into a Database Server
What Is MySQL?
Getting Started with MySQL
What’s a Relational Database Management System?
How and Where MySQL Stores Data
Common Storage Engines
Where Is My Data Stored?
The MySQL Configuration File
How to Start, Stop, and Restart MySQL
Creating Users and Granting Access
Building a Raspberry Pi MySQL Server
Partitioning and Formatting the Drive
Setting Up Automatic Drive Mounting
Project: Installing MySQL Server on a Raspberry Pi
Prerequisites
Building MySQL Server
Running CMake (Preparing to Compile)
Running Make (Compiling)
Making the Package
Installing MySQL Server
Configuring MySQL Server
Moving the Data Directory to the External Drive
Advanced Project: Using MySQL Replication to Back Up Your Sensor Data
What Is Replication, and How Does It Work?
How to Set Up Replication
Preparing the Master
Component Shopping List
Summary
Chapter 9: MySQL and Arduino: United at Last!
Introducing Connector/Arduino
Hardware Requirements
What About Memory?
Installing MySQL Connector/Arduino
Limitations
Building Connector/Arduino-Enabled Sketches
Database Setup
Setting Up the Arduino
Starting a New Sketch
Include Files
Preliminary Setup
Connecting to a MySQL Server
Running a Query
One More Thing…
Testing the Sketch
What About the Ethernet Shield 2?
What About the WiFi Shield?
What About the WiFi 101 Shield?
Troubleshooting Connector/Arduino
MySQL Server Configuration
Server Is Not Using Networking
Cannot Connect, and Correct IP Address Is Used
I Can Connect Locally but Not Remotely
MySQL User Account Problems
Networking Configuration
Connector Installation
Compilation Errors Related to “No Module Named”
Compilation Errors Related to Include File
Others
Strange Characters Appear in the Serial Monitor
No Output in the Serial Monitor
My Sketch Is Too Big
None of These Solved My Problem—What Next?
A Tour of the MySQL Connector/ Arduino Code
Library Files
Field Structure
Public Methods
MySQL_Connection
MySQL_Cursor
MySQL_Packet
Example Uses
Queries Without Results
Queries Returning Results
Project: Building a MySQL Arduino Client
Hardware Setup
Software Setup
Setting Up the Sensor Database
Writing the Code
Test Execution
For More Fun
Project Example: Inserting Data from Variables
Project Example: How to Perform SELECT Queries
Displaying a Result Set in the Serial Monitor
Writing Your Own Display Method
Example: Getting a Lookup Value from the Database
Component Shopping List
Summary
Chapter 10: Building Your Network: Arduino Wireless Aggregator + Wireless Sensor Node + Raspberry Pi Server
Data-Aggregate Nodes
Local-Storage Data Aggregator
Project: Data-Aggregate Node with Local Storage
Hardware
Data-Aggregate Node
Sensor Nodes
Software
Overview
Lightweight Web Server
Local Storage Using the Onboard EEPROM
Reading Data from Sensor Nodes via XBee
Putting It All Together
Testing the Project
For More Fun
Remote-Storage Data Aggregator
Project: Arduino Data-Aggregate Node with Database Storage
Hardware
Software
Adding the MySQL Connector Code to the Sketch
Setting Up the MySQL Database
Testing the Project
For More Fun
Project: Raspberry Pi Data-Aggregate Node with Database Storage
Hardware
Software
Testing the Project
For More Fun
Component Shopping List
Summary
Chapter 11: Putting It All Together
Sensor Networks Best Practices
Considerations for Data-Aggregate Nodes
Network Type and Node Placement
Storing Data
Considerations for Sensor Network Databases
How Data Is Organized
Table Design Notes
Adding Indexes for Query Efficiency
Other Considerations
Stay Within Range of XBee Modules
Keep an Engineering Logbook
Putting It All Together: Testing and Deploying Your Sensor Network
Choosing Sensor Nodes
Wired or Wireless?
Arduino or Raspberry Pi?
Cost
Security
Functionality
Expandability
Connectivity
Alternative Hosts
Seeed Studio Wireless Sensor Kit
Raspberry Pi Alamode
Project: Home Temperature-Monitoring Network
Planning Considerations
Planning the Nodes
Cost Considerations
What About Implementation?
Conclusion
For More Fun
Optional Component Shopping List
Summary
Appendix
Consolidated Shopping Lists
Alternative Connection Systems
Grove
Qwiic
STEMMA QT
Summary
Index