Intel Do-It-Yourself Challenge Lab 5: Controlling Galileo from a webpage Nicolas Vailliet ...

12
Intel Do-It-Yourself Challenge Lab 5: Controlling Galileo from a webpage Nicolas Vailliet www.Intel-Software-Academic-Program.com [email protected] Intel Software 2014-02-01

Transcript of Intel Do-It-Yourself Challenge Lab 5: Controlling Galileo from a webpage Nicolas Vailliet ...

Page 1: Intel Do-It-Yourself Challenge Lab 5: Controlling Galileo from a webpage Nicolas Vailliet  paul.guermonprez@intel.com.

Intel Do-It-Yourself ChallengeLab 5: Controlling Galileo from a

webpage

Nicolas Vaillietwww.Intel-Software-Academic-Program.com

[email protected] Software

2014-02-01

Page 2: Intel Do-It-Yourself Challenge Lab 5: Controlling Galileo from a webpage Nicolas Vailliet  paul.guermonprez@intel.com.

Prerequisites and objectivesWe assume that:- You are able to download an archive, to unzipped it and run a

program under the OS you’re familiar to.- You are able to read pieces of code and comments written in C-like

language.

Our objective are:- Given a Galileo board and a laptop connected on the same

network, you will be able to write node.js code to control galileo from a webpage, displayed in your laptop’s browser.

In general,Our goal is to teach you a little bit of node.js, as it is one of the most employed technology in IoT.

Page 3: Intel Do-It-Yourself Challenge Lab 5: Controlling Galileo from a webpage Nicolas Vailliet  paul.guermonprez@intel.com.

Before you start

Page 4: Intel Do-It-Yourself Challenge Lab 5: Controlling Galileo from a webpage Nicolas Vailliet  paul.guermonprez@intel.com.

What do you need?Desktop OSWe assume you’re under Microsoft Windows.Linux and Mac users should not have any problem to do the same.

Hardware- An Intel Galileo Development Board.- The box comes with power supply and cable.- A Wi-Fi adaptor (N-2200 Mini-PCIe)- A micro SD card (8GB with the full Linux image we provide)

Software- A SSH client like Putty for Windows. Mac and Linux users only need a terminal.http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

- Set up system date to avoid certificate expiration issue- Install Galileo-io node on your Galileo board

(Optional: You can install node.js on your laptop to test your program before).

Page 5: Intel Do-It-Yourself Challenge Lab 5: Controlling Galileo from a webpage Nicolas Vailliet  paul.guermonprez@intel.com.

Web LED controller demo

Page 6: Intel Do-It-Yourself Challenge Lab 5: Controlling Galileo from a webpage Nicolas Vailliet  paul.guermonprez@intel.com.

Web LED controller demoGalileo-io moduleThis node.js module allows you to access GPIO without dealing with files from Linux file system (and the mapping stuff). Functions have the same name as Arduino library ones.

Importing this modulevar Galileo = require("galileo-io");var board = new Galileo();

TurnOnLed functionfunction turnOnLed(){

board.digitalWrite(8, 1);}

A simple HTTP servervar http = require('http');

http.createServer(function (req, res) {function respond() {

res.writeHead(200, { "Content-Type": "text/html" });res.end(“Hello World");

}).listen(1337);

Page 7: Intel Do-It-Yourself Challenge Lab 5: Controlling Galileo from a webpage Nicolas Vailliet  paul.guermonprez@intel.com.

Web LED controller demoA respond function with a basic html page function respond() {

res.writeHead(200, { "Content-Type": "text/html" });res.write("<!DOCTYPE html><html><body>");res.write("<h1>Intel Galileo web controller</h1>");res.write("<p>Sensor value : ");res.write(sensorvalue);res.write("</p><p>LED Status : ");res.write(ledstatus);res.write("</p><p>Action</p>");res.write("<p><input type='button' onclick='location.reload();'

value='Refresh'/></p>");res.write("<p><input type='button' onclick='window.location =

\"http://192.168.2.134:1337/ledOn\"' value='Turn LED on'/></p>");

res.write("<p><input type='button' onclick='window.location = \"http://192.168.2.134:1337/ledOff\"'

value='Turn LED off'/></p>");res.write("</body></html>"); res.end();

}

Page 8: Intel Do-It-Yourself Challenge Lab 5: Controlling Galileo from a webpage Nicolas Vailliet  paul.guermonprez@intel.com.

Web LED controller demoLooking the server-side URL to determine the command

console.log("Request: " + req.url);if(req.url === "/ledOn")

turnOnLed();else if(req.url === "/ledOff")

turnOffLed();respond();

}).listen(1337);console.log('Server running at http://localhost:1337/');}

Running the serverstartServer();

Page 9: Intel Do-It-Yourself Challenge Lab 5: Controlling Galileo from a webpage Nicolas Vailliet  paul.guermonprez@intel.com.

Web LED controller demoOpen your browserAccess the URL : http://192.168.2.1XX:1337/Click on buttons to test your implementation!

Page 10: Intel Do-It-Yourself Challenge Lab 5: Controlling Galileo from a webpage Nicolas Vailliet  paul.guermonprez@intel.com.

Controlling servo motorsUSB ports on Galileo are useful.Let’s control servo motor!

Implement your own projectsWant a remote for Galileo? Do it under Android!Another idea? Let’s make it!

Next steps

Page 11: Intel Do-It-Yourself Challenge Lab 5: Controlling Galileo from a webpage Nicolas Vailliet  paul.guermonprez@intel.com.
Page 12: Intel Do-It-Yourself Challenge Lab 5: Controlling Galileo from a webpage Nicolas Vailliet  paul.guermonprez@intel.com.

License Creative Commons – By 3.0

You are free:• to Share — to copy, distribute and transmit the work • to Remix — to adapt the work • to make commercial use of the work Under the following conditions:• Attribution — You must attribute the work in the manner specified by the author or licensor (but

not in any way that suggests that they endorse you or your use of the work).With the understanding that: • Waiver — Any of the above conditions can be waived if you get permission from the copyright

holder. • Public Domain — Where the work or any of its elements is in the public domain under applicable

law, that status is in no way affected by the license. • Other Rights — In no way are any of the following rights affected by the license:

– Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations; – The author's moral rights; – Rights other persons may have either in the work itself or in how the work is used, such as publicity or

privacy rights. • Notice — For any reuse or distribution, you must make clear to others the license terms of this

work. The best way to do this is with a link to this web page.

http://creativecommons.org/licenses/by/3.0/