Top Banner
IoT Hackathon : Tessel Thomas Conté @tomconte
19

Tessel + Azure IoT hackathon intro

Aug 08, 2015

Download

Technology

Thomas Conté
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Tessel + Azure IoT hackathon intro

IoT Hackathon : Tessel

Thomas Conté @tomconte

Page 2: Tessel + Azure IoT hackathon intro

The Tessel is tiny

Page 3: Tessel + Azure IoT hackathon intro

Its modules too

Page 4: Tessel + Azure IoT hackathon intro

Modules

▪ Accelerometer

▪ Ambient Light + Sound

▪ Audio

▪ Bluetooth Low Energy

▪ Camera

▪ Climate

▪ GPS

▪ GPRS

▪ Infrared

▪ MicroSD Card

▪ nRF24 Module

▪ Relay

▪ RFID

▪ Servo

Page 5: Tessel + Azure IoT hackathon intro
Page 6: Tessel + Azure IoT hackathon intro

http://blog.technical.io/post/98257815497/how-tessel-works-the-basics

Page 7: Tessel + Azure IoT hackathon intro

What can you do with a Tessel?

▪ Ambient monitoring: monitor temperature, noise… Detect variations and take action / notify.– Is the light on at home? Turn on Hue lights automatically at dark.

▪ Accelerometer: game controllers, activity trackers…

▪ Camera: take pictures on event, motion detection…

▪ Infrared: control your TV– Clap your hands to turn it on

▪ Lots of projects ideas: https://projects.tessel.io/projects

Page 8: Tessel + Azure IoT hackathon intro

What can you do with Azure?

▪ In theory, anything you can do in Node.JS– In practice, some complex modules or projects will cause translation

problems because not all Node constructs are fully supported– Most notably, the Azure SDKs for Node.JS seem to be causing some

problems– It might be easier to revert to plain old REST APIs when possible

▪ Upload stuff to Azure: Blob Storage

▪ Send monitoring/telemetry to Azure: Service Bus, Event Hubs– Experiment with different protocols: HTTPS, AMQP, MQTT…

▪ Interact with mobile devices through Mobile Services– Send notifications

▪ Labs on https://github.com/dx-ted-emea/azure-tessel

Page 9: Tessel + Azure IoT hackathon intro

Node for Tessel crash course

Page 10: Tessel + Azure IoT hackathon intro

Node.JS for the Tessel

▪ Node.JS is usually used on the server-side; here we are going to use it on the client side!

▪ Node.JS is well suited to real-time processing of events, thanks to its asynchronous nature; this is well adapted to a device whose main job is to monitor and process events (temperature / noise / light / etc.)

▪ Instead of listening to server-side events (GET, POST, etc.) you will be listening to module-specific events

▪ Events are handled using callbacks, functions that you pass when registering for the event

Page 11: Tessel + Azure IoT hackathon intro

Hello World: tessel run blinky.js

// Import the interface to Tessel hardwarevar tessel = require('tessel');

// Set the led pins as outputs with initial states// Truthy initial state sets the pin high// Falsy sets it low.var led1 = tessel.led[0].output(1);var led2 = tessel.led[1].output(0);

setInterval(function () { console.log("I'm blinking! (Press CTRL + C to stop)"); // Toggle the led states led1.toggle(); led2.toggle();}, 100);

Page 12: Tessel + Azure IoT hackathon intro

npm for the Tessel

▪ When you install the Tessel library, you will use npm –g

▪ This will install the library and CLI “globally”, i.e. in a place where it can be found by default from your shell

▪ When you install Tessel Node.JS modules (corresponding to the hardware “modules”) you will not use –g

▪ This will install the module locally in a directory called node_modules

▪ When you run your script with tessel run, all the dependent modules in node_modules will automatically be packaged and sent to the Tessel

Page 13: Tessel + Azure IoT hackathon intro

Listen for Ambient module events

var tessel = require('tessel');

var ambientlib = require('ambient-attx4');

var ambient = ambientlib.use(tessel.port['A']);

ambient.on('ready', function () {

ambient.setLightTrigger(0.5);

ambient.on('light-trigger', function(data) {

console.log("Our light trigger was hit:", data);

});

});

Page 14: Tessel + Azure IoT hackathon intro

JavaScript callback hell

var db = require('somedatabaseprovider'); http.get('/recentposts', function(req, res){ db.openConnection('host', creds, function(err, conn){ res.param['posts'].forEach(post) { conn.query('select * from users where id=' + post['user'],function(err,results){ conn.close(); res.send(results[0]); }); } }); });

Page 15: Tessel + Azure IoT hackathon intro

Don’t panic

var db = require('somedatabaseprovider'); http.get('/recentposts', afterRecentPosts); function afterRecentPosts(req, res) { db.openConnection('host', creds, function(err, conn) { afterDBConnected(res, conn); }); } function afterDBConnected(err, conn) { res.param['posts'].forEach(post) { conn.query('select * from users where id=‘ +post['user'],afterQuery); } } function afterQuery(err, results) { conn.close(); res.send(results[0]); }

▪ Avoid anonymous callbacks

▪ Give them names and move them out of the “pyramid”

▪ This is good enough to make the code reasonably maintainable

▪ To go further, explore JavaScript Promises and/or the Q library

Page 16: Tessel + Azure IoT hackathon intro

Let’s hack!

▪ Grab your hardware

▪ Pair up–Might be best to have one person who

knows JS/Node per pair

▪ Get something done in 4 hours

▪ Present your results/learnings/findings

Page 17: Tessel + Azure IoT hackathon intro

Getting Started

▪ First, install Node.JS!–http://nodejs.org/ –Click on the big green INSTALL button

▪ Go to tessel.io/start

▪ Basically,–npm install -g tessel–tessel update

Page 18: Tessel + Azure IoT hackathon intro

More getting started: Wi-Fi

▪ Pretty hard to connect to MSFT network, even MSFTOPEN isn’t stable

▪ Revert to using phone hotspot

▪ tessel wifi -n “MyPhone" -p "Passxyz "

Page 19: Tessel + Azure IoT hackathon intro

The End