From d8a4a7d47b1276e7fe643eaff7f03f35fa538ac5 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 afd05be8..6120e0e0 100644 --- a/gatts_sd.go +++ b/gatts_sd.go @@ -118,7 +118,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,