Name: ng-cordova-bluetoothle
Owner: Jewelbots
Description: Angular 1.x wrapper for the PhoneGap/Cordova Bluetooth Low Energy Plugin
Created: 2015-09-15 16:35:17.0
Updated: 2017-11-24 13:12:12.0
Pushed: 2016-01-09 21:26:20.0
Homepage: null
Size: 2400
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This wraps the Bluetooth Low Energy Phonegap Plugin by Rand Dusing in AngularJS code so it can be used more easily in AngularJS mobile applications.
The core Apache Cordova plugin is required to use this wrapper:
ova plugin add https://github.com/randdusing/BluetoothLE
params = {
quest: true,
me : 10000 //in milliseconds, time to scan defaults to 5000ms if not provided
dovaBluetoothle.startScan(params).then(function(success) {
console.log(device.name);
console.log(device.address);
The Scan method will stop as soon as it finds its first device. This is probably not what you want; and is a limitation of wrapping a continuous operation (like scan) into a one-time promise resolution. This is definitely open for improvement. I use 'find' instead to find a specific device.
params = {
quest: true, //ask user to enable bluetooth
me: 'Jewelbot' //device name to look for
icPlatform.ready()
.then(function () {
return $cordovaBluetoothle.initialize(params)
.then(function () {
//successfully initialized
return $cordovaBluetoothle.find(params);
}, function (err) {
//error trying to initialiez
});
})
.then(function (data) {
// Scanning for specific device
if (data.status === 'scanResult') {
$scope.model.status = 'Found device: ' + data.name;
$scope.model.devices.push(data);
return $cordovaBluetoothle.stopScan();
}
}, function (error) {
$scope.model.status = 'Error while scanning.' + JSON.stringify(error);
return $cordovaBluetoothle.stopScan();
}, function (notify) {
// found other devices; but not the device you're looking
})
.then(function () {
$scope.model.status = 'ending scan...';
return $cordovaBluetoothle.isScanning().then(function(isScanning) {
$scope.model.status = isScanning ? 'Scan Not Ended' : 'Scan Ended';
if (isScanning) {
return $cordovaBluetoothle.stopScan();
}
});
});
troller("ExampleController", ['$cordovaBluetoothle', '$ionicPlatform', '$scope', function($cordovaBluetoothle,$ionicPlatform, $scope ) {
$ionicPlatform.ready()
.then(function () {
return $cordovaBluetoothle.connect({address: $scope.model.address})
.then( function (success) {
//successfully paired
})
.error(function (err) {
//error while pairing, return promise that invokes disconnect.
return $cordovaBluetoothle.disconnect(address);
})
.notify(function (notify) {
//still trying to connect.
});
});
Here are a list of available functions:
dovaBluetoothle.initalize() //ios
dovaBluetoothle.enable() //android
dovaBluetoothle.disable() //android
dovaBluetoothle.startScan()
dovaBluetoothle.stopScan()
dovaBluetoothle.retrieveConnected()
dovaBluetoothle.connect()
dovaBluetoothle.disconnect()
dovaBluetoothle.reconnect()
dovaBluetoothle.close() // android
dovaBluetoothle.discover() //android
dovaBluetoothle.characteristics()
dovaBluetoothle.descriptors()
dovaBluetoothle.read()
dovaBluetoothle.subscribe()
dovaBluetoothle.unsubscribe()
dovaBluetoothle.write()
dovaBluetoothle.readDescriptor()
dovaBluetoothle.writeDescriptor()
dovaBluetoothle.rssi()
dovaBluetoothle.isInitialized()
dovaBluetoothle.isEnabled()
dovaBluetoothle.isScanning()
dovaBluetoothle.isConnected()
dovaBluetoothle.isDiscovered()
dovaBluetoothle.find()
AngularJS - http://www.angularjs.org
Apache Cordova - http://cordova.apache.org
The code that powers the 'build generation' is a carbon copy (with minimal changes) of Nic Raboy's ngCordovaBeacon project. As of the Fork, it was licensed under the MIT license; The Cordova Wrapper was written by myself, and my employer and I retain the copyright for that; but this project is also licensed under the MIT License.
If you want to follow more of Nic's work, his blog is located here. If you want to know more about me or Jewelbots, you can follow Jewelbots on twitter, our Ink, or me.