Last active
October 19, 2015 08:39
-
-
Save marchbold/ca04781574881dbca7ec to your computer and use it in GitHub Desktop.
Bluetooth LE: Discover services and characteristics of a connected peripheral
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var peripheral:Peripheral = ...; // This snippet assumes you have a connected 'peripheral' object. | |
var service:Service = null; | |
peripheral.addEventListener( PeripheralEvent.DISCOVER_SERVICES, peripheral_discoverServicesHandler ); | |
peripheral.addEventListener( PeripheralEvent.DISCOVER_CHARACTERISTICS, peripheral_discoverCharacteristicsHandler ); | |
peripheral.discoverServices(); | |
... | |
private function peripheral_discoverServicesHandler( event:PeripheralEvent ):void | |
{ | |
trace( "peripheral discover services: " + event.peripheral.name ); | |
if (event.peripheral.services.length > 0) | |
{ | |
for each (var service:Service in event.peripheral.services) | |
{ | |
trace( "service: "+ service.uuid ); | |
} | |
// As an example discover the characteristics of the first available service | |
peripheral.discoverCharacteristics( peripheral.services[0] ); | |
} | |
} | |
private function peripheral_discoverCharacteristicsHandler( event:PeripheralEvent ):void | |
{ | |
trace( "peripheral discover characteristics: " + event.peripheral.name ); | |
for each (var service:Service in event.peripheral.services) | |
{ | |
trace( "service: "+ service.uuid ); | |
for each (var ch:Characteristic in service.characteristics) | |
{ | |
trace( "characteristic: "+ch.uuid ); | |
} | |
} | |
} | |
// com.distriqt.BluetoothLE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment