Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Detect IBeacon mac address

$
0
0

Hello .. I am using alloy to create app the detect ibeacons near to me using altbeacon module . I want to detect ibeacon mac address but i can not . how can i do this . Thanks.

var button1 = Ti.UI.createButton({
    title : 'Start Monitoring',
    top : 10,
    height : 50
});
button1.addEventListener('click', startMonitoring);
var button2 = Ti.UI.createButton({
    title : 'Start Ranging',
    top : 70,
    height : 50
});
button2.addEventListener('click', startRanging);
 
 
 
var label = Ti.UI.createLabel();
label.addEventListener('click', function() {
    label.text = '';
});
$.scroll.add(button1);
$.scroll.add(button2);
$.scroll.add(label);
$.win.open();
 
var TiBeacons = null;
if (Ti.Platform.name == "android") {
    TiBeacons = require('com.drtech.altbeacon');
    TiBeacons.setScanPeriods({
    foregroundScanPeriod: 1000*60*10,
    foregroundBetweenScanPeriod: 1000*60*10,
    backgroundScanPeriod: 1000*60*10,
    backgroundBetweenScanPeriod: 1000*60*10
});
    TiBeacons.addBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
    TiBeacons.bindBeaconService();
    label.text = "module is => " + TiBeacons + "and checkAvailability says: " + TiBeacons.checkAvailability();
} else {
    label.text = "com.drtech.altbeacon not supported on " + Ti.Platform.name;
}
 
function startMonitoring() {
    if (TiBeacons != null) {
        TiBeacons.addEventListener("enteredRegion", enteredRegionCallback);
        TiBeacons.addEventListener("exitedRegion", exitedRegionCallback);
        TiBeacons.addEventListener("beaconProximity", rangingCallback);
 
        TiBeacons.startMonitoringForRegion({
            identifier : 'Region by UUID only',
            uuid : 'E2C56DB5-DFFB-48D2-B060-D0F5A71096E0'
        });
    }
    button1.removeEventListener('click', startMonitoring);
    button1.title = 'Stop Monitoring';
    button1.addEventListener('click', stopMonitoring);
}
 
function startRanging() {
    if (TiBeacons != null) {
        TiBeacons.addEventListener("enteredRegion", enteredRegionCallback);
        TiBeacons.addEventListener("exitedRegion", exitedRegionCallback);
        TiBeacons.addEventListener("beaconProximity", rangingCallback);
 
        TiBeacons.startRangingForBeacons({
            identifier : 'Region by UUID only',
            uuid : 'E2C56DB5-DFFB-48D2-B060-D0F5A71096E0'
        });
    }
    button2.removeEventListener('click', startRanging);
    button2.title = 'Stop Ranging';
    button2.addEventListener('click', stopRanging);
}
 
function stopMonitoring() {
    TiBeacons.stopMonitoringAllRegions();
    if (TiBeacons != null) {
        TiBeacons.removeEventListener("enteredRegion", enteredRegionCallback);
        TiBeacons.removeEventListener("exitedRegion", exitedRegionCallback);
        TiBeacons.removeEventListener("beaconProximity", rangingCallback);
    }
    button1.removeEventListener('click', startMonitoring);
    button1.title = 'Start Monitoring';
    button1.addEventListener('click', startMonitoring);
}
 
function stopRanging() {
    TiBeacons.stopRangingForAllBeacons();
    if (TiBeacons != null) {
        TiBeacons.removeEventListener("enteredRegion", enteredRegionCallback);
        TiBeacons.removeEventListener("exitedRegion", exitedRegionCallback);
        TiBeacons.removeEventListener("beaconProximity", rangingCallback);
    }
    button2.removeEventListener('click', stopRanging);
    button2.title = 'Start Ranging';
    button2.addEventListener('click', startRanging);
}
 
function enteredRegionCallback(e) {
    console.log(JSON.stringify(e));
    console.log("identifer: " + e.identifier);
    label.text = "Entered region: " + e.identifier;
}
 
function exitedRegionCallback(e) {
    console.log(JSON.stringify(e));
    console.log("identifer: " + e.identifier);
    label.text = "Exited region: " + e.identifier;
}
 
function rangingCallback(e) {
    console.log(JSON.stringify(e));
    console.log("identifer: " + e.identifier);
    console.log("uuid: " + e.uuid);
    console.log("major: " + e.major);
    console.log("minor: " + e.minor);
    console.log("proximity: " + e.proximity);
    console.log("accuracy: " + e.accuracy);
    console.log("rssi: " + e.rssi);
    console.log("power: " + e.power);
    //console.log("mac: " + e.macAddress);
    var d = "Proximity:\n" + "Identifier: " + e.identifier + "\n" + "UUID: " + e.uuid + "\n" + "Major: " + e.major + "\n" + "Minor: " + e.minor + "\n" + "Proximity: " + e.proximity + "\n" + "Distance: " + e.accuracy + "\n" + "RSSI: " + e.rssi + "\n" + "Power: " + e.power;
 
     var Detailslabel = Ti.UI.createLabel();
     Detailslabel.text = d;
     $.scroll.add(Detailslabel);
 
 
 
}
 
function monitorCallback(e) {
 
}

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>