This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I know I can send a packet with data length 1~20 using sd_ble_gatts_hvx(), then how to send an empty notification packet(data length 0)?

Hi, I am using nrf51822 (128k). Softdevice 6.0 (s110), SDK 5.2. How can I send an empty notification packet (data length 0) to master device? If I send a packet with data length 0, nrf51822 reset...

Thank you.

  • Sorry for not being helpful, but... why dont You just ignore this one byte?

  • Hi

    I think it would be better not to send any notification instead of trying to send an empty nofification, or why would you want to send an empty packet? The way BLE works is that empty packets (i.e. with no payload data) are sent periodically between central and peripheral when they are connected and you are not sending data. How frequently that happens is determined by the connection interval that you specify in your code.

    Perhaps the softdevice does not accept payload with length 0 so it throws an error which is captured by the app_error_handler, usually implemented at the top of the main file of any BLE example in the nRF51 SDK. By default, the app_error_handler will make the device reset but you could uncomment ble_debug_assert_handler and put a breakpoint there to see the error_code and where in the code it was generated.

  • Hi

    If you would like to send an empty notification, the hvx_params have to be something like this:

    unit8_t buffer[20], len=0;
    
    hvx_params.p_data = &buffer[0];
    hvx_params.p_len = &len;
    hvx_params.offset = 0;
    hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
    hvx_params.handle = 0x000F
    
    sd_ble_gatts_hvx(gs_conn_handle, &hvx_params);
    
  • Thank you very much! It is strange, I tried in this way two days ago, but my nrf51822 resets when send zero-length-data packet. But not works without reset~

    I will test more.

  • Please thank him by accepting his answer, and please remember to vote: devzone.nordicsemi.com/.../ .

Related