Created
October 20, 2015 01:41
-
-
Save marchbold/6ac6c618f39827141b91 to your computer and use it in GitHub Desktop.
Bluetooth LE: Updating Subscribed Centrals
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
// This assumes you have previously published and advertised services as a peripheral | |
var characteristic:Characteristic = ...; // Some characteristic you have created and added to a published service | |
BluetoothLE.service.peripheralManager.addEventListener( CentralEvent.SUBSCRIBE, peripheral_central_subscribeHandler ); | |
BluetoothLE.service.peripheralManager.addEventListener( CentralEvent.UNSUBSCRIBE, peripheral_central_unsubscribeHandler ); | |
... | |
private function peripheral_central_subscribeHandler( event:CentralEvent ):void | |
{ | |
trace( "peripheral manager: central subscribe: " + event.central.uuid ); | |
// You should use this to track whether you should be periodically sending updates | |
// For the moment we'll just show as an example sending an update immediately | |
var value:ByteArray = new ByteArray(); | |
value.writeUTFBytes( "some_updated_value" ); | |
BluetoothLE.service.peripheralManager.updateValue( characteristic, value ); | |
} | |
private function peripheral_central_unsubscribeHandler( event:CentralEvent ):void | |
{ | |
trace( "peripheral manager: central unsubscribe: " + event.central.uuid ); | |
// If there are no other centrals subscribed you can stop periodically sending updates | |
} | |
// com.distriqt.BluetoothLE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment