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

PDF
Smart home automation
PDF
Not another *$#@ app: How to avoid IoT fatigue
PDF
Oakter - Smart Home
PPTX
How i built my own irrigation controller
PPT
Scripting Things - Creating the Internet of Things with Perl
PDF
Logging into the Network!
PPTX
TeksunLab Pegasus Program 2014
PPTX
Home automation using google assistant ppt
Smart home automation
Not another *$#@ app: How to avoid IoT fatigue
Oakter - Smart Home
How i built my own irrigation controller
Scripting Things - Creating the Internet of Things with Perl
Logging into the Network!
TeksunLab Pegasus Program 2014
Home automation using google assistant ppt

Similar to Hackbright Workshop (20)

PDF
Api workshop
PPTX
Electric Imp - Hackathon Intro
PDF
How To Electrocute Yourself using the Internet
PDF
YOTG Munich - Simon Mang - SixReasons - Hardware prototyping – Sketching with...
PDF
Arduino: interruptor de encendido controlado por Internet
PDF
Building Droids with JavaScript
PPTX
IoT13: Electric Imp showcase
PDF
Home automation with javascript
KEY
Android and Arduio mixed with Breakout js
PPTX
Introduction to Node MCU
PDF
Innovation Showcase: Hugo Fiennes, CEO/Co-Founder, Electric Imp
PDF
Survey_Paper
PDF
Prototyping products for the Internet of Things using JavaScript
PPTX
Bare metal Javascript & GPIO programming in Linux
PPTX
Getting Started with the NodeMCU- Getting started with Internet of Things (Io...
PPTX
IoT applications With Arduino coding and real life examples
PDF
Programming the Real World: Javascript for Makers
PDF
manual Internet of ThingsArduino_IOTArdu
PPTX
IoT Application Development
PDF
UI Beyond the Browser - Software for Hardware Projects
Api workshop
Electric Imp - Hackathon Intro
How To Electrocute Yourself using the Internet
YOTG Munich - Simon Mang - SixReasons - Hardware prototyping – Sketching with...
Arduino: interruptor de encendido controlado por Internet
Building Droids with JavaScript
IoT13: Electric Imp showcase
Home automation with javascript
Android and Arduio mixed with Breakout js
Introduction to Node MCU
Innovation Showcase: Hugo Fiennes, CEO/Co-Founder, Electric Imp
Survey_Paper
Prototyping products for the Internet of Things using JavaScript
Bare metal Javascript & GPIO programming in Linux
Getting Started with the NodeMCU- Getting started with Internet of Things (Io...
IoT applications With Arduino coding and real life examples
Programming the Real World: Javascript for Makers
manual Internet of ThingsArduino_IOTArdu
IoT Application Development
UI Beyond the Browser - Software for Hardware Projects

Recently uploaded (20)

PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Approach and Philosophy of On baking technology
PDF
Empathic Computing: Creating Shared Understanding
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Electronic commerce courselecture one. Pdf
PPT
Teaching material agriculture food technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Big Data Technologies - Introduction.pptx
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Cloud computing and distributed systems.
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Diabetes mellitus diagnosis method based random forest with bat algorithm
NewMind AI Monthly Chronicles - July 2025
Approach and Philosophy of On baking technology
Empathic Computing: Creating Shared Understanding
Mobile App Security Testing_ A Comprehensive Guide.pdf
Understanding_Digital_Forensics_Presentation.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectral efficient network and resource selection model in 5G networks
Electronic commerce courselecture one. Pdf
Teaching material agriculture food technology
Building Integrated photovoltaic BIPV_UPV.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Advanced methodologies resolving dimensionality complications for autism neur...
Machine learning based COVID-19 study performance prediction
Big Data Technologies - Introduction.pptx
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Cloud computing and distributed systems.

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

  • #2: 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)
  • #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: 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
  • #5: 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)
  • #6: 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
  • #7: 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)
  • #8: 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
  • #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: 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
  • #12: 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
  • #13: 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
  • #14: 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
  • #15: 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
  • #16: Click Save Changes
  • #17: 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
  • #18: 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
  • #19: 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
  • #20: 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.
  • #21: Make sure button is connected to GND and PIN1 Buttons connected to VIN and PIN1 could potentially damage the imp
  • #22: 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
  • #23: 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
  • #24: Point out where the Agent URL can be found If they can’t find it, they likely need to select a device (slide 12)
  • #25: 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
  • #26: 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
  • #27: 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
  • #28: Similar to previous example, but data flow is going the other way
  • #29: 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)
  • #30: Same data flow as slide (22) but with the device -> agent code as well
  • #31: 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
  • #32: 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