Hardware Reference
In-Depth Information
Power up your Bone using the 5 V adapter. You need the adapter because the BLE dongle
needs extra power for the radios it contains. After it is booted up, log in ( Recipe 5.3 ) and
run the following commands:
bone# apt-get install libbluetooth-dev
bone# npm install -g sensortag
This installs the Bluetooth tools and the JavaScript library to talk to it.
Add the code in Example 2-15 to a file called sensorTag.js and run it.
Example 2-15. Code for reading the temperature from a SensorTag (sensorTag.js)
#!/usr/bin/env node
// From: https://github.com/sandeepmistry/node-sensortag
// Reads temperature
var util = require ( 'util' );
var async = require ( 'async' );
var SensorTag = require ( 'sensortag' );
var fs = require ( 'fs' );
console . log ( "Be sure sensorTag is on" );
SensorTag . discover ( function ( sensorTag ) {
console . log ( 'sensorTag = ' + sensorTag );
sensorTag . on ( 'disconnect' , function () {
console . log ( 'disconnected!' );
process . exit ( 0 );
});
async . series ([
function ( callback ) {
console . log ( 'connect' );
sensorTag . connect ( callback );
},
function ( callback ) {
console . log ( 'discoverServicesAndCharacteristics' );
sensorTag . discoverServicesAndCharacteristics ( callback );
},
function ( callback ) {
console . log ( 'enableIrTemperature' );
sensorTag . enableIrTemperature ( callback );
},
 
 
 
 
 
 
 
Search WWH ::




Custom Search