Skip to content

peripheral.observe(characteristic) not working on macosArm64 #1168

Description

@BoD

The following piece of code works as expected on the JVM target running on MacOS. But when targeting macosArm64, I get 0 emission inside of collect {}:

logd("Scanning for $deviceName device...")
val advertisement = Scanner {
  logging {
    engine = NanoLogEngine()
  }
}.advertisements.first { it.name?.contains(deviceName, ignoreCase = true) == true }
logd("Found $deviceName device: ${advertisement.identifier}")

val peripheral = Peripheral(advertisement) {
  logging {
    engine = NanoLogEngine()
  }
}
peripheral.connect().launch {
  logd("Connected to peripheral: ${peripheral.identifier}")
  val services = peripheral.services.first { it != null }!!
  logd("services=$services")
  val characteristic = services.first { it.serviceUuid == Bluetooth.BaseUuid + GATT_SERVICE_CYCLING_SPEED_AND_CADENCE }
    .characteristics.first { it.characteristicUuid == Bluetooth.BaseUuid + GATT_CHARACTERISTIC_CYCLING_SPEED_AND_CADENCE_MEASUREMENT }
  logd("characteristic=$characteristic")
  peripheral.observe(characteristic).collect { byteArray ->
    logd(byteArray.size.toString()) // <- called in JVM, never called on macosArm64
  }
}

JVM logs

Connected to peripheral: fdedcd29-0725-2979-b358-de773371ccca

services=[
BtleplugService(service=Service(uuid=0000180a-0000-1000-8000-00805f9b34fb, primary=true, characteristics=[Characteristic(uuid=00002a27-0000-1000-8000-00805f9b34fb, service=0000180a-0000-1000-8000-00805f9b34fb, properties=CharacteristicPropertyFlags(bits=2), descriptors=[]), Characteristic(uuid=00002a28-0000-1000-8000-00805f9b34fb, service=0000180a-0000-1000-8000-00805f9b34fb, properties=CharacteristicPropertyFlags(bits=2), descriptors=[]), Characteristic(uuid=00002a29-0000-1000-8000-00805f9b34fb, service=0000180a-0000-1000-8000-00805f9b34fb, properties=CharacteristicPropertyFlags(bits=2), descriptors=[])])), 
BtleplugService(service=Service(uuid=0000180f-0000-1000-8000-00805f9b34fb, primary=true, characteristics=[Characteristic(uuid=00002a19-0000-1000-8000-00805f9b34fb, service=0000180f-0000-1000-8000-00805f9b34fb, properties=CharacteristicPropertyFlags(bits=18), descriptors=[Descriptor(uuid=00002902-0000-1000-8000-00805f9b34fb, service=0000180f-0000-1000-8000-00805f9b34fb, characteristic=00002a19-0000-1000-8000-00805f9b34fb)])])), 
BtleplugService(service=Service(uuid=00001816-0000-1000-8000-00805f9b34fb, primary=true, characteristics=[Characteristic(uuid=00002a55-0000-1000-8000-00805f9b34fb, service=00001816-0000-1000-8000-00805f9b34fb, properties=CharacteristicPropertyFlags(bits=40), descriptors=[Descriptor(uuid=00002902-0000-1000-8000-00805f9b34fb, service=00001816-0000-1000-8000-00805f9b34fb, characteristic=00002a55-0000-1000-8000-00805f9b34fb)]), Characteristic(uuid=00002a5b-0000-1000-8000-00805f9b34fb, service=00001816-0000-1000-8000-00805f9b34fb, properties=CharacteristicPropertyFlags(bits=16), descriptors=[Descriptor(uuid=00002902-0000-1000-8000-00805f9b34fb, service=00001816-0000-1000-8000-00805f9b34fb, characteristic=00002a5b-0000-1000-8000-00805f9b34fb)]), Characteristic(uuid=00002a5c-0000-1000-8000-00805f9b34fb, service=00001816-0000-1000-8000-00805f9b34fb, properties=CharacteristicPropertyFlags(bits=2), descriptors=[]), Characteristic(uuid=00002a5d-0000-1000-8000-00805f9b34fb, service=00001816-0000-1000-8000-00805f9b34fb, properties=CharacteristicPropertyFlags(bits=2), descriptors=[])])), 
BtleplugService(service=Service(uuid=6e400001-b5a3-f393-e0a9-e50e24dcca9e, primary=true, characteristics=[Characteristic(uuid=6e400002-b5a3-f393-e0a9-e50e24dcca9e, service=6e400001-b5a3-f393-e0a9-e50e24dcca9e, properties=CharacteristicPropertyFlags(bits=12), descriptors=[]), Characteristic(uuid=6e400003-b5a3-f393-e0a9-e50e24dcca9e, service=6e400001-b5a3-f393-e0a9-e50e24dcca9e, properties=CharacteristicPropertyFlags(bits=16), descriptors=[Descriptor(uuid=00002902-0000-1000-8000-00805f9b34fb, service=6e400001-b5a3-f393-e0a9-e50e24dcca9e, characteristic=6e400003-b5a3-f393-e0a9-e50e24dcca9e)])]))
]

characteristic=BtleplugCharacteristic(characteristic=Characteristic(uuid=00002a5b-0000-1000-8000-00805f9b34fb, service=00001816-0000-1000-8000-00805f9b34fb, properties=CharacteristicPropertyFlags(bits=16), descriptors=[Descriptor(uuid=00002902-0000-1000-8000-00805f9b34fb, service=00001816-0000-1000-8000-00805f9b34fb, characteristic=00002a5b-0000-1000-8000-00805f9b34fb)]))

Then I'm getting regular byteArray.size logs.

MacOS logs

Connected to peripheral: fdedcd29-0725-2979-b358-de773371ccca

services=[
DiscoveredService(serviceUuid=00001816-0000-1000-8000-00805f9b34fb, hashCode=51751936), 
DiscoveredService(serviceUuid=0000180f-0000-1000-8000-00805f9b34fb, hashCode=51751808), 
DiscoveredService(serviceUuid=0000180a-0000-1000-8000-00805f9b34fb, hashCode=51751680), 
DiscoveredService(serviceUuid=6e400001-b5a3-f393-e0a9-e50e24dcca9e, hashCode=51751552)
]

characteristic=DiscoveredCharacteristic(serviceUuid=00001816-0000-1000-8000-00805f9b34fb, serviceHashCode=51751936, characteristicUuid=00002a5b-0000-1000-8000-00805f9b34fb, characteristicHashCode=385696)

then nothing.

Help is appreciated! Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions