1. 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
2. ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Agenda
A Bit About Me
Intro
Basics
Usage Scenarios
3. ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Ex
Dev
4. ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
זאת ובכל,עבודה
ולוחצים לחוצים לקוחות
משעממים פרוייקטים
13. ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
14. ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
15. 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
16. ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Internet
Computers, connected through Internet protocols
Display or manipulate documents
17. 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
18. ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
IoT Reference Model
19. ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
IOT Basics
20. 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
21. 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
22. 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
23. 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
24. ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Usage Scenarios
25. 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
26. ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Xively
Plot.ly
Data Aggregation, Harvesting &
Presentation
27. 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.1rn
Host: api.xively.comrn
X-ApiKey: <your API key>rn
Content-Length: <content length>rn
rn
<sensor name>,<sensor value>
GET /v2/feeds/<feed id>.json HTTP/1.1rn
Host and X-ApiKey as above…rnrn
28. 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
29. 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
30. ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
We people LOVE remote control!
Realtime Home Automation
31. 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
32. ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Teleduino
33. 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
34. 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
37. 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
38. 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
39. 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
40. 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
42. 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
43. ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
NodeMCU / Spark Core
44. 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
45. 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.1rnHost: www.nodemcu.comrn"
.."Connection: keep-alivernAccept: */*rnrn")
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
46. ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Mash-ups
A mash-up combines two or more Web services
47. 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
48. ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Online Physical Chess?
Custom Apps
49. ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Advanced Data Analysis
Mobile “Things”
Future
50. ForReal Team 2014-15 | All rights reserved | www.forrealteam.com | learn.forrealteam.com
Thank You!