Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marchbold/52a155609b61eaafbfd3 to your computer and use it in GitHub Desktop.
Save marchbold/52a155609b61eaafbfd3 to your computer and use it in GitHub Desktop.
Bluetooth LE: Reading the value of a Characteristic
var peripheral:Peripheral = ...; // Previously connected Peripheral
var characteristic:Characteristic = ...; // Discovered Characteristic of interest
peripheral.addEventListener( CharacteristicEvent.UPDATE, peripheral_characteristic_updatedHandler );
peripheral.addEventListener( CharacteristicEvent.UPDATE_ERROR, peripheral_characteristic_errorHandler );
peripheral.readValueForCharacteristic( characteristic );
...
private function peripheral_characteristic_updatedHandler( event:CharacteristicEvent ):void
{
trace( "peripheral characteristic updated: " + event.characteristic.uuid );
trace( "value="+ event.characteristic.value.readUTFBytes( event.characteristic.value.length ) );
}
private function peripheral_characteristic_errorHandler( event:CharacteristicEvent ):void
{
trace( "peripheral characteristic error: [" + event.errorCode +"] "+event.error );
}
// com.distriqt.BluetoothLE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment