My environment:
Windows 10
Eclipse Version: 2020-12 (4.18.0)
Connect IQ Device Simulator 3.2.5 (Connect IQ application is developed for Forerunner 945; Target API Level 3.2.x)
nRF52 DK (flashed with memory layout from this link https://developer.garmin.com/downloads/connect-iq/connectivity_2.0.1_115k2_with_s132_5.0.zip)
Snippet of code:
---start
// After pairing a device this will be called after the connection is made.
// ---
// device — (BluetoothLowEnergy.Device) — The device state that was changed.
// state — (Lang.Number) — A BluetoothLowEnergy.CONNECTION_STATE_* inicating the state of the connection.
// ---
function onConnectedStateChanged(device, state) {
var myService;
var ch;
var desc;
myDevice = device;
System.println("ble:onConnectedStateChanged " + myDevice + " " + connectionStateToString(state));
if (state == Ble.CONNECTION_STATE_CONNECTED) {
if (myDevice == null) {
System.println("device is not connected");
return;
}
System.println("0");
var services = myDevice.getServices();
for (var service = services.next(); service != null; service = services.next()) {
System.println(service.getUuid().toString());
}
myService = myDevice.getService(Ble.stringToUuid("0000180f-0000-1000-8000-00805f9b34fb")); // 0000180f-0000-1000-8000-00805f9b34fb is UUID for battery service
System.println("1");
if (myService == null) {
System.println("myService is null");
} else { // this else block of code is now irrelevant
ch = myService.getCharacteristic(tempAndHumidityCharacteristicUuid);
System.println("2");
desc = ch.getDescriptor(Ble.cccdUuid());
System.println("3");
desc.requestWrite([value & 0x01, 0x00]b);
System.println("4");
}
} else {
System.println("other state");
connected = false;
}
}
---end
Note: real device I am not tried, important now for me is Simulator with flashed nRF52 DK
Thanks for your any help.