19
IoT Hackathon : Tessel Thomas Conté @tomconte

Tessel + Azure IoT hackathon intro

Embed Size (px)

Citation preview

IoT Hackathon : Tessel

Thomas Conté @tomconte

The Tessel is tiny

Its modules too

Modules

▪ Accelerometer

▪ Ambient Light + Sound

▪ Audio

▪ Bluetooth Low Energy

▪ Camera

▪ Climate

▪ GPS

▪ GPRS

▪ Infrared

▪ MicroSD Card

▪ nRF24 Module

▪ Relay

▪ RFID

▪ Servo

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

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

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

Node for Tessel crash course

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

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);

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

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);

});

});

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]); }); } }); });

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

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

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

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 "

The End