implemented eddystone-uid & ibeacon uuid with bleacon
implemented eddystone-uid & ibeacon uuid with bleacon

file:a/app.js -> file:b/app.js
--- a/app.js
+++ b/app.js
@@ -1,5 +1,6 @@
 var request = require('request');
 var beacon = require('eddystone-beacon');
+var bleacon = require('bleacon');
 
 var app = [];
 var fs = require('fs');
@@ -39,12 +40,26 @@
 			json: true
 		}, function (error, response, body) {
 			if (!error && response.statusCode === 200) {
-				if (body.url && body.url != app.urlcache) {
-					beacon.advertiseUrl(body.url);
-					app.urlcache = body.url;
-				} else if (body.uid && body.uid != app.uidcache) {
-					//beacon.advertiseUid(body.uid); disable until eddystone-beacon supports it or use other library
-					app.uidcache = body.uid;
+				if (body.type == 'eddystone-url') {
+					if (body.url && body.url != app.urlcache) {
+						beacon.advertiseUrl(body.url);
+						app.urlcache = body.url;
+					}
+				} else if (body.type == 'eddystone-uid') {
+					if (body.namespaceId && body.instanceId && body.namespaceId+'-'+body.instanceId != app.uidcache) {
+						eddystoneBeacon.advertiseUid(body.namespaceId, body.instanceId);
+						app.uidcache = body.namespaceId+'-'+body.instanceId;
+					}
+				} else if (body.type == 'ibeacon') {
+					if (body.uuid && body.uuid != app.uuidcache) {
+						var uuid = body.uuid;
+						var major = body.major ? body.major : 0; // 0 - 65535
+						var minor = body.monor ? body.minor : 0; // 0 - 65535
+						var measuredPower = body.measuredPower ? body.measuredPower :  -59; // -128 - 127 (measured RSSI at 1 meter)
+
+						bleacon.startAdvertising(uuid, major, minor, measuredPower);
+						app.uuidcache = body.uuid;
+					}
 				}
 			}
 		});

--- a/backend/example.php
+++ b/backend/example.php
@@ -13,9 +13,26 @@
 ".tg",".th",".tj",".tk",".tm",".tn",".to",".tp",".tr",".tt",".tv",".tw",".tz",".ua",".ug",".uk",".um",".us",".uy",".uz", ".va",".vc",
 ".ve",".vg",".vi",".vn",".vu",".wf",".ws",".ye",".yt",".yu",".za",".zm",".zr",".zw");
 
-$json = array (
-	"url"	=>	"http://www.google".$domains[ mt_rand(0, count($domains)-1) ]."/"
-);
+if ( $_GET['type'] == "eddystone-url" ) {
+	$json = array (
+		"type"	=>	"eddystone-url",
+		"url"	=>	"http://www.google".$domains[ mt_rand(0, count($domains)-1) ]."/"
+	);
+} elseif ( $_GET['type'] == "eddystone-uid" ) {
+	$json = array (
+		"type"	=>	"eddystone-uid",
+		"namespaceId"	=>	"00010203040506070809",
+		"instanceId"	=>	"aabbccddeeff"
+	);
+} elseif ( $_GET['type'] == "ibeacon" ) {
+	$json = array (
+		"type"	=>	"ibeacon",
+		"uuid"	=>	"B9407F30F5F8466EAFF925556B57FE6D", //Estimote default proximityUUID
+		"minor"	=>	0,
+		"major"	=>	0,
+		"measuredPower"	=>	-59
+	);
+}
 echo json_encode ($json);
 
 ?>

--- a/default/piBeacon
+++ b/default/piBeacon
@@ -1,5 +1,5 @@
 DEVICES=1
 NAME="piBeacon demo"
-SERVER=http://demo.razvi.ro/piBeacon/index.php?
+SERVER=http://demo.razvi.ro/piBeacon/index.php?type=eddystone-url
 INTERVAL=60
 

file:a/install.sh -> file:b/install.sh
--- a/install.sh
+++ b/install.sh
@@ -18,6 +18,7 @@
 	rm node_latest_armhf.deb
 
 	npm install eddystone-beacon
+	npm install bleacon
 	npm install forever-monitor
 	npm install request
 	npm install forever -g
@@ -56,6 +57,7 @@
 
 	cd /opt/piBeacon
 	npm uninstall eddystone-beacon
+	npm uninstall bleacon
 	npm uninstall forever-monitor
 	npm uninstall request
 	npm uninstall forever -g

comments