Skip to content

Instantly share code, notes, and snippets.

@sandeepmistry
Last active March 17, 2016 23:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandeepmistry/d423c8c3b3e7a6947517 to your computer and use it in GitHub Desktop.
Save sandeepmistry/d423c8c3b3e7a6947517 to your computer and use it in GitHub Desktop.
Reconfigure any Estimote 3.1+ beacon in range to broadcast a specified Eddystone-URL
var async = require('async');
var encodeEddystoneUrl = require('eddystone-url-encoding').encode;
var Estimote = require('bleacon').Estimote;
var URL = 'http://example.com';
var ENCODED_URL_DATA = encodeEddystoneUrl(URL);
var discovered = {};
console.log('discovering all Estimote beacons in range');
console.log('-----------------------------------------')
Estimote.discoverAll(function(estimote) {
var address = estimote.address;
if (discovered[address]) {
// already discovered ... ignore
return;
}
discovered[address] = true;
console.log('discovered beacon: ' + address);
async.series([
function(callback) {
console.log('connecting and setting up ...');
estimote.connectAndSetUp(function() {
console.log('\tdone');
callback();
});
},
function(callback) {
console.log('pairing ...');
estimote.pair(function(error) {
console.log('\tdone');
callback();
});
},
function(callback) {
console.log('writing encoded Eddystone URL ' + ENCODED_URL_DATA.toString('hex') + ' ...');
estimote.writeEddystoneUrl(ENCODED_URL_DATA, function() {
console.log('\tdone');
callback();
});
},
function(callback) {
console.log('writing service configuration for Eddystone-URL mode ...');
estimote.writeServiceConfiguration('eddystone-url', function() {
console.log('\tdone');
callback();
});
},
function(callback) {
console.log('disconnecting ...');
estimote.disconnect(function() {
console.log('\tdone');
callback();
});
}
]);
});
mkdir EstimoteEddystoneURL
cd EstimoteEddystoneURL
npm install async eddystone-url-encoding bleacon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment