PYTHON AND IOT: From Chips and Bits to Data Science. Jeff Fischer Data-Ken Research https://data-ken.org Sunnyvale, California, USA

Similar documents
SEP Bright Pi v1.0 Assembly Instructions

Internet of Things - IoT Training

Alice EduPad Board. User s Guide Version /11/2017

Greens Technologys is a leading Classroom & Online platform providing live instructor-led interactive

Just a T.A.D. (Traffic Analysis Drone)

Internet of Things at Bohunt School (Wokingham) Plant moisture sensing system

Chunghwa Telecom Laboratories. CHT IoT Smart Platform and Ameba. Two-Way Communication Application. Case Instruction Document

ADD AN AUDIO MESSAGE TO YOUR PRODUCT WITH THIS RECORD & PLAYBACK KIT

Korea Electronics Technology Institute

T : Internet Technologies for Mobile Computing

Weekly report: January 25 - Februry 8, 2018

Internet of Things (IoT) and Big Data DOAG 2016 Big Data Days

Application of Internet of Things for Equipment Maintenance in Manufacturing System

ISSN (PRINT): , (ONLINE): , VOLUME-5, ISSUE-4,

Distributed by Pycom Ltd. Copyright 2016 by Pycom Ltd. All rights reserved. No part of this document may be reproduced, distributed, or transmitted

DEVELOPING IN THE IOT SPACE

Alice EduPad for Tiva or MSP432 TI ARM Launchpad. User s Guide Version /23/2017

The Micropython Microcontroller

IoT using Python & Cloud Computing

Designing and Implementing an Affordable and Accessible Smart Home Based on Internet of Things

Building the ChronoDot Calendar Reminder

Bridging Legacy Systems & the Internet of Things. Matt Newton Director of Technical Marketing OPTO 22

Arduino LED Matrix Control. Controlling lots of LEDs

IoT Software Platforms

Introduction. The Clock Hardware. A Unique LED Clock Article by Craig A. Lindley

An Introduction to The Internet of Things

Bill of Materials: Super Simple Water Level Control PART NO

Dust Sensor using GP Y

Linux+Zephyr: IoT made easy

This module senses temperature and humidity. Output: Temperature and humidity display on serial monitor.

INTRODUCTION OF INTERNET OF THING TECHNOLOGY BASED ON PROTOTYPE

The Haply Development Kit

Arduino Lesson 3. RGB LEDs

EasyAir Philips Field Apps User Manual. May 2018

Be a part of the circuit. Brick'R'knowledge. Set overview.

General FAQs Status as of: 22/10/2018


8 PIN PIC PROGRAMMABLE BOARD (DEVELOPMENT BOARD & PROJECT BOARD)

Laboratory 7. Lab 7. Digital Circuits - Logic and Latching

Internet of Things Conceptual Frameworks and Architecture

Edge Connector Light Level Detector

MAGICLiteSeries-16CH1080pDVRSystem-SupportsEX- SDI/HD-SDI/960H/Analog/IP

16CH 1080p HD-SDI Security MAGIC Lite Series DVR System - Auto detects Analog/960H/HD-SDI

UAV Ultimate Atari Video A7800

EE123 Digital Signal Processing

Architecture of Industrial IoT

Keysight Technologies U3801A/02A IoT Fundamentals Applied Courseware. Data Sheet

Lesson Sequence: S4A (Scratch for Arduino)

Inc. Internet of Things. Outcome Economy. to Win in the. How Your Company Can Use the

uresearch GRAVITECH.US GRAVITECH GROUP Copyright 2007 MicroResearch GRAVITECH GROUP

Module 4: Traffic Signal Design Lesson 1: Traffic Signal (Arduino) Control System Laboratory Exercise Grade 6-8

Introduction 1. Green status LED, controlled by output signal ST. Sounder, controlled by output signal Q6. Push switch on input D6

Laptop Lcd To Vga Interface Circuit Diagram

Hardware Guide BrightSign, LLC Version:.1 Los Gatos, CA, USA. MODELS: XD Product Line

Data Acquisition Using LabVIEW

AIFA TECHNOLOGY CORP.

Take advantage of these channels in your marketing!

Schematic Analysis of P10 16x32 RGB LED Panel 3 in 1 DIP Type Dual (Dual In-Line Package) on Trafficlight Revolution

Log-detector. Sweeper setup using oscilloscope as XY display

3 rd International Conference on Smart and Sustainable Technologies SpliTech2018 June 26-29, 2018

Prime Num Generator - Maker Faire 2014

