Alright, so thank you so far for getting this far! I have my nordic dongle flashed and it seems to work... I think. I'm trying to read a Kinsa thermometer with the simulator.
Here's the problem: In nordic connect, I can just push "Notify" and Nordic connect gets a notification every time I take a temperature. How do I do that in code?
Here's the report from Nordic Connect:
Here's my BLE Delegate:
using Toybox.Application; using Toybox.WatchUi; using Toybox.BluetoothLowEnergy; class BleDelegate extends BluetoothLowEnergy.BleDelegate { private var blueEarView; private var kinsaUuid = BluetoothLowEnergy.stringToUuid("00000000-0068-746C-6165-4861736E694B"); private var temperatureServiceUuid = BluetoothLowEnergy.stringToUuid("00000002-0068-746C-6165-4861736E694B"); private var kinsaProfileDef = { :uuid => kinsaUuid, :characteristics => [{ :uuid => temperatureServiceUuid, :descriptors => [BluetoothLowEnergy.cccdUuid()] }] }; private var device; function initialize(view){ BleDelegate.initialize(); blueEarView = view; registerProfiles(); BluetoothLowEnergy.setScanState(BluetoothLowEnergy.SCAN_STATE_SCANNING); System.println("BleDelegate - initialize()"); } function onScanResults(scanResults) { System.println("BleDelegate - onScanResults() scanResults" + scanResults); for (var result = scanResults.next(); result != null; result = scanResults.next()) { var iter = result.getServiceUuids(); for (var uuid = iter.next(); uuid != null; uuid = iter.next()) { System.println("found uuid:" + uuid); if (kinsaUuid.equals(uuid)) { System.println("attemping connection...."); BluetoothLowEnergy.setScanState(BluetoothLowEnergy.SCAN_STATE_OFF); BluetoothLowEnergy.pairDevice(result); } } } } function onConnectedStateChanged(device, state) { System.println("BleDelegate - onConnectedStateChanged() device:" + device.getName()); var services = device.getServices(); for (var service = services.next(); service != null; service = services.next()) { System.println("service:" + service.getUuid()); var characteristic = service.getCharacteristic(temperatureServiceUuid); characteristic.requestRead(); characteristic. } } function onCharacteristicRead(characteristic, status, value) { System.println("BleDelegate - onCharacteristicRead() value:" + value); characteristic.requestRead(); } function registerProfiles() { BluetoothLowEnergy.registerProfile(kinsaProfileDef); System.println("KinsaPM - registerProfiles()"); } }
Here's the output
KinsaPM - registerProfiles() BleDelegate - initialize() BleDelegate - onScanResults() scanResultsObj: 167 BleDelegate - onScanResults() scanResultsObj: 167 BleDelegate - onScanResults() scanResultsObj: 167 found uuid:00000000-0068-746C-6165-4861736E694B attemping connection.... BleDelegate - onConnectedStateChanged() device:null service:00000000-0068-746C-6165-4861736E694B BleDelegate - onCharacteristicRead() value:[7, 1]
First, it takes forever to read the characteristic, whereas Nordic connect gets notified immediately. Second, 7,1 is a magic number that means no temperature, whereas nordic connect receives a value. Argh, what am I doing wrong?