Skip to content

Added more usability for beginners #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ var recognizedDevices = {
'105.105.60.123.235.203': 'Myo',
'70.10.117.62.49.92': 'August'
};
var tessel = require('tessel');
var blelib = require('ble-ble113a');
var ble = blelib.use(tessel.port['A']);

// Set up server
var router = require('tiny-router');
router.get('/', function (req, res) {
console.log('request from client');
if (devices.length > 0) {
var page = "<html><body>Devices in view:<br/><br/>";
for (var device in devices) {
Expand All @@ -32,16 +36,16 @@ router.get('/', function (req, res) {

// Start server
router.listen(port);
console.log('Listening on port', port);
var networkInterfaces=require('os').networkInterfaces();

console.log('Visit http://'+networkInterfaces.en1[0].address+':'+port+' to see your devices');

// Set up hardware
var tessel = require('tessel');
var blelib = require('ble-ble113a');
var ble = blelib.use(tessel.port['A']);


ble.on('ready', function () {
// Initial scan for devices
console.log('ready');
scan();
});

Expand All @@ -54,17 +58,25 @@ ble.on('discover', function(peripheral) {

// Scan for devices regularly
function poll() {
console.log('polling');
setTimeout(scan, pollFreq);
}

// Check and see if authed devices in range
function scan () {
// Reset found devices
devices = [];
console.log('Scanning...');
console.log('Scanning for BLE devices transceive as an iBeacon');
ble.startScanning();
console.log('... started');
noneFound = setTimeout(function () {
ble.stopScanning();
console.log('nothing found !');
console.log('########################################');
console.log('## Maybe you have no active iBeacon ? ##');
console.log('## Normal Bluetooth 4.x devices will ##');
console.log('## not be discovered by this scan! ##');
console.log('########################################');
// Check for changes
poll();
}, timeout);
Expand Down