Presentation is loading. Please wait.

Presentation is loading. Please wait.

Internet of Things with Intel Edison Web controller

Similar presentations

Presentation on theme: "Internet of Things with Intel Edison Web controller"— Presentation transcript:

1 Internet of Things with Intel Edison Web controller
Pierre Collet Intel Software

2 Objectives Objective NodeJS
Edison is highly connected, so let’s use the network : Edison as a web server, your laptop as a network client. We’ll interact with a LED, because that’s a thing you could not do on a regular PC. NodeJS We’ll use NodeJS : it’s a JavaScript based framework, but commonly used from a command line interpreter, not in a browser window. NodeJS is also asynchronous / functional programming, making it very easy to develop network interactions. It’s very popular in the IoT field, and there’s tons of libraries in NodeJS.

3 What do you need? Software Run script
On Windows, we use Putty as ssh client. On mac or linux, ssh is part of the regular shell. We’ll run NodeJS framework on the Edison board itself, as a server language. But you can also install NodeJS on your laptop to run some scripts locally. Run script The code discussed today is available from the folder : labs/nodeserver. To execute the script, run : node ./webcontroller.js

4 Web LED controller demo

5 Architecture Architecture – Network side Architecture – LED side
NodeJS will create html and send it over the network. Your browser will display the result. Architecture – LED side NodeJS will launch 2 scripts to control the LED : and They are controlling the pin 7. Architecture – NodeJS library or System call ? In the future, you may find a NodeJS modules to interface sensors on Edison and you won’t need to call shell scripts. We already have galileo-io for Intel Galileo. But it’s good to know you don’t need a native NodeJS module for simple things. It’s important for other scripting languages where no Edison module will come : remember you can call libmraa binaries or shell scripts.

6 The Code # Import child_process function # TurnOnLed function
var system = require(‘child_process’).exec; # TurnOnLed function function turnOnLed(){ system(‘sh ./’); /* execute the shell script */ ledstatus = “on”; } # A simple HTTP server var http = require('http'); http.createServer(function (req, res) { function respond() { res.writeHead(200, { "Content-Type": "text/html" }); res.end(“Hello World"); }).listen(1337);

7 The Code # A function to send the default home page
function respond() { res.writeHead(200, { "Content-Type": "text/html" }); res.write("<!DOCTYPE html><html><body>"); res.write("<h1>Intel Edison 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=‘location.pathname = \"/ledOn\"' value='Turn LED on'/></p>"); res.write("<p><input type='button' onclick=‘location.pathname = \"/ledOff\"' value='Turn LED off'/></p>"); res.write("</body></html>"); res.end(); }

8 The Code Analyzing URL to determine the command Running the server
console.log("Request: " + req.url); if(req.url === "/ledOn") turnOnLed(); else if(req.url === "/ledOff") turnOffLed(); respond(); }).listen(1337); console.log('Server running at } Running the server startServer();

9 Demo Open your browser Access the URL : http://192.168.XXX.XXX:1337/
Click on buttons to test your implementation!

10 Conclusion Network – Object Full Server NodeJS
With this demo, we’ve seen we can interact with an IoT object (LED, sensor) on one side and the network on the other side. That’s the definition of an IoT. Full Server Edison is not only sending data over the network. It can act as a server. We used NodeJS, but larger stacks like Apache or JBoss run very well. NodeJS NodeJS is a great framework for networked IoT. Even if there’s no module to do what you need, just call a script or a libmraa binary !


12 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.

Download ppt "Internet of Things with Intel Edison Web controller"

Similar presentations

Ads by Google