9/23/2014. Andrew Costin, Tom Syster, Ryan Cramer Advisor: Professor Hack Instructor: Professor Lin May 5 th, 2014

Digital (5hz to 500 Khz) Frequency-Meter

Arduino Hacking Village THOTCON 0x9

MotionPro. Team 2. Delphine Mweze, Elizabeth Cole, Jinbang Fu, May Oo. Advisor: Professor Bardin. Midway Design Review

Model- based design of energy- efficient applications for IoT systems

Experiment (6) 2- to 4 Decoder. Figure 8.1 Block Diagram of 2-to-4 Decoder 0 X X

Total solder points: 123 Difficulty level: beginner 1. advanced AUDIO ANALYZER K8098. audio gea Give your. . high-tech ILLUSTRATED ASSEMBLY MANUAL

IOT BASED ENERGY METER RATING

Light your home smarter

Integrating Device Connectivity in IoT & Embedded devices

VERIFICATION TEST PLAN

Building Intelligent Edge Solutions with Microsoft IoT

Internet of Things hiotron Custom IOT Solution Development

Hello and welcome to this presentation of the STM32L4 Analog-to-Digital Converter block. It will cover the main features of this block, which is used

Snail Fence InteleCell Deployment Guide

Bezirk. Things plus Cloud does not equal IoT. Saturn 2016, San Diego. IoT that tastes better. IoT by default

MAKE AN RGB CONTROL KNOB.

FOSS PLATFORM FOR CLOUD BASED IOT SOLUTIONS

MAX2660/MAX2661/MAX2663/MAX2671 Evaluation Kits

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

LED Array Tutorial. This guide explains how to set up and operate the LED arrays that can be used for your. Internal Structure of LED Array

Chapter 4. It Began with a Dripping Faucet

Internet of Things. a practical component-oriented approach. What is IoT (wikipedia):

ECE 4220 Real Time Embedded Systems Final Project Spectrum Analyzer

... A Pseudo-Statistical Approach to Commercial Boundary Detection. Prasanna V Rangarajan Dept of Electrical Engineering Columbia University

Running leds from Pokeys

TP7001 Range Electronic 7 Day Programmable Room Thermostat. Danfoss Heating. Installation Guide

MAGICUSeries-4CH1080pDVRSystem4Kouput- SupportsEX-SDI/HD-SDI/HD-TVI/A-HD/960H/Analog/ IP

Getting Started with Launchpad and Grove Starter Kit. Franklin Cooper University Marketing Manager

User Manual Wireless HD AV Transmitter & Receiver Kit

This Unit may form part of a National Qualification Group Award or may be offered on a free standing basis.

Home Monitoring System Using RP Device

New Technologies: 4G/LTE, IOTs & OTTS WORKSHOP

SWITCH: Microcontroller Touch-switch Design & Test (Part 2)

MAGICQLSeries-4CH1080pDVRSystem-SupportsEX- SDI/HD-SDI/960H/Analog/IP

[1-H1-3-17/1-P3-2-19] AWS IoT. Takashi Koyanagawa SA: IoT/AI Solution Builder. 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Jazz Melody Generation and Recognition

WiPry 5x User Manual. 2.4 & 5 GHz Wireless Troubleshooting Dual Band Spectrum Analyzer

MAGICUSeries-32CHDVR4Koutput-SupportsEX-SDI/ HD-SDI/HD-TVI/A-HD/960H/Analog/IP

Transcription:

PYTHON AND IOT: From Chips and Bits to Data Science Jeff Fischer Data-Ken Research jeff@data-ken.org https://data-ken.org Sunnyvale, California, USA BayPiggies October 2016

Agenda 2 Project overview Hardware Data capture Data analysis Player Parting thoughts

Project Motivation 3 If out of town for the weekend, don t want to leave the house dark Timers are flakey and predictable Would like a self-contained solution Avoid security issues with cloud solutions Wouldn t be cool to use machine learning?

Lighting Replay Application 4 Lux Sensors Smart Lights Data Capture Analysis and Machine Learning Player Application

Lighting Replay Application: Capture 5 Front Bedroom Sensor Node Raspberry Pi (Dining Room) Lux Sensor ESP8266 Lux Sensor Back Bedroom Sensor Node MQTT Data Capture App Lux Sensor ESP8266 Flat Files

Lighting Replay Application: Analysis 6 Raspberry Pi (Dining Room) Flat Files HMM definitions file copy Laptop Jupyter Notebook

Lighting Replay Application: Replay 7 Front Room Smart Light Raspberry Pi (Dining Room) HMM definitions Player Script HTTP ZigBee WiFi Router and Switch Philips Hue Bridge Back Room Smart Light

8 Hardware

Recommended Hardware Supplier: 9 Adafruit Focused on the hobbyist Plenty of documentation and examples Breakout boards make it easy to work with peripheral ICs

Recommended Tools 10 Solder Soldering iron Breadboards (get ½ and full sized) Wire (#24 or #26) Breadboarding wires Wire strippers Wire cutters Pliers Multimeter

Raspberry Pi 11 Two full-sized breadboards TSL2591 lux sensor breakout board LED Resistor Breakout cable Pi Cobbler Plus Raspberry Pi 2

ESP8266 12 ½ Size breadboard Lithium Ion Polymer Battery 3.7v 350mAh MicroUSB to USB cable TSL2591 lux sensor breakout board Adafruit Feather HUZZAH ESP8266 breakout board

13 Data Capture

Lighting Replay Application: Capture 14 Front Bedroom Sensor Node Raspberry Pi (Dining Room) Lux Sensor ESP8266 Lux Sensor Back Bedroom Sensor Node MQTT Data Capture App Lux Sensor ESP8266 Flat Files

AntEvents 15 Python3 library for processing IoT event streams Built on Python 3.4 s asyncio module Port to Micropython, which runs on the ESP8266 Key library features: Push-style streams of events Assemble elements into a DAG n Fine-grained pub/sub model: an element is a publisher, a subscriber, or both n Special support for pipelines of stateful filters n Elements can be proxies for external systems Event-driven scheduling, with separate threads for blocking elements https://github.com/mpi-sws-rse/antevents-python

Simple AntEvents Example 16 Sample a light sensor every two seconds and turn on an LED if the average of the last 5 samples exceeds a threshold lux = LuxSensor() Lux.map(lambda e: e.val).running_avg(5) \.map(lambda v: v > threshold).gpiopinout() scheduler.schedule_recurring(lux, 2.0) Lux Sensor Map Running Average Map LED

ESP8266 Code 17 from antevents import Scheduler from tsl2591 import Tsl2591 from mqtt_writer import MQTTWriter from wifi import wifi_connect import os https://github.com/jfischer/micropython-tsl2591 # Params to set WIFI_SID= WIFI_PW= SENSOR_ID="front-room" BROKER='192.168.11.153' wifi_connect(wifi_sid, WIFI_PW) sensor = Tsl2591() writer = MQTTWriter(SENSOR_ID, BROKER, 1883, 'remote-sensors') sched = Scheduler() sched.schedule_sensor(sensor, SENSOR_ID, 60, writer) sched.run_forever() Sample at 60 second intervals The MQTT writer subscribes to events from The lux sensor. See https://github.com/mpi-sws-rse/antevents-examples/blob/master/lighting_replay_app/capture/esp8266_main.py

Raspberry Pi Code 18 MQTT Adapter Map to UTF8 Parse JSON Map to events Dispatch CSV File Writer (front room) CSV File Writer (back room) Lux Sensor CSV File Writer (dining room) https://github.com/mpi-sws-rse/antevents-examples/blob/master/lighting_replay_app/capture/sensor_capture.py

Raspberry Pi Code: Threading Model 19 MQTT Adapter Map to UTF8 Parse JSON Map to events Dispatch Separate Thread CSV File Writer (front room) CSV File Writer (back room) Lux Sensor CSV File Writer (dining room) Separate Thread Main Thread https://github.com/mpi-sws-rse/antevents-examples/blob/master/lighting_replay_app/capture/sensor_capture.py

20 Data Analysis

Lighting Replay Application: Analysis 21 Raspberry Pi (Dining Room) Flat Files HMM definitions file copy Laptop Jupyter Notebook

Steps in Data Analysis 22 1. Read and preprocess data files 2. Convert to discrete levels using K-means clustering 3. Map to on-off values 4. Train Hidden Markov Models (HMMs) on data 5. Validate predictions 6. Export HMM definitions for player https://github.com/mpi-sws-rse/antevents-examples/tree/master/lighting_replay_app/analysis

Read and Process CSV Files (AntEvents running in a Jupyter Notebook) 23 Pandas Writer (raw series) Pandas Writer (smoothed series) CSV File Reader Fill in missing times Sliding Mean Round values Output Event Count Capture NaN Indexes reader.fill_in_missing_times()\.passthrough(raw_series_writer)\.transduce(sensorslidingmeanpassnans(5)).select(round_event_val).passthrough(smoothed_series_writer)\.passthrough(capture_nan_indexes).output_count()

Raw Sensor Data: Entire Set 24 Front room Vacation!

Raw Sensor Data: Entire Set 25 Front room Back room Dining room

Raw Sensor Data: Last Day Only 26 Front room Data gaps

Raw Sensor Data: Last Day Only 27 Front room Back room Dining room

Data Processing: Raw Data 28 Front room, last day

Data Processing: Smoothed Data 29 Front room, last day

Data Processing: K-Means Clustering 30 Front room, last day

Data Processing: Mapping to on-off values 31 Front room, last day

Hidden Markov Models (HMMs) 32 In a Markov process, the probability distribution of future states is determined only by the current state, not on the sequence of events that preceded it. In a HMM, the states are not visible to the observer, only the outputs ( emissions ). In a machine learning context, we are given a sequence of emissions and a number of states. We want to infer the state machine. The hmmlearn library will do this for us. https://github.com/hmmlearn/hmmlearn Example Markov process (from Wikipedia)

Slicing Data into Time-based Zones 33 Sunrise Max(sunset+60m, 9:30 pm) 30 Minutes before sunset 0 1 2 3 0

HMM Training and Prediction Process 34 1. Build a list of sample subsequences for each zone n Drop the timestamps n Beak into separate sequences at zone boundaries and NaNs 2. Guess a number of states (e.g. 5) 3. For each zone, create an HMM and call fit() with the subsequences 4. For each zone of a given day: n Run the associated HMM to generate N samples for an N minute zone duration n Associated a computed timestamp with each sample

HMM Predicted Data 35 Front room, one day predicted data Front room, one week predicted data

36 Replaying the Lights

Lighting Replay Application: Replay 37 Front Room Smart Light Raspberry Pi (Dining Room) HMM definitions Player Script HTTP ZigBee WiFi Router and Switch Philips Hue Bridge Back Room Smart Light

Logic of the Replay Script 38 Use phue library to control lights Reuse time zone logic and HMMs from analysis Pseudo-code: Initial testing of lights while True: compute predicted values for rest of day organize predictions into a time-sorted list of on/off events for each event: sleep until event time send control message for event wait until next day https://github.com/mpi-sws-rse/antevents-examples/blob/master/lighting_replay_app/player/lux_player.py

39 Parting Thoughts

Acknowledgements 40 Rupak Majumdar, Max Planck Institute for Software Systems Co-designer of AntEvents Sze Ning Chng, Cambridge University First user of AntEvents while interning at MPI Dmitrill Lourovitski, BayPiggies Gave me advice regarding machine learning techniques

Lessons Learned 41 An end-to-end project like this is a great way to learn a new area Applying machine learning to a problem can be very much a trial-and-error process Visualization is key to understanding/debugging these systems The Python ecosystem is great for both runtime IoT and offline analytics

Future Work 42 Gather more data and re-try other machine learning algorithms Integrate AntEvents with visualization (looking at Bokeh) What are the right abstractions for IoT analytics?

ESP8266 Demo 43

44 Thank You Questions? More information Website and blog: https://data-ken.org AntEvents: https://github.com/mpi-sws-rse/antevents-python Examples (including lighting replay app): https://github.com/mpi-sws-rse/antevents-examples

45 Additional Details

Raspberry Pi 2: Wiring Detail 46

Raspberry Pi 2: Wiring Diagram 47 SDA SCL GPIO 0 Resistor 10k Anode (long lead) LED Cathode (short lead) 3.3V GND

ESP8266: Wiring Diagram 48 SDA SCL 3V GND

Third-party Resources 49 Adafruit TSL2591 Lux Sensor tutorial https://learn.adafruit.com/adafruit-tsl2591 Adafruit ESP8266 tutorial https://learn.adafruit.com/adafruit-feather-huzzah-esp8266 LED tutorials n n n https://learn.adafruit.com/all-about-leds/overview https://thepihut.com/blogs/raspberry-pi-tutorials/27968772- turning-on-an-led-with-your-raspberry-pis-gpio-pins https://projects.drogon.net/raspberry-pi/gpio-examples/tuxcrossing/gpio-examples-1-a-single-led/ Micropython Getting Started on ESP8266 https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/ intro.html

Machine Learning: Other Approaches 50 Tried Feature data Time of day, zone, on-off value N-samples back Also tried the number of samples since the last value change made results worse Algorithms tried K-nearest neighbors Logistic Regression Decision Tree (classifier, probabilistic classifier, regressor) Pure probability approach Build a probability distribution based on length of time at current value worked fairly well Conclusion: need more sample data