ble_nus_data_send returns err_code:8

Hi 

I am using  NRF52840 SDK17.1 with ble_app_uart project to be a server role. Some behavior as below:

1. Use phone's app could communicate it successfully. Write and notify work normally. 

2. Use another BLE chip, do the service discover and send CCCD. Write is no problem, but after sending CCCD and write a data to 52840, I changed the code to send notification after receive a write value, but  ble_nus_data_send returns 8. Here are some more information about this. Use lightblue or nordic app do the test, there is no problem. 

Another question is that I want nrf52840 could send notify without enable CCCD, how could I do? 

Really thank you for your help! 

  • For the question "Another question is that I want nrf52840 could send notify without enable CCCD, how could I do? "  I just want to know if I could enable CCCD in the server side application layer.

  • Hi 

    If you get the invalid state error (error 8) when trying to send notifications it is most likely because the client has not written to the CCCD yet.

    Are you able to update the nus_data_handler to write something to the log when the BLE_NUS_EVT_COMM_STARTED event occurs?

    When this event occurs it means the CCCD has been set, and from this point on you are free to send notifications using the ble_nus_data_send(..) function. 

    Regarding the sniffer trace, could you share the file with me so I can have a look at the entire trace, and the data content of the packets?

    Another question is that I want nrf52840 could send notify without enable CCCD, how could I do? 

    This is not possible, since the Bluetooth specification requires the CCCD to be set before you can send notifications or indications. 

    The client is always in control of the communication. 

    It is possible to set up a server on the central side, in which case you could send write requests to this server as soon as the service discovery procedure is completed, but this will complicate the application quite a lot. 

    Best regards
    Torbjørn

Related