Created
June 23, 2014 19:22
-
-
Save EvanSimpson/e6199ece19e2bccbc20b to your computer and use it in GitHub Desktop.
BLE113a Connection Test for Tessel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tessel = require('tessel'); | |
var bgLib = require('bglib'); | |
var bglib = new bgLib(); | |
var port = tessel.port['A']; | |
var resetPin = port.digital[2]; | |
var uart = port.UART({baudrate: 9600}); | |
uart.on('data', parseData); | |
var incomingBuf = []; | |
function parseData(data){ | |
bglib.parseIncoming(data, function(err, packets){ | |
for (var i=0; i < packets.length; i++){ | |
if (packets[i].packet.cClass == 0) { | |
if (packets[i].packet.cID == 0) { | |
console.log('Device booted'); | |
sayHello(); | |
} else if(packets[i].packet.cID == 1) { | |
console.log('Device said hello back'); | |
process.exit(); | |
} else { | |
logOther(packets[i]); | |
} | |
} else { | |
logOther(packets[i]); | |
} | |
} | |
}); | |
function logOther (packet){ | |
console.log('Got other packet', packet); | |
} | |
} | |
function reset(){ | |
console.log('Reseting BLE device'); | |
resetPin.output().low(); | |
resetPin.high(); | |
} | |
function sayHello(){ | |
var numSent = uart.write(new Buffer([0x04, 0x00, 0x00, 0x00, 0x01])); | |
console.log('Said hello to device'); | |
} | |
reset(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment