Acknowledged

App crashes when isBonded()/requestBond() API is used with simulator

Hello.

I'm facing problems using simulator (e.g., epix Gen 2, Forerunner 965) and at this point I'm pretty sure this is a bug, or something just unsupported. My setup is:

  • Windows 10
  • Java version 8 update 421
  • VSCode 1.92.2
  • Monkey C plugin 1.0.11
  • Connect IQ 7.2.1
  • nRF52840 Dongle (I checked two firmwares: connectivity_1.0.0_usb_with_s132_5.1.0.hex and connectivity_4.1.4_usb_with_s132_5.1.0.hex)

Whenever I'm calling isBonded() or requestBond() API, the application just crashes, with the following error:

Error: System Error
Details: Failed invoking <symbol>
Stack:
- onConnectedStateChanged() at E:\(...)\MyBleDelegate.mc:42 0x100000cc

Encountered app crash.

On the watch everything works fine, but it will be very hard to develop this way, so I'm looking how to do it using the simulator.

This is the minimum BleDelegate that can be used to reproduce the problem. The device in this case is GoPro 11, but it doesn't seem to make any difference - the call crashes with any device.

import Toybox.Lang;
using Toybox.BluetoothLowEnergy as Ble;

class MyBleDelegate extends Ble.BleDelegate {
  const MY_UUID = 0xfea6;

  function initialize() {
    BleDelegate.initialize();
    Ble.setScanState(Ble.SCAN_STATE_SCANNING);
  }

  function onScanResults(scanResults as Ble.Iterator) {
    var result = scanResults.next() as Ble.ScanResult;
    while (result != null) {
      var uuids = result.getServiceUuids();
      var service = uuids.next() as Ble.Uuid;
      while (service != null) {
        var decode_options = {
          :offset => 12,
          :endianness => Lang.ENDIAN_LITTLE,
        };

        var uuid = service
          .toByteArray()
          .decodeNumber(Lang.NUMBER_FORMAT_UINT16, decode_options);
        if (uuid == MY_UUID) {
          Ble.setScanState(Ble.SCAN_STATE_OFF);
          Ble.pairDevice(result);
          return;
        }
        service = uuids.next();
      }
      result = scanResults.next();
    }
  }

  function onConnectedStateChanged(
    device as Ble.Device,
    state as Ble.ConnectionState
  ) {
    if (state == Ble.CONNECTION_STATE_CONNECTED) {
      device.requestBond();
    }
  }
}

Parents
  • IIRC when they added bonded APIs, they said it's not yet implemented in the simulator, and likely still isn't.

    Unfortunately, constantly reconnecting a device, side-loading the app, disconnecting the device, running on the watch, reconnecting a device again is the only way I found to develop/debug BLE apps reliably. This is pain :/

Comment
  • IIRC when they added bonded APIs, they said it's not yet implemented in the simulator, and likely still isn't.

    Unfortunately, constantly reconnecting a device, side-loading the app, disconnecting the device, running on the watch, reconnecting a device again is the only way I found to develop/debug BLE apps reliably. This is pain :/

Children
No Data