Skip to content

Instantly share code, notes, and snippets.

@sandeepmistry sandeepmistry/main.js Secret
Last active Mar 17, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.