SlideShare a Scribd company logo
Building Connected Things
with Electric Imp
These slides are licensed under the MIT License
http://opensource.org/licenses/MIT
SSID: impdemo
PW: electric
Matt Haines | Tom Byrne
matt@electricimp.com | tom@electricimp.com
@beardedinventor | @tlbyrn
Agenda
The Internet of Things
• What is the Internet of Things
• What does the Internet of Things space look like
• What goes into an Internet of Things application
• Overview of the Electric Imp platform
Workshop – Your first imp project
• Getting your first imp online
• Digital I/O
• Building a basic HTTPS request handler
• Making HTTP requests
The Internet of Things (2025)
50B
Connected
Devices
$6.2T
Economic
Impact
McKinsey Global Institute, 2013
Internet of Things Verticals
What Goes Into an IoT Application
• Hardware
• Microcontrollers, radios, sensors, actuators, etc
• Firmware
• Device logic, drivers, network stack, etc
• Server Code
• Heavy processing, external device API, data storage, etc
• External Web Services
• Weather APIs, Twitter, Twilio, Gmail/email, IFTTT, etc
• App / Website / Etc
• User interface, OAuth, etc
• Areas of knowledge required:
• Electrical Engineering, embedded software, security, backend/server
development, web development, database admin, app development, …
The Electric Imp Platform
Connectivity Infrastructure
In-house
Great products
Focus on the
core business
Platform
Server Infrastructure
In-house
Great products
Focus on the
core business
Platform
The Electric Imp Platform – Overview
The Electric Imp Platform - Devices
• 32-Bit ARM Cortex M3 processor
• 802.11 b/g/n WiFi
• Open WiFi, WEP, WPA, WPA2
• 80 KB* code space (device – 'firmware')
• 6/12 Configurable GPIO Pins
• Digital In/Out
• Analog In
• 12 bit DAC (Analog Out)
• PWM Out
• I2C, UART, SPI
* This value changes a little bit each release (the imp originally only had about 40 KB of code space)
The Electric Imp Platform - Agents
• Micro-server than can act on behalf of a device
• Runs on the Electric Imp Servers
• 1 MB code space
• 1MB RAM
• Allows you to do things that you typically can’t on an embedded processor
• Process incoming HTTP requests (create APIs for your device)
• Make outgoing HTTP requests (interact with external APIs)
• Persist small amounts of data
Let’s get started
BlinkUp - Getting Online
• Create an Electric Imp Account: https://ide.electricimp.com
• Download the Electric Imp mobile app:
• Android: play.google.com/store/apps/details?id=com.electricimp.electricimp
• iPhone: itunes.apple.com/us/app/electric-imp
• Sign into the app with your Electric Imp Account
• Enter WiFi credentials:
• SSID: impdemo
• PW: electric
• Power up your imp
• The imp’s internal LED must be blinking before continuing to the next step
• Click BlinkUp in the mobile app
• Hold screen of phone against blinking light of imp until BlinkUp is complete
• Your device should now be blinking green (online)*
* Your imp will stop blinking after 1 minute to save power (it is still powered on)
BlinkUp Example
* Your imp will stop blinking after 1 minute to save power (it is still powered on)
Creating a New Model
Creating a New Model
Creating a New Model
Creating a New Model
Digital Output - Circuit
Digital Output - Device Code
// Device Code
led <- hardware.pin9;
led.configure(DIGITAL_OUT);
state <- 0;
function blink() {
imp.wakeup(1.0, blink);
state = 1 – state;
led.write(state);
}
blink();
Blocking Loops are Bad!
// Device Code
// NOTE: THIS IS BAD CODE:
led <- hardware.pin9;
led.configure(DIGITAL_OUT);
function loop() {
local state = 0;
while (1) {
led.write(state);
state = 1 – state;
imp.sleep(1.0);
}
}
loop();
Digital Input – Circuit
Digital Input - Device Code
// Device Code:
led <- hardware.pin9;
led.configure(DIGITAL_OUT);
button <- hardware.pin1;
function onButton() {
local state = button.read();
led.write(state);
}
button.configure(DIGITAL_IN_PULLUP, onButton);
Event Driven Programming and Callbacks
• Squirrel is an Event Driven Language
• Behaviour is defined by events and callbacks
• An event is a pre-programmed thing that can happen:
• The timeout on an imp.wakeup ends
• The state of a DIGITAL_IN pin changes
• A message is passed from the device to the agent or vice versa
• An agent receives an incoming HTTP request
• A callback is a function bound to a event:
• imp.wakeup(5, blink);
• Tells the imp to run the function called blink in 5 seconds
• button.configure(DIGITAL_IN, onButton);
• Tells the imp to run the function called onButton when the state of the pin
assigned to button changes
HTTP Handlers
• Each device has an agent – a tiny micro servers that act on behalf of their device
• Each agent has a unique URL associated with it (see below)
• http.onrequest binds a callback to the 'received incoming HTTP Request' event
HTTP Handler – Agent Code
// Agent Code:
function httpHandler(request, response) {
if ("state" in request.query) {
local state = request.query["state"];
device.send("led", state);
}
response.send(200, "OK");
}
http.onrequest(httpHandler);
HTTP Handler – Device Code
// Device Code:
led <- hardware.pin9;
led.configure(DIGITAL_OUT);
function ledHandler(data) {
if (data == "0") {
server.log("LED OFF")
led.write(0);
} else {
server.log("LED ON");
led.write(1);
}
}
agent.on("led", ledHandler);
Passing Messages
Making HTTP Requests – Device Code
// Device Code:
led <- hardware.pin9;
led.configure(DIGITAL_OUT);
function ledHandler(data) {
if (data == "0") {
server.log("LED OFF")
led.write(0);
} else {
server.log("LED ON");
led.write(1);
}
}
agent.on("led", ledHandler);
Making HTTP Requests – Agent Code
// Add to the bottom of your agent code:
const URL = "https://agent.electricimp.com/RO5HOrveo4I1";
function buttonPressHandler(state) {
local url = URL + "?state=" + state;
local request = http.get(url);
request.sendasync(function(resp) {
server.log(resp.statuscode + " - " + resp.body);
});
}
device.on("buttonPress", buttonPressHandler)
Passing Messages
Other activities
• Device:
• Try to control your LED with PWM
• electricimp.com/docs/examples/pwm-led
• Bonus: Try to control the brightness with a web request
• Create multiple “states” for your LED (on, off, blinking slow, blinking fast)
• Make the button switch between states
• Agent:
• Grab the Wunderground API code
• github.com/electricimp/reference/tree/master/webservices/wunderground
• Grab weather every 5 mins and change the brightness of the LED based on
the temperature
• Bonus: Create an Umbrella reminder to keep by your front door:
• Every morning the agent checks the weather
• If there’s > 50% chance of rain, LED turns on
• Grab the Twitter API
• github.com/electricimp/reference/tree/master/webservices/twitter
• Make your imp tweet whenever the button is pressed
• Bonus: Control the state of the LED based on a Twitter stream
• Turn the light on whenever something is tweeted with a tracked tag
• Click the button to clear the light
Electric Imp Resource
Getting Started Guide electricimp.com/docs/getting-started
API Documentation electricimp.com/docs/api
Squirrel Documentation electricimp.com/docs/squirrel
Reference Code github.com/electricimp/reference
Community Blog community.electricimp.com
Forums forums.electricimp.com

More Related Content

Similar to Hackbright Workshop

[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...
[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...
[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...
Hackito Ergo Sum
 
Building the Internet of Things with Thingsquare and Contiki - day 1, part 2
Building the Internet of Things with Thingsquare and Contiki - day 1, part 2Building the Internet of Things with Thingsquare and Contiki - day 1, part 2
Building the Internet of Things with Thingsquare and Contiki - day 1, part 2
Adam Dunkels
 
LG Developer Event 2013 in San Francisco
LG Developer Event 2013 in San FranciscoLG Developer Event 2013 in San Francisco
LG Developer Event 2013 in San Francisco
LGDeveloper
 
The Internet of Fails - Mark Stanislav, Senior Security Consultant, Rapid7
The Internet of Fails - Mark Stanislav, Senior Security Consultant, Rapid7The Internet of Fails - Mark Stanislav, Senior Security Consultant, Rapid7
The Internet of Fails - Mark Stanislav, Senior Security Consultant, Rapid7
Rapid7
 
Internet of Things 101 - Part II
Internet of Things 101 - Part IIInternet of Things 101 - Part II
Internet of Things 101 - Part II
Yoonseok Hur
 
DIY Technology for the Internet of Things
DIY Technology for the Internet of ThingsDIY Technology for the Internet of Things
DIY Technology for the Internet of Things
srmonk
 
Android and Arduio mixed with Breakout js
Android and Arduio mixed with Breakout jsAndroid and Arduio mixed with Breakout js
Android and Arduio mixed with Breakout js
musart Park
 
Arduino blueooth
Arduino blueoothArduino blueooth
Arduino blueooth
Nitish Kumar
 
Node red for Raspberry Pi
Node red for Raspberry PiNode red for Raspberry Pi
Node red for Raspberry Pi
Anshu Pandey
 
Android Things, Alexey Rybakov, Technical Evangelist, DataArt
Android Things, Alexey Rybakov, Technical Evangelist, DataArtAndroid Things, Alexey Rybakov, Technical Evangelist, DataArt
Android Things, Alexey Rybakov, Technical Evangelist, DataArt
Alina Vilk
 
CSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoT
CSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoTCSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoT
CSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoT
CanSecWest
 
IAB3948 Wiring the internet of things with Node-RED
IAB3948 Wiring the internet of things with Node-REDIAB3948 Wiring the internet of things with Node-RED
IAB3948 Wiring the internet of things with Node-RED
PeterNiblett
 
Building the Internet of Things with Thingsquare and Contiki - day 1, part 3
Building the Internet of Things with Thingsquare and Contiki - day 1, part 3Building the Internet of Things with Thingsquare and Contiki - day 1, part 3
Building the Internet of Things with Thingsquare and Contiki - day 1, part 3
Adam Dunkels
 
Can we build an Azure IoT controlled device in less than 40 minutes that cost...
Can we build an Azure IoT controlled device in less than 40 minutes that cost...Can we build an Azure IoT controlled device in less than 40 minutes that cost...
Can we build an Azure IoT controlled device in less than 40 minutes that cost...
Codemotion Tel Aviv
 
Uvais
Uvais Uvais
Introduction to Node MCU
Introduction to Node MCUIntroduction to Node MCU
Introduction to Node MCU
Amarjeetsingh Thakur
 
Gobot Meets IoT : Using the Go Programming Language to Control The “Things” A...
Gobot Meets IoT : Using the Go Programming Language to Control The “Things” A...Gobot Meets IoT : Using the Go Programming Language to Control The “Things” A...
Gobot Meets IoT : Using the Go Programming Language to Control The “Things” A...
Justin Grammens
 
Windows 10 IoT-Core to Azure IoT Suite
Windows 10 IoT-Core to Azure IoT SuiteWindows 10 IoT-Core to Azure IoT Suite
Windows 10 IoT-Core to Azure IoT Suite
David Jones
 
Connecting Hardware to Flex (360MAX)
Connecting Hardware to Flex (360MAX)Connecting Hardware to Flex (360MAX)
Connecting Hardware to Flex (360MAX)
Justin Mclean
 
Getting Started with the Internet of Things - Allianz Hackrisk Hackathon 29/...
Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/...Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/...
Getting Started with the Internet of Things - Allianz Hackrisk Hackathon 29/...
The Internet of Things Methodology
 

Similar to Hackbright Workshop (20)

[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...
[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...
[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...
 
Building the Internet of Things with Thingsquare and Contiki - day 1, part 2
Building the Internet of Things with Thingsquare and Contiki - day 1, part 2Building the Internet of Things with Thingsquare and Contiki - day 1, part 2
Building the Internet of Things with Thingsquare and Contiki - day 1, part 2
 
LG Developer Event 2013 in San Francisco
LG Developer Event 2013 in San FranciscoLG Developer Event 2013 in San Francisco
LG Developer Event 2013 in San Francisco
 
The Internet of Fails - Mark Stanislav, Senior Security Consultant, Rapid7
The Internet of Fails - Mark Stanislav, Senior Security Consultant, Rapid7The Internet of Fails - Mark Stanislav, Senior Security Consultant, Rapid7
The Internet of Fails - Mark Stanislav, Senior Security Consultant, Rapid7
 
Internet of Things 101 - Part II
Internet of Things 101 - Part IIInternet of Things 101 - Part II
Internet of Things 101 - Part II
 
DIY Technology for the Internet of Things
DIY Technology for the Internet of ThingsDIY Technology for the Internet of Things
DIY Technology for the Internet of Things
 
Android and Arduio mixed with Breakout js
Android and Arduio mixed with Breakout jsAndroid and Arduio mixed with Breakout js
Android and Arduio mixed with Breakout js
 
Arduino blueooth
Arduino blueoothArduino blueooth
Arduino blueooth
 
Node red for Raspberry Pi
Node red for Raspberry PiNode red for Raspberry Pi
Node red for Raspberry Pi
 
Android Things, Alexey Rybakov, Technical Evangelist, DataArt
Android Things, Alexey Rybakov, Technical Evangelist, DataArtAndroid Things, Alexey Rybakov, Technical Evangelist, DataArt
Android Things, Alexey Rybakov, Technical Evangelist, DataArt
 
CSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoT
CSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoTCSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoT
CSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoT
 
IAB3948 Wiring the internet of things with Node-RED
IAB3948 Wiring the internet of things with Node-REDIAB3948 Wiring the internet of things with Node-RED
IAB3948 Wiring the internet of things with Node-RED
 
Building the Internet of Things with Thingsquare and Contiki - day 1, part 3
Building the Internet of Things with Thingsquare and Contiki - day 1, part 3Building the Internet of Things with Thingsquare and Contiki - day 1, part 3
Building the Internet of Things with Thingsquare and Contiki - day 1, part 3
 
Can we build an Azure IoT controlled device in less than 40 minutes that cost...
Can we build an Azure IoT controlled device in less than 40 minutes that cost...Can we build an Azure IoT controlled device in less than 40 minutes that cost...
Can we build an Azure IoT controlled device in less than 40 minutes that cost...
 
Uvais
Uvais Uvais
Uvais
 
Introduction to Node MCU
Introduction to Node MCUIntroduction to Node MCU
Introduction to Node MCU
 
Gobot Meets IoT : Using the Go Programming Language to Control The “Things” A...
Gobot Meets IoT : Using the Go Programming Language to Control The “Things” A...Gobot Meets IoT : Using the Go Programming Language to Control The “Things” A...
Gobot Meets IoT : Using the Go Programming Language to Control The “Things” A...
 
Windows 10 IoT-Core to Azure IoT Suite
Windows 10 IoT-Core to Azure IoT SuiteWindows 10 IoT-Core to Azure IoT Suite
Windows 10 IoT-Core to Azure IoT Suite
 
Connecting Hardware to Flex (360MAX)
Connecting Hardware to Flex (360MAX)Connecting Hardware to Flex (360MAX)
Connecting Hardware to Flex (360MAX)
 
Getting Started with the Internet of Things - Allianz Hackrisk Hackathon 29/...
Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/...Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/...
Getting Started with the Internet of Things - Allianz Hackrisk Hackathon 29/...
 

More from Matt Haines

Best Practices for Design Hardware APIs
Best Practices for Design Hardware APIsBest Practices for Design Hardware APIs
Best Practices for Design Hardware APIs
Matt Haines
 
Robots conf microcontroller and iot survey
Robots conf   microcontroller and iot surveyRobots conf   microcontroller and iot survey
Robots conf microcontroller and iot survey
Matt Haines
 
Your Device Needs an API
Your Device Needs an APIYour Device Needs an API
Your Device Needs an API
Matt Haines
 
Electric Imp - Hackathon Intro
Electric Imp - Hackathon IntroElectric Imp - Hackathon Intro
Electric Imp - Hackathon Intro
Matt Haines
 
electric imp Intro
electric imp Introelectric imp Intro
electric imp Intro
Matt Haines
 

More from Matt Haines (6)

Best Practices for Design Hardware APIs
Best Practices for Design Hardware APIsBest Practices for Design Hardware APIs
Best Practices for Design Hardware APIs
 
Robots conf microcontroller and iot survey
Robots conf   microcontroller and iot surveyRobots conf   microcontroller and iot survey
Robots conf microcontroller and iot survey
 
Your Device Needs an API
Your Device Needs an APIYour Device Needs an API
Your Device Needs an API
 
Api workshop
Api workshopApi workshop
Api workshop
 
Electric Imp - Hackathon Intro
Electric Imp - Hackathon IntroElectric Imp - Hackathon Intro
Electric Imp - Hackathon Intro
 
electric imp Intro
electric imp Introelectric imp Intro
electric imp Intro
 

Recently uploaded

A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 

Recently uploaded (20)

A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 

Hackbright Workshop

  • 1. Building Connected Things with Electric Imp These slides are licensed under the MIT License http://opensource.org/licenses/MIT SSID: impdemo PW: electric Matt Haines | Tom Byrne matt@electricimp.com | tom@electricimp.com @beardedinventor | @tlbyrn
  • 2. Agenda The Internet of Things • What is the Internet of Things • What does the Internet of Things space look like • What goes into an Internet of Things application • Overview of the Electric Imp platform Workshop – Your first imp project • Getting your first imp online • Digital I/O • Building a basic HTTPS request handler • Making HTTP requests
  • 3. The Internet of Things (2025) 50B Connected Devices $6.2T Economic Impact McKinsey Global Institute, 2013
  • 4. Internet of Things Verticals
  • 5. What Goes Into an IoT Application • Hardware • Microcontrollers, radios, sensors, actuators, etc • Firmware • Device logic, drivers, network stack, etc • Server Code • Heavy processing, external device API, data storage, etc • External Web Services • Weather APIs, Twitter, Twilio, Gmail/email, IFTTT, etc • App / Website / Etc • User interface, OAuth, etc • Areas of knowledge required: • Electrical Engineering, embedded software, security, backend/server development, web development, database admin, app development, …
  • 6. The Electric Imp Platform Connectivity Infrastructure In-house Great products Focus on the core business Platform Server Infrastructure In-house Great products Focus on the core business Platform
  • 7. The Electric Imp Platform – Overview
  • 8. The Electric Imp Platform - Devices • 32-Bit ARM Cortex M3 processor • 802.11 b/g/n WiFi • Open WiFi, WEP, WPA, WPA2 • 80 KB* code space (device – 'firmware') • 6/12 Configurable GPIO Pins • Digital In/Out • Analog In • 12 bit DAC (Analog Out) • PWM Out • I2C, UART, SPI * This value changes a little bit each release (the imp originally only had about 40 KB of code space)
  • 9. The Electric Imp Platform - Agents • Micro-server than can act on behalf of a device • Runs on the Electric Imp Servers • 1 MB code space • 1MB RAM • Allows you to do things that you typically can’t on an embedded processor • Process incoming HTTP requests (create APIs for your device) • Make outgoing HTTP requests (interact with external APIs) • Persist small amounts of data
  • 11. BlinkUp - Getting Online • Create an Electric Imp Account: https://ide.electricimp.com • Download the Electric Imp mobile app: • Android: play.google.com/store/apps/details?id=com.electricimp.electricimp • iPhone: itunes.apple.com/us/app/electric-imp • Sign into the app with your Electric Imp Account • Enter WiFi credentials: • SSID: impdemo • PW: electric • Power up your imp • The imp’s internal LED must be blinking before continuing to the next step • Click BlinkUp in the mobile app • Hold screen of phone against blinking light of imp until BlinkUp is complete • Your device should now be blinking green (online)* * Your imp will stop blinking after 1 minute to save power (it is still powered on)
  • 12. BlinkUp Example * Your imp will stop blinking after 1 minute to save power (it is still powered on)
  • 13. Creating a New Model
  • 14. Creating a New Model
  • 15. Creating a New Model
  • 16. Creating a New Model
  • 17. Digital Output - Circuit
  • 18. Digital Output - Device Code // Device Code led <- hardware.pin9; led.configure(DIGITAL_OUT); state <- 0; function blink() { imp.wakeup(1.0, blink); state = 1 – state; led.write(state); } blink();
  • 19. Blocking Loops are Bad! // Device Code // NOTE: THIS IS BAD CODE: led <- hardware.pin9; led.configure(DIGITAL_OUT); function loop() { local state = 0; while (1) { led.write(state); state = 1 – state; imp.sleep(1.0); } } loop();
  • 20. Digital Input – Circuit
  • 21. Digital Input - Device Code // Device Code: led <- hardware.pin9; led.configure(DIGITAL_OUT); button <- hardware.pin1; function onButton() { local state = button.read(); led.write(state); } button.configure(DIGITAL_IN_PULLUP, onButton);
  • 22. Event Driven Programming and Callbacks • Squirrel is an Event Driven Language • Behaviour is defined by events and callbacks • An event is a pre-programmed thing that can happen: • The timeout on an imp.wakeup ends • The state of a DIGITAL_IN pin changes • A message is passed from the device to the agent or vice versa • An agent receives an incoming HTTP request • A callback is a function bound to a event: • imp.wakeup(5, blink); • Tells the imp to run the function called blink in 5 seconds • button.configure(DIGITAL_IN, onButton); • Tells the imp to run the function called onButton when the state of the pin assigned to button changes
  • 23. HTTP Handlers • Each device has an agent – a tiny micro servers that act on behalf of their device • Each agent has a unique URL associated with it (see below) • http.onrequest binds a callback to the 'received incoming HTTP Request' event
  • 24. HTTP Handler – Agent Code // Agent Code: function httpHandler(request, response) { if ("state" in request.query) { local state = request.query["state"]; device.send("led", state); } response.send(200, "OK"); } http.onrequest(httpHandler);
  • 25. HTTP Handler – Device Code // Device Code: led <- hardware.pin9; led.configure(DIGITAL_OUT); function ledHandler(data) { if (data == "0") { server.log("LED OFF") led.write(0); } else { server.log("LED ON"); led.write(1); } } agent.on("led", ledHandler);
  • 27. Making HTTP Requests – Device Code // Device Code: led <- hardware.pin9; led.configure(DIGITAL_OUT); function ledHandler(data) { if (data == "0") { server.log("LED OFF") led.write(0); } else { server.log("LED ON"); led.write(1); } } agent.on("led", ledHandler);
  • 28. Making HTTP Requests – Agent Code // Add to the bottom of your agent code: const URL = "https://agent.electricimp.com/RO5HOrveo4I1"; function buttonPressHandler(state) { local url = URL + "?state=" + state; local request = http.get(url); request.sendasync(function(resp) { server.log(resp.statuscode + " - " + resp.body); }); } device.on("buttonPress", buttonPressHandler)
  • 30. Other activities • Device: • Try to control your LED with PWM • electricimp.com/docs/examples/pwm-led • Bonus: Try to control the brightness with a web request • Create multiple “states” for your LED (on, off, blinking slow, blinking fast) • Make the button switch between states • Agent: • Grab the Wunderground API code • github.com/electricimp/reference/tree/master/webservices/wunderground • Grab weather every 5 mins and change the brightness of the LED based on the temperature • Bonus: Create an Umbrella reminder to keep by your front door: • Every morning the agent checks the weather • If there’s > 50% chance of rain, LED turns on • Grab the Twitter API • github.com/electricimp/reference/tree/master/webservices/twitter • Make your imp tweet whenever the button is pressed • Bonus: Control the state of the LED based on a Twitter stream • Turn the light on whenever something is tweeted with a tracked tag • Click the button to clear the light
  • 31. Electric Imp Resource Getting Started Guide electricimp.com/docs/getting-started API Documentation electricimp.com/docs/api Squirrel Documentation electricimp.com/docs/squirrel Reference Code github.com/electricimp/reference Community Blog community.electricimp.com Forums forums.electricimp.com

Editor's Notes

  1. Welcome everyone Introduce yourself Ensure everyone is on WiFi Share a link to the slides or provide a printed copy as a handout (printed copies means participants will need to type in code, instead of copy paste)
  2. Quickly go over what they will be learning tonight The Internet of Things Startup space slide / discussion is very optional, and should really only be used when it will provide interest / value to the workshop (i.e. – university students) Go over the main goals of the course Understand how to get your imps online Understand basic event driven programming and message passing in the Electric Imp platform Understand how to write basic APIs for your hardware Understand how to make basic web requests from an agent
  3. Quickly go over what they will be learning tonight The Internet of Things Startup space slide / discussion is very optional, and should really only be used when it will provide interest / value to the workshop (i.e. – university students) Go over the main goals of the course Understand how to get your imps online Understand basic event driven programming and message passing in the Electric Imp platform Understand how to write basic APIs for your hardware Understand how to make basic web requests from an agent
  4. Talk about some of the various verticals in the IoT Space (note this is far from complete) Talk about how some of the products work, and the various components that go into it - Nest is a good example.. - Hardware (the Nest), Software (running on the Nest, your phone, the Nest Servers), security between everything so someone else can’t set your thermostat, see when you’re home, etc - Revenue from Nest comes from selling units, but also potentially from power companies for cycling AC in a way that prevents peaks while people are away from home - Toymail is a good Electric Imp Example - Little mailbox shapped toys - Allows parents/grandparents to send voice mails to kits without phones - Hardware, software (on the device, your phone, Toymails servers, imp servers), security (you don’t want strangers sending voicemails to your kids, you don’t want strangers knowing when your kids are playing messages (ie – they’re home and their parents may not be). - Revenue from selling toys, also in-app purchase to send more than X messages per month (on-going revenue stream)
  5. Can talk about this in the context of the startups discussed previously, and how those applications have each of the following This is designed to illustrate the complexities of building an Internet of Things application and why platforms are a good thing Talk a little bit about how each layer fits into an IoT application and the user’s experience, and that each layer requires specialized knowledge
  6. Comparing Electric Imp to AWS – depending on the audience this slide may or may not make sense Focus on the things you’re good at – designing products, making Things Use platforms to solve things you are not good at / don’t want to focus on in product (security, connectivity, etc)
  7. There are four core components of the Electric Imp platform we’re going to look at today The imp / impOS This is the hardware that will execute your device code More details on the next slide The imp cloud & Open API Each imp has a tiny micro servo that runs in our cloud (i.e. on our servers) that you can program to do just about anything The imp cloud acts as a proxy for your device to do things embeeded devices traditionally can’t do (make and process web requests, encode/decode json, persist data, etc) BlinkUp BlinkUp is the process we use to get the imp online More information shortly The imp IDE (part of the imp cloud) This is where you write code for your device and your agent, view logs, and push updates to developer devices
  8. Imp001 (SD Card) has 6 configurable GPIO pins Imp002 (solder down module) has 12 configurable GPIO pins Imp003 (8mm x 10mm Murata module) has 24 configurable GPIO pins, but is not well suited for Makers, so we won’t talk about that Firmware is not true firmware, but rather interpreted code running in a VM on the device. Agents are embedded code running in a VM on the Electric Imp servers
  9. Imp001 (SD Card) has 6 configurable GPIO pins Imp002 (solder down module) has 12 configurable GPIO pins Imp003 (8mm x 10mm Murata module) has 24 configurable GPIO pins, but is not well suited for Makers, so we won’t talk about that Firmware is not true firmware, but rather interpreted code running in a VM on the device. Agents are embedded code running in a VM on the Electric Imp servers
  10. This is typically one of the longest and most difficult steps with a large group of people. Ensure that everyone is online before continuing.. If you don’t there will be people left behind who can’t do anything past this step. BlinkUp flashes the screen at 60 hz Please advise the room that if anyone is photosensitive or epileptic they should look away during BlinkUp If their phones audio is turned on, there are audio cues to indicate when BlinkUp starts and finishes BlinkUp is the process Electric Imp uses to get imps online Each imp card has a light sensor + led that is used in the BlinkUp process BlinkUp flashes the screen very quickly, which the light sensor reads as 1’s (bright) and 0’s (dark) Once BlinkUp is complete, the imp attempts to connect to the WiFi – and once it connects it talks to our servers and registers itself with your account If you want to change the account the imp is connected to, you can BlinkUp the device with new credentials The imp retains it’s network information even when powered off When the imp is powered on, it checks to see if it has network information, and if it does it tries to connect See course FAQ for BlinkUp troubleshooting
  11. This is typically one of the longest and most difficult steps with a large group of people. Ensure that everyone is online before continuing.. If you don’t there will be people left behind who can’t do anything past this step. BlinkUp flashes the screen at 60 hz Please advise the room that if anyone is photosensitive or epileptic they should look away during BlinkUp If their phones audio is turned on, there are audio cues to indicate when BlinkUp starts and finishes BlinkUp is the process Electric Imp uses to get imps online Each imp card has a light sensor + led that is used in the BlinkUp process BlinkUp flashes the screen very quickly, which the light sensor reads as 1’s (bright) and 0’s (dark) Once BlinkUp is complete, the imp attempts to connect to the WiFi – and once it connects it talks to our servers and registers itself with your account If you want to change the account the imp is connected to, you can BlinkUp the device with new credentials The imp retains it’s network information even when powered off When the imp is powered on, it checks to see if it has network information, and if it does it tries to connect See course FAQ for BlinkUp troubleshooting
  12. If people don’t see their devices, they may need to refresh The arrow points to the device we just blinked up - Click on the gear icon beside it
  13. Enter a model name - A model is a pair of device and agent code that tied together We’re naming our model Electric Imp Workshop 1 – you can call yours whatever you want Hit enter after you’ve entered a name
  14. Click Save Changes
  15. Select your device - A model can have multiple devices associated with it - Each device has it’s own agent We need to select what device we want to communicate with, view logs for, etc
  16. Make sure to point out that LEDs have a “right way” and a “wrong way” and that the longer leg of the LED must be connected to the PIN9 side
  17. Things to point out: <- global variable Configure hardware.pin9 as a DIGITAL_OUT – it’s either on (1) or off (0) state = current state of the LED Functions are blocks of code we can programmatically call imp.wakeup schedules a function to run in a certain amount of time.. - In this case we’re telling the imp to run blink function again in 1 second Need to call blink() once to get things started
  18. Have participants run this code Their device should disconnect after 30 seconds or a minute, and will require a power cycle to get it back online Explain the single thread of execution - imp has lots of things to do.. Running your code is only 1 of them - Infinite loops steal the thread of execution and don’t allow anything else to happen - one of the background tasks the imp does is manage it’s wifi connection + connection to the server - if you steal the thread of execution, it can’t do that, so it looks disconnected to the imp servers.
  19. Make sure button is connected to GND and PIN1 Buttons connected to VIN and PIN1 could potentially damage the imp
  20. Things to point out local makes a local variable - if you try and use “state” outside of function onButton, it won’t work We configure button as a DIGITAL_IN_PULLUP - this means that when the button is not pressed, it will be 1, and when the button is pressed, it will be 0 Configuring a DIGITAL_IN allows you to pass an optional second parameter of a callback function - This function gets called whenever the state changes - more info on next slide
  21. Explain how event driven languages differ from non-event driven languages (like Arduino’s processing) Explain the power of event driven processing - When there is nothing to do, we can spin down clocks, etc - You don’t need to check variables 100 times a second (the OS manages all of that for you) We’ll see a few more examples of event driven programming + callbacks throughout the rest of the class
  22. Point out where the Agent URL can be found If they can’t find it, they likely need to select a device (slide 12)
  23. Explain what query parameters are, how we can check to see if a specific query parameter was included, and how to access it Make sure to point out that we’re doing no validation here, which means someone could pass in state=pineapple if they wanted to resp.send returns a response back to whoever made the request – it is VERY important that every incoming request send a response back i.e. make sure you don’t have code paths that don’t send a response
  24. agent.on catches a message from the agent the parameter for ledHandler comes from the device.send in the previous slide Next slide explains flow better
  25. Describe how basic message passing between the agent and device works device.send(“messageName”, data) is caught by agent.on(“messageName”, callback) - The callback MUST have 1 parameter - The data from device.send will be the parameter passed into the callback It’s a lot easier to explain flow of data with this slide than the previous two code slids
  26. Similar to previous example, but data flow is going the other way
  27. Talk about request verbs (GET, PUT, POST, etc) We’re making a get since it’s the simplest request Agents can make any kind of request Talk about sync vs async requests This code example also introduces inline functions (lambda functions)
  28. Same data flow as slide (22) but with the device -> agent code as well
  29. If people finish early they can try these They should have all of the required hardware The exercises get increasingly difficult as you go down the list
  30. Getting Started Guide – essentially what we just went through Also has a “Next Steps” section, which is worth looking at API Documentation – complete Electric Imp API spec Squirrel Standard Library – complete docs for Squirrel standard library Reference Code – great place to find classes for various web services and hardware components Community blog – Technical articles, and community contributed projects and blog posts Forums – The place to ask questions about the Electric Imp platform, and building connected devices