Programming The Internet of Things
Programming The Internet of Things
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Agenda
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Agenda
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Personal
Computing
Internet
Mobile
Computing
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Basically
Things
Devices with embedded
computers
Often without displays
Reading physical sensors
Controlling physical actuators
Limited power, memory,
compute
on the Internet.
Communicating globally
Variety of networking protocols
Interface to existing
infrastructure
Autonomous operation modes
Coordinated operation modes
Part of a system
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Lighting systems
Home security
Security
Delivery management
Maintenance (wearable)
Automotive monitoring
Point of Sale
Inventory tracking
Home maintenance
Precision agriculture
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Endpoint
Endpoint
Gateway
Wi-Fi*
LTE
Optimization Notice
Wired
Analysis
(Server)
Gateway
Human
Interface
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Good documentation
Both online and in book form, although to date mostly focused on web services
11
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Developer View
Servers
Interface
Devices
Cloud
Services
HTML5
Remote debug
Smart
Things
Node.js
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
14
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
NPM package
Remote
debug
fetching
Remote
execution and
debugging
15
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Agenda
16
Optimization Notice
Internet of Things
Set up the Thing (45m)
Build the Thing
Program the Thing
Network the Thing
Connect the Thing
Conclusion
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
- Start by copying folder from USB sticks being passed around to your desktop
- Then look in Course/Install directory specific to your OS
Summary: install drivers for the Edison on your computer, update its
operating system and software, set up a development tool (the Intel XDK
IoT Edition) specific to Node.js on the Edison.
Network: SSID is Solid; no password
17
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Agenda
18
Optimization Notice
Internet of Things
Set up the Thing
Build the Thing (10m)
Program the Thing
Network the Thing
Connect the Thing
Conclusion
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Hardware Kit
19
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
20
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Hardware Assembly
Light sensor on A0
Rotation sensor on A1
7-15V power connected
TWO micro USB cables to
computer
USB selection switch toward
micro USB host port
21
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Agenda
22
Optimization Notice
Internet of Things
Set up the Thing
Build the Thing
Program the Thing (30+10m)
Network the Thing
Connect the Thing
Conclusion
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Introduction to JavaScript*
C-like syntax, but ; are optional.
Strings:
'this is a string'
"so is this"
Declaring a variable:
var my_variable;
Points to note:
- Types are dynamic
- All numbers are floats
- Scope is function, not block
23
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
I2C: Two-wire (clock and data) halfduplex serial interface using a shared
bus. Devices on the bus have fixed
address and a set of registers that
can be read or written. Each device
has its own registers and interface
specification. Speed:100KHz and
400KHz.
SPI: 3 or 4-wire (clock, Tx and Rx
data, chip select) full-duplex serial
interface. Higher performance than
I2C (up to 25MHz) but more complex
wiring.
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
I2C: Two-wire (clock and data) halfduplex serial interface using a shared
bus. Devices on the bus have fixed
address and a set of registers that
can be read or written. Each device
has its own registers and interface
specification. Speed:100KHz and
400KHz.
SPI: 3 or 4-wire (clock, Tx and Rx
data, chip select) full-duplex serial
interface. Higher performance than
I2C (up to 25MHz) but more complex
wiring.
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Third Party
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Third Party
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
MRAA Setup
28
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
29
Optimization Notice
Do something periodically
Read state of button
If the button is pressed
Read the knob state and
write it to the LED
Repeat every 0.1s (100ms)
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
30
Optimization Notice
Do something periodically
Read state of button
If the button is pressed
Read the knob state and
write it to the LED
Repeat every 0.1s (100ms)
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
31
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Assignment 1: Solution
setInterval(function() {
var push = button.read();
if (push) {
led.write(
knob.readFloat()
);
} else {
led.write( 0 );
}
}, 100); // every 0.1s (100ms)
32
Optimization Notice
Do something periodically
Read state of button
If the button is pressed
Read the knob state and write it to
the LED
Otherwise
Turn off the light
Repeat every 0.1s (100ms)
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
33
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Assignment 2: Solution
var light_state = 0;
Do something periodically
Read state of button
If the button is pressed
Toggle the light power state
setInterval(function() {
var push = button.read()
if (push && !last_push) {
light_state = !light_state;
}
last_push = push;
if (light_state) {
led.write( knob.readFloat() );
} else {
led.write( 0 );
}
Optimization Notice
Otherwise
Turn off the light
Repeat every 0.1s (100ms)
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
light_state = !light_state;
}
last_push = push;
if (light_state) {
led.write( knob.readFloat() );
} else {
led.write( 0 );
}
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Assignment 3: Solution
var ambient = new mraa.Aio(0);
var light_state = 0;
if (light_state) {
led.write( knob.readFloat() * ambient.readFloat() );
} else {
led.write( 0 );
}
36
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
37
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Agenda
38
Optimization Notice
Internet of Things
Set up the Thing
Build the Thing
Program the Thing
Network the Thing (50+25m)
Connect the Thing
Conclusion
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Modules:
net: TCP sockets
http: web protocols
socket.io/shoe: websockets
dnode: remote async function invocation
mqtt: status and configuration
39
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
40
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
42
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
System Architecture
http request
Interface Client
(e.g., Browser)
43
Optimization Notice
Smart Thing
dnode
dnodeAPI
APIconnection
connection
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
On device:
npm install g browserify
first time only
cd /node_app_slot/web/js
browserify client.js o gen/bundle.js
On host (in web/js/gen directory of XDK project):
scp [email protected]:/node_app_slot/web/js/gen/bundle.js bundle.js
45
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
function set_light_state(state) {
Define helper function to
if (state) {
manage light images.
console.log("turning light on");
light_button.attr("src","images/on.jpg");
} else {
console.log("turning light off");
light_button.attr("src","images/off.jpg");
}
}
46
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
51
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Same as previous A3
solution.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
55
setInterval(function() {
A slight change here.
var push = button.read();
Can you spot it?
if (push && !last_push) {
light_state = !light_state;
if (notify_light) {
notify_light(light_state);
}
}
last_push = push;
if (light_state) {
led.write( knob.readFloat() * ambient.readFloat() );
} else {
led.write( 0 );
}
}, 100);
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
56
setInterval(function() {
Call any non-null notifier
var push = button.read();
callback when light state
if (push && !last_push) {
changes.
light_state = !light_state;
if (notify_light) {
notify_light(light_state);
}
}
last_push = push;
if (light_state) {
led.write( knob.readFloat() * ambient.readFloat() );
} else {
led.write( 0 );
}
}, 100);
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Assignment 5: Solution
For the solution please see the files in the A5 directory
58
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Client 1
59
Optimization Notice
callback
register
notify
Thing
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Client 1
60
Optimization Notice
callback 1
register
notify
Thing
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Client 2
Client 1
61
Optimization Notice
callback 2
1
register
notify
Thing
register
notify
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Client 2
Client 1
62
Optimization Notice
cb1
register
notify
cb2
Thing
register
notify
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Client 2
Publish-Subscribe
var subscribers = {};
function subscribe(cb,id) {
subscribers[id] = cb;
}
function unsubscribe(id) {
delete subscribers[id];
}
63
Optimization Notice
List of callbacks
Add a subscriber
Remove a subscriber
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Publish-Subscribe
function publish(data) {
for (id in subscribers) {
subscribers[id](data);
}
}
64
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
65
Optimization Notice
this.publish =
function() {
for (id in this.subs) {
this.subs[id].apply(
arguments
);
}
}
};
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
this.subscribe = function(cb,id) {
hub.subscribe(cb,id);
conn.on('end', function() {
hub.unsubscribe(id);
Subscribe function
automatically unsubscribes
when connection ends
});
}
});
stream.pipe(d).pipe(stream);
66
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
this.subscribe = function(cb,id) {
hub.subscribe(cb,id);
conn.on('end', function() {
hub.unsubscribe(id);
Subscribe function
automatically unsubscribes
when connection ends
});
}
});
stream.pipe(d).pipe(stream);
67
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
68
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
71
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Agenda
72
Optimization Notice
Internet of Things
Set up the Thing
Build the Thing
Program the Thing
Network the Thing
Connect the Thing (10m)
Conclusion
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Web Services
Server (using Express)
request('http://192.168.0.3/time.txt:8080',
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Print the time
}
});
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
server.on('ready', setup);
Optimization Notice
function setup() {
console.log('Mosca is up');
}
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Subscribe
75
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Subscribe
client = mqtt.createClient(1883,
192.168.0.2');
client = mqtt.createClient(1883,
192.168.0.2');
// Get my hostname
var os = require("os");
var hn = os.hostname();
client.subscribe(light/#');
Optimization Notice
client.on('message',
function (topic, message) {
console.log(topic,": ",message);
}
);
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Send data to
Kinesis*
},kinesis); // publish ID
77
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
var log_data = {
AWS.config.loadFromPath(
"/home/root/aws_config.json");
'Data': JSON.stringify(status),
'PartitionKey':
'StreamName': 'Light',
};
hub.subscribe(function(err,status) {
Send data to
Kinesis*
kinesis.putRecord(log_data,
function(err,data) {
if (err) {
}
}
},kinesis); // publish ID
78
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Agenda
79
Optimization Notice
Internet of Things
Set up the Thing
Build the Thing
Program the Thing
Network the Thing
Connect the Thing
Conclusion (5m)
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Summary
80
Embedded things also need to interface with mobile devices and services
Things can talk to web services and even provide their own services
The Intel XDK IoT Edition provides a convenient way to program and
debug both mobile devices using HTML5 and things using Node.js
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Call to Action
What have you done?
You have seen how to build a complete IoT system
- Not just a single thing, but a thing talking to both interface devices and services
- You seen how all this can be done using a single programming language, JavaScript *
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
References
1.
83
2.
3.
4.
5.
6.
7.
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Software and workloads used in performance tests may have been optimized for performance only on Intel
microprocessors. Performance tests, such as SYSmark and MobileMark, are measured using specific computer
systems, components, software, operations and functions. Any change to any of those factors may cause the
results to vary. You should consult other information and performance tests to assist you in fully evaluating your
contemplated purchases, including the performance of that product when combined with other products.
Copyright 2014, Intel Corporation. All rights reserved. Intel, Pentium, Xeon, Xeon Phi, Core, VTune, Cilk, and the
Intel logo are trademarks of Intel Corporation in the U.S. and other countries.
Optimization Notice
Intels compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel
microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the
availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent
optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture
are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the
specific instruction sets covered by this notice.
Notice revision #20110804
84
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.
Risk Factors
The above statements and any others in this document that refer to plans and expectations for the first quarter, the year and the future are forwardlooking statements that involve a number of risks and uncertainties. Words such as "anticipates," "expects," "intends," "plans," "believes," "seeks,"
"estimates," "may," "will," "should" and their variations identify forward-looking statements. Statements that refer to or are based on projections,
uncertain events or assumptions also identify forward-looking statements. Many factors could affect Intel's actual results, and variances from Intel's
current expectations regarding such factors could cause actual results to differ materially from those expressed in these forward-looking statements.
Intel presently considers the following to be important factors that could cause actual results to differ materially from the company's expectations.
Demand for Intels products is highly variable and could differ from expectations due to factors including changes in the business and economic
conditions; consumer confidence or income levels; customer acceptance of Intels and competitors products; competitive and pricing pressures,
including actions taken by competitors; supply constraints and other disruptions affecting customers; changes in customer order patterns including
order cancellations; and changes in the level of inventory at customers. Intels gross margin percentage could vary significantly from expectations based
on capacity utilization; variations in inventory valuation, including variations related to the timing of qualifying products for sale; changes in revenue
levels; segment product mix; the timing and execution of the manufacturing ramp and associated costs; excess or obsolete inventory; changes in unit
costs; defects or disruptions in the supply of materials or resources; and product manufacturing quality/yields. Variations in gross margin may also be
caused by the timing of Intel product introductions and related expenses, including marketing expenses, and Intels ability to respond quickly to
technological developments and to introduce new features into existing products, which may result in restructuring and asset impairment charges.
Intel's results could be affected by adverse economic, social, political and physical/infrastructure conditions in countries where Intel, its customers or its
suppliers operate, including military conflict and other security risks, natural disasters, infrastructure disruptions, health concerns and fluctuations in
currency exchange rates. Results may also be affected by the formal or informal imposition by countries of new or revised export and/or import and
doing-business regulations, which could be changed without prior notice. Intel operates in highly competitive industries and its operations have high
costs that are either fixed or difficult to reduce in the short term. The amount, timing and execution of Intels stock repurchase program and dividend
program could be affected by changes in Intels priorities for the use of cash, such as operational spending, capital spending, acquisitions, and as a result
of changes to Intels cash flows and changes in tax laws. Product defects or errata (deviations from published specifications) may adversely impact our
expenses, revenues and reputation. Intels results could be affected by litigation or regulatory matters involving intellectual property, stockholder,
consumer, antitrust, disclosure and other issues. An unfavorable ruling could include monetary damages or an injunction prohibiting Intel from
manufacturing or selling one or more products, precluding particular business practices, impacting Intels ability to design its products, or requiring
other remedies such as compulsory licensing of intellectual property. Intels results may be affected by the timing of closing of acquisitions, divestitures
and other significant transactions. A detailed discussion of these and other factors that could affect Intels results is included in Intels SEC filings,
including the companys most recent reports on Form 10-Q, Form 10-K and earnings release.
86
Rev. 1/15/15
Optimization Notice
Copyright 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.