From ec80e0111e1072e6e7cf6553ac403f5657616724 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 24 Dec 2023 13:54:19 +0100 Subject: [PATCH] softdevice: don't send a notify/indicate without a CCCD sd_ble_gatts_hvx_noescape can only be called when the notify/indicate permission is set (and therefore a CCCD has been added). Without it, it will just return an error. This fixes a problem I found on the PineTime, while implementing the battery service. --- gatts_sd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatts_sd.go b/gatts_sd.go index 824a64bb..5e9852f0 100644 --- a/gatts_sd.go +++ b/gatts_sd.go @@ -123,7 +123,7 @@ func (c *Characteristic) Write(p []byte) (n int, err error) { } connHandle := currentConnection.Get() - if connHandle != C.BLE_CONN_HANDLE_INVALID { + if connHandle != C.BLE_CONN_HANDLE_INVALID && c.permissions&(CharacteristicNotifyPermission|CharacteristicIndicatePermission) != 0 { // There is a connected central. p_len := uint16(len(p)) errCode := C.sd_ble_gatts_hvx_noescape(connHandle,