zvika markfeld
TRANSCRIPT
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
W H E N W E B H I T M I C R O C O N T R O L L E R S
Making IOT
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Agenda
A Bit About Me
Intro
Basics
Usage Scenarios
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Ex Dev
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
עבודה, ובכל זאת
לקוחות לחוצים ולוחצים
פרוייקטים משעממים
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
תוכן ולא טכניקה
משחקיות ולא משחק סכום אפס
יצירתיות ויצירה ולא רק יצרנות
זמן למצוא עץ לחטוב, הגרזן מושחז דיו
שמעתי לראשונה את השם ארדואינו 2010בסביבות
חיפשתי קצת יותר
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
תחילתה של התמכרות מופלאה
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Arduino!
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
דורי אדר -פרוייקטי אינטראקציה
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Experience Design
Digi-Physi
“Garage Studio”
!בשלה העת לסטודיו
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Maker
Geekcon, Arduino, industrial design
Invention, Creation, Imagination
Experience engineer
Creative Coder
Makathon Organizer
Robotic Educator
Project Mentor
…
ForReal Team
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
G E T T I N G S T A R T E D W I T H A R D U I N O
IOT Intro
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Internet
Computers, connected through Internet protocols
Display or manipulate documents
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Internet of Things (IoT)
Computers, sensors and actuators connected through Internet protocols
Measure or manipulate physical properties
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
IoT Reference Model
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
IOT Basics
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Ardu-XXX low performance microcontrollers IO: GPIOs Arduino, PIC, Basic Stamp, …
ARM-based high performance microcontrollers IO: GPIOs Teensy, Arduino ZERO, …
XXX-Berry Trimmed down Linux Distros IO: usb, hdmi, ... Raspie, Hackberry, ..
High Rollers Full Linux Players IO: whatever Intel Galileo & Edison, Google (Android/Brillo), Samsung ARTIK
Hardware
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
IoT hardware has a pretty basic interface to the real world GPIO: read/write boolean voltage levels
Analog input: sensors
Fast switching
Interaction Measure:
read sensor value from input pin
Process: translate data models
Manipulate: write actuator value to output pin
Hardware
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Ethernet (built-in or shield), plug it in anywhere
Wi-Fi (module), configured once per location
3G (module), configured once, easy to use
Bluetooth/BLE (module), via 3G/Wi-Fi of phone
ZigBee (module), via ZigBee gateway
USB (built-in), via desktop computer
Connectivity
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Energy
Wall socket, Power over Ethernet (w/ adapters), batteries (direct or Minty Boost USB charger), LiPo batteries (also shields), solar panels, …
Low power: lets hardware sleep to save energy
Future: new battery technologies, ultra low power hardware, energy harvesting
Note: Moore’s law does not apply to batteries
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Usage Scenarios
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Accelerometer were only the beginning
Remember “Smart Alarm Clocks”?
QS
Physical - accelerometers
Cognitive: EEG sensors
Behavioral Correlation Analyzers?
Heuristical/Neural
[[User Story]]
Data Aggregation, Harvesting & Presentation
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Xively
Plot.ly
Data Aggregation, Harvesting & Presentation
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Pachube / Xively
The Pachube (now Xively) service lets you store, monitor and share sensor data in open formats PUT /v2/feeds/<your feed id>.csv HTTP/1.1\r\n
Host: api.xively.com\r\n
X-ApiKey: <your API key>\r\n
Content-Length: <content length>\r\n
\r\n
<sensor name>,<sensor value>
GET /v2/feeds/<feed id>.json HTTP/1.1\r\n
Host and X-ApiKey as above…\r\n\r\n
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
#include <Ethernet.h>
#include <SPI.h>
#include "plotly_streaming_ethernet.h"
// Sign up to plotly here: https://plot.ly
// View your API key and stream tokens here: https://plot.ly/settings
#define nTraces 2
// View your tokens here: https://plot.ly/settings
// Supply as many tokens as data traces
// e.g. if you want to ploty A0 and A1 vs time, supply two tokens
char *tokens[nTraces] = {"a1b1c1d1e1f1", "a2b2c2d2e2f2"};
// arguments: username, api key, streaming token, filename
plotly graph = plotly("zvika.markfeld", “********", tokens, "analog", nTraces);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte my_ip[] = { 199, 168, 222, 18 }; // google will tell you: "public ip address"
void startEthernet(){
Serial.println("... Initializing ethernet");
if(Ethernet.begin(mac) == 0){
Serial.println("... Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, my_ip);
}
Serial.println("... Done initializing ethernet");
delay(1000);
}
Plot.ly
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
startEthernet();
graph.fileopt = "overwrite"; // See the "Usage" section in https://github.com/plotly/arduino-api for details
bool success;
success = graph.init();
if(!success) {
Serial.println("Error! ");
while(true);
}
graph.openStream();
}
unsigned long x;
int y;
void loop() {
graph.plot(millis(), analogRead(A0), tokens[0]);
graph.plot(millis(), analogRead(A1), tokens[1]);
delay(50);
}
Plot.ly
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
We people LOVE remote control!
Realtime Home Automation
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Firmata
S4A, IOIO, NodeJS/Johnny5
Teleduino
Web / JS / Bookmark Scripting
Realtime Home Automation
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Teleduino
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Game Changer
Super low cost (~3 USD)
LUA compliant
Arduino compliant
Complete Solution
Forkable: NodeMCU
ESP8266
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
wifi.setmode(wifi.STATION)
wifi.sta.config("YOUR_NETWORK_NAME","YOUR_NETWORK_PASSWORD")
print(wifi.sta.getip())
led1 = 3
led2 = 4
gpio.mode(led1, gpio.OUTPUT)
gpio.mode(led2, gpio.OUTPUT)
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(client,request)
local buf = "";
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
if(method == nil)then
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
end
local _GET = {}
if (vars ~= nil)then
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
_GET[k] = v
end
end
LUA
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
uf = buf.."<h1> ESP8266 Web Server</h1>";
buf = buf.."<p>GPIO0 <a href=\"?pin=ON1\"><button>ON</button></a> <a
href=\"?pin=OFF1\"><button>OFF</button></a></p>";
buf = buf.."<p>GPIO2 <a href=\"?pin=ON2\"><button>ON</button></a> <a
href=\"?pin=OFF2\"><button>OFF</button></a></p>";
local _on,_off = "",""
if(_GET.pin == "ON1")then
gpio.write(led1, gpio.HIGH);
elseif(_GET.pin == "OFF1")then
gpio.write(led1, gpio.LOW);
elseif(_GET.pin == "ON2")then
gpio.write(led2, gpio.HIGH);
elseif(_GET.pin == "OFF2")then
gpio.write(led2, gpio.LOW);
end
client:send(buf);
client:close();
collectgarbage();
end)
end)
LUA
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
OAuth2 / SSL / …
Temboo: Gmail, FB, Twitter
IFTTT / Mashups
Web2.0 Invocations / Callbacks
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
/* Setup shield-specific #include statements */
#include <SPI.h>
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <Temboo.h>
#include "TembooAccount.h" // Contains Temboo account information
byte ethernetMACAddress[] = ETHERNET_SHIELD_MAC;
EthernetClient client;
int numRuns = 1; // Execution count, so this doesn't run forever
int maxRuns = 10; // Maximum number of times the Choreo should be executed
Arduino Mail Sender
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
void setup() {
Serial.begin(9600);
// For debugging, wait until the serial console is connected
delay(4000);
while(!Serial);
Serial.print("DHCP:");
if (Ethernet.begin(ethernetMACAddress) == 0) {
Serial.println("FAIL");
while(true);
}
Serial.println("OK");
delay(5000);
Serial.println("Setup complete.\n");
}
Arduino Mail Sender
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
void loop() {
if (numRuns <= maxRuns) {
Serial.println("Running SendMessage - Run #" + String(numRuns++));
TembooChoreo SendMessageChoreo(client);
// Invoke the Temboo client
SendMessageChoreo.begin();
// Set Temboo account credentials
SendMessageChoreo.setAccountName(TEMBOO_ACCOUNT);
SendMessageChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
SendMessageChoreo.setAppKey(TEMBOO_APP_KEY);
// Set Choreo inputs
String ClientIDValue = "zakakflemvrid";
SendMessageChoreo.addInput("ClientID", ClientIDValue);
Arduino Mail Sender
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
// Identify the Choreo to run
SendMessageChoreo.setChoreo("/Library/Google/Gmailv2/Messages/SendMessage");
// Run the Choreo; when results are available, print them to serial
SendMessageChoreo.run();
while(SendMessageChoreo.available()) {
char c = SendMessageChoreo.read();
Serial.print(c);
}
SendMessageChoreo.close();
}
Serial.println("\nWaiting...\n"); delay(30000);
}
Arduino Mail Sender
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
23andMe
Amazon
AuthorizeNet
Basecamp
Bitly
Box
Bugzilla
Clicky
CloudMine
ConstantContact
CorpWatch
DailyMed
DataGov
Delicious
Disqus
DonorsChoose
Dropbox
DuckDuckGo
Temboo Chreos
Dwolla
eBay
EnviroFacts
Factual
FedEx
FedSpending
FilesAnywhere
Fitbit
Flickr
Foursquare
Genability
GitHub
GovTrack
Highrise
InfluenceExplorer
Instapaper
KhanAcademy
Kiva
Klout
LastFm
LittleSis
MailChimp
Microsoft
Mixpanel
MySQL
Nexmo
NOAA
NPR
NYTimes
OneLogin
PagerDuty
Parse
PayPal
PostgreSQL
RunKeeper
Salesforce
SchoolFinder
SendGrid
Socrata
Stripe
SunlightLabs
Tumblr
Twilio
Uber
UnlockPlaces
USPS
Withings
WolframAlpha
Wordnik
Xively
Yahoo
Yelp
YouTube
Zendesk
Zillow
Zoho
Utilities
Labs
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Add physical dimension to your social feed
Send E-Mail alerts for home security system
Read newspapers and decide whether it’s going to be a good day…
Order an Uber cab whenever leaving the house
Physical Trader
Choreo Example Scenarios
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
NodeMCU / Spark Core
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Connect to the wireless network
print(wifi.sta.getip())
--nil
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","password")
print(wifi.sta.getip())
--192.168.18.110
Arduino like IO access
pin = 1
gpio.mode(pin,gpio.OUTPUT)
gpio.write(pin,gpio.HIGH)
gpio.mode(pin,gpio.INPUT)
print(gpio.read(pin))
NodeMCU
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
HTTP Client
-- A simple http client
conn=net.createConnection(net.TCP, false)
conn:on("receive", function(conn, pl) print(pl) end)
conn:connect(80,"121.41.33.127")
conn:send("GET / HTTP/1.1\r\nHost: www.nodemcu.com\r\n"
.."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
HTTP Server
-- a simple http server
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive",function(conn,payload)
print(payload)
conn:send("<h1> Hello, NodeMCU.</h1>")
end)
end)
HTTP
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Mash-ups
A mash-up combines two or more Web services
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Mash-ups
Once devices have APIs, they become scriptable
Logic moves out of device, into the Cloud
e.g. Web-enabled LED + Yahoo Weather API = ambient weather notification
IoT enables physical mash-ups of things
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Online Physical Chess?
Custom Apps
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Advanced Data Analysis
Mobile “Things”
Future
ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Thank You!