MySQL for the Internet of Things

329 Pages · 9.69 mb ·

Charles Bell

Internet

Table of contents

- Contents at a Glance (Page 5)
- Contents (Page 6)
- About the Author (Page 11)
- About the Technical Reviewer (Page 12)
- Acknowledgments (Page 13)
- Introduction (Page 14)
- Chapter 1: The Internet of Things and Data (Page 17)
- IOT Solutions (Page 18)
- IOT Is More Than Just Connected to the Internet (Page 19)
- IOT Services (Page 22)
- Example IOT Solutions (Page 23)
- Sensor Networks (Page 23)
- Fleet Management (Page 24)
- Home Automation (Page 26)
- What Is IOT Data? (Page 27)
- IOT Predictions: Data Overload? (Page 32)
- Addressing IOT Devices (Page 32)
- Are There Enough Addresses Available? (Page 32)
- How Can You Find an IOT Device? (Page 32)
- IOT and Big Data (Page 35)
- IOT Security (Page 36)
- Common Security Threats (Page 39)
- Communication Protocols (Page 39)
- Privacy Policies (Page 40)
- Remote Maintenance (Page 40)
- Password Policies (Page 40)
- Physical Security (Page 41)
- Software and Firmware (Page 41)
- Securing IOT Solutions (Page 41)
- Securing Data Collectors (Page 43)
- Securing Data Aggregators (Page 43)
- Securing Actionable Devices (Page 43)
- Securing the Database Server (Page 43)
- Securing IOT Services (Page 44)
- Summary (Page 44)
- Chapter 2: Hardware for IOT Solutions (Page 45)
- Microcontrollers (Page 45)
- What Is an Arduino? (Page 46)
- Arduino Models (Page 47)
- Arduino Zero (Page 47)
- Arduino Yún (Page 48)
- Arduino Leonardo (Page 49)
- Arduino Due (Page 50)
- Arduino Mega 2560 (Page 51)
- Arduino Clones (Page 52)
- Sparkfun Redboard (Page 52)
- TinyCircuits TinyDuino (Page 53)
- SpikenzieLabs Sippino (Page 55)
- Spikenzie Labs Prototino (Page 57)
- Sparkfun ESP8266 WiFi Module (Page 58)
- Arduino Tutorial (Page 61)
- Learning Resources (Page 61)
- The Arduino IDE (Page 61)
- Project: Hardware “Hello, World!” (Page 64)
- Wiring the Circuit (Page 64)
- Writing the Sketch (Page 66)
- Compiling and Uploading (Page 67)
- Testing the Project (Page 67)
- Additional Arduino Hardware (Page 68)
- Arduino Ethernet Shield (Page 69)
- Arduino WiFi Shield 101 (Page 70)
- Arduino WiFi Shield (Page 71)
- Sparkfun WiFi Shield: ESP8266 (Page 72)
- Adafruit WiFi Shield (Page 73)
- Sparkfun CryptoShield (Page 74)
- Sparkfun MicroSD Shield (Page 76)
- XBee Modules (Page 76)
- Low-Powered Computing Platforms (Page 78)
- Arduino Hybrids (Page 79)
- pcDuino3B (Page 79)
- Intel Galileo Gen 2 (Page 81)
- Computer Boards (Page 82)
- BeagleBone Black (Page 83)
- Raspberry Pi 2 Model B (Page 84)
- Raspberry Pi B (Page 85)
- Intel Edison (with Sparkfun Blocks) (Page 86)
- Sensors (Page 88)
- Analog Sensors (Page 89)
- Digital Sensors (Page 89)
- Storing Sensor Data (Page 90)
- Examples of Sensors (Page 90)
- Computer Systems (Page 93)
- Summary (Page 94)
- Chapter 3: How IOT Data Is Stored (Page 95)
- Distributed IOT (Page 96)
- Data Collectors (Page 97)
- Data Collectors with Storage (Page 97)
- Actionable Device (Page 97)
- Data Aggregators (Page 97)
- Database Server (Page 98)
- Local On-Device Storage (Page 98)
- Local Storage on the Raspberry Pi (Page 99)
- Writing Data to Files (Page 99)
- Local Storage on the Arduino (Page 101)
- Nonvolatile Memory (Page 102)
- SD Card (Page 102)
- Passing the Buck to Aggregators (Page 106)
- Database Storage (Page 108)
- Benefits (Page 109)
- Techniques (Page 110)
- Considerations (Page 111)
- Distributed IOT Network Best Practices (Page 112)
- Node Placement (Page 112)
- Data Storage (Page 113)
- Presentation (Page 115)
- Summary (Page 115)
- Chapter 4: Data Transformation (Page 116)
- Making Sense of IOT Data (Page 117)
- What Is Being Observed? (Page 117)
- Is There Another Way to Make the Observation? (Page 117)
- How Often Do You Need to Record the Observation? (Page 118)
- What Type of Data Does the Sensor Produce? (Page 119)
- Are There Interpretations Needed for the Observation Data? (Page 119)
- What Level of Accuracy Do You Need? (Page 120)
- What Is the Lifetime of the Data? (Page 120)
- Annotation (Page 121)
- Recording the Sensor Name or Adding Notes (Page 122)
- Code Implementation (Page 122)
- Database Considerations (Page 124)
- Recording the Date and Time (Page 125)
- Using a Real-Time Clock Module (Page 126)
- Code Implementation (Page 127)
- Database Considerations (Page 130)
- Data Type Transformations (Page 131)
- Code Implementation (Page 134)
- Database Considerations (Page 137)
- Adding Derived or Calculated Data (Page 138)
- Code Implementation (Page 138)
- Database Considerations (Page 141)
- Derived and Calculated Columns Using a Trigger (Page 142)
- Derived and Calculated Columns Using a SELECT Statement (Page 143)
- Derived and Calculated Columns Using an INSERT Statement (Page 144)
- Data Interpretations (Page 145)
- Code Implementation (Page 146)
- Database Considerations (Page 147)
- Aggregation (Page 149)
- Data from Multiple Sensors (Page 149)
- Sensor-Driven Data (Page 149)
- Interval Driven Data (Page 151)
- Data from Multiple Nodes (Page 152)
- Aggregate Calculations (Page 154)
- Summary (Page 155)
- Chapter 5: MySQL Primer (Page 156)
- Getting Started (Page 156)
- How Do I Use MySQL? (Page 157)
- How to Get and Install MySQL (Page 159)
- How Data Is Stored and Retrieved (Page 172)
- How and Where MySQL Stores Data (Page 173)
- The MySQL Configuration File (Page 177)
- How to Start, Stop, and Restart MySQL on Windows (Page 178)
- Creating Users and Granting Access (Page 178)
- Common MySQL Commands and Concepts (Page 179)
- MySQL Commands (Page 179)
- Creating Databases and Tables (Page 180)
- Getting Results (Page 181)
- Adding Data (Page 184)
- Changing Data (Page 185)
- Removing Data (Page 186)
- MySQL Concepts (Page 186)
- Indexes (Page 186)
- Views (Page 187)
- Triggers (Page 187)
- Simple Joins (Page 188)
- Additional Advanced Concepts (Page 190)
- Planning Database Storage for IOT Data (Page 191)
- Example 1: Plant-Monitoring System (Page 191)
- Step 1: Describe the Data (Page 192)
- Step 2: Design the Database Objects (Page 192)
- Step 3: Design the Queries or Questions for the Database (Page 196)
- Example 1: A Simple Query (Page 196)
- Example 2: A Complex Query (Page 198)
- Step 4: Testing the Database (Page 200)
- Testing Example 1 (Page 202)
- Testing the Complex Query (Page 204)
- Recommendations and Best Practices (Page 206)
- Summary (Page 208)
- Chapter 6: Building Low-Cost MySQL Data Nodes (Page 209)
- Introducing the Raspberry Pi (Page 209)
- Noble Origins (Page 211)
- Models (Page 212)
- A Tour of the Board (Page 214)
- Required Accessories (Page 215)
- Recommended Accessories (Page 216)
- Where to Buy (Page 217)
- Raspberry Pi Tutorial (Page 220)
- Choosing a Boot Image (Operating System) (Page 220)
- Using NOOBS (Page 221)
- Installing Boot Image on a Micro SD Card (Page 225)
- Windows (Page 225)
- Mac OS X (Page 225)
- Linux (Page 226)
- Booting Up (Page 226)
- MySQL Installation and Setup (Page 229)
- Partitioning and Formatting the Drive (Page 230)
- Setting Up Automatic Drive Mounting (Page 232)
- Installing MySQL Server (Page 234)
- Installing MySQL (Page 234)
- Moving the Data Directory to the External Drive (Page 237)
- Other Platforms (Page 239)
- BeagleBone Black (Page 239)
- Installing MySQL (Page 240)
- Configuring the Hard Drive (Page 240)
- pcDuino (Page 240)
- Installing MySQL (Page 241)
- Configuring the Hard Drive (Page 241)
- Intel Galileo (Page 241)
- Installing MySQL (Page 242)
- Configuring the Hard Drive (Page 243)
- MySQL Clients: How to Connect and Save Data (Page 244)
- Introducing Connector/Arduino (Page 244)
- Installing Connector/Arduino (Page 246)
- Using Connector/Arduino (Page 248)
- Starting a New Sketch (Page 249)
- Include Files (Page 249)
- Preliminary Setup (Page 249)
- Connecting to a MySQL Server (Page 250)
- Running a Query (Page 251)
- Testing the Sketch (Page 251)
- Introducing Connector/Python (Page 256)
- Installing Connector/Python (Page 257)
- Installing on Desktop/Laptop Platforms (Page 257)
- Installing on Low-Cost Platforms (Page 258)
- Checking the Installation (Page 259)
- Using Connector/Python (Page 259)
- Summary (Page 263)
- Chapter 7: High Availability IOT Solutions (Page 264)
- What Is High Availability? (Page 264)
- High Availability Options for IOT Solutions with MySQL (Page 266)
- Recovery (Page 266)
- Redundancy (Page 267)
- Scaling (Page 268)
- Fault Tolerance (Page 268)
- High Availability Techniques (Page 269)
- Backup and Recovery (Page 269)
- The mysqldump Client (Page 270)
- The mysqlpump Client Utility (Page 272)
- MySQL Utilities Database Export and Import (Page 273)
- MySQL Enterprise Backup (Page 274)
- Physical File Copy (Page 275)
- Backup and Recovery with the Binary Log (Page 275)
- MySQL Replication Primer (Page 277)
- What Is Replication, and How Does It Work? (Page 277)
- How to Set Up Replication (Page 278)
- Preparing the Master (Page 278)
- Preparing the Slave (Page 279)
- Fault Tolerance in IOT Nodes (Page 283)
- Summary (Page 284)
- Chapter 8: Demonstration of High Availability Techniques (Page 285)
- MySQL Replication Techniques (Page 285)
- Transaction Processing (Page 286)
- Advanced Replication with Global Transaction Identifiers (Page 288)
- Switchover (Page 291)
- Failover (Page 292)
- Replication and Database Maintenance Tips (Page 294)
- Avoiding Errant Transactions (Page 294)
- Resolving Slave Errors (Page 294)
- Starting Replication with Existing Data (Page 296)
- Example: Scaling Applications (Page 297)
- Overview of the Design (Page 298)
- Write the Code (Page 299)
- Test the Sketch (Page 302)
- High Availability IOT Nodes (Page 303)
- Example: Redundant Data Collectors (Page 303)
- Overview of the Design (Page 303)
- Assemble the Hardware (Page 304)
- Write the Sketch (Page 306)
- Test the Sketch (Page 310)
- Example: Fault-Tolerant Data Collector (Page 312)
- Overview of the Design (Page 313)
- Assemble the Hardware (Page 313)
- Write the Sketch (Page 314)
- Test the Sketch (Page 321)
- Check the Requirements (Page 322)
- Summary (Page 322)
- Index (Page 323)