This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to force the notification to turn on from the server not the client?

uint16_t buffer[4];
	
buffer[0] = p_nus->handles1.cccd_handle;                  // cccd handle
buffer[1] = 2;                                            // cccd attribute size = 2
buffer[2] = 1;                                            // 1 = enable notifications
buffer[3] = crc16_compute((uint8_t *)buffer, 6, NULL);     // CRC-CCITT (0xFFFF)
err_code = sd_ble_gatts_sys_attr_set(p_ble_evt->evt.gap_evt.conn_handle, (uint8_t*)(buffer), 8, BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS); 

if(err_code == NRF_SUCCESS)
{
    p_client->is_notification_enabled1 = true;  // Enable notification
}

I add this code in 'static void on_connect(ble_nus_t * p_nus, ble_evt_t const * p_ble_evt) '  on the sever. But I still got an err_code NRF_ERROR_INVALID_DATA. Softdevice is s132nrf52611. Any suggestions to force the notification? I use the SDK version 15.3.0.

Parents
  • Hello,

    Any suggestions to force the notification?

    I am not sure I understand exactly what you mean here.

    A server / peripheral may not force the client / central to accept notifications. The notification has to be enabled by the central / client itself, before the peripheral / server can start sending notifications.
    The only time that the peripheral may send notifications "unprompted" to the central, is if the two devices are bonded, and the central has enabled the notification in a previous connection.
    Perhaps if you could detail your problem or use-case some more, I would be able to advise you better.

    If this is not what you were asking about, please elaborate on what you would like to achieve.

    Best regards,
    Karl 

  • Hi Karl

    I want to achieve the effect of using NRF connect to automatically enable notification as soon as Bluetooth is connected, without needing to click the button on the app. I have successfully implemented this effect in the sample program(uart).  But in my project, I changed the characteristic UUID and added notify write and write_no_resp to both of them.

Reply Children
No Data
Related