Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marchbold/6ac6c618f39827141b91 to your computer and use it in GitHub Desktop.
Save marchbold/6ac6c618f39827141b91 to your computer and use it in GitHub Desktop.
Bluetooth LE: Updating Subscribed Centrals
// 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