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

Custom UART BLE Read fails

Hello, I have a custom program based on the uart example. I can write to the device, but sending to the master fails. I call the SendString code, but p_nus->is_notification_enabled is always false. Looking through the code, the only place this flag gets set true is in:

static void on_write(ble_nus_t * p_nus, ble_evt_t * p_ble_evt)
{
    ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
    if ((p_evt_write->handle == p_nus->rx_handles.cccd_handle)  && (p_evt_write->len == 2))
    {
        if (ble_srv_is_notification_enabled(p_evt_write->data))
        {
            p_nus->is_notification_enabled = true;
        }
        else
        {
            p_nus->is_notification_enabled = false;
        }
    }
    else if ((p_evt_write->handle == p_nus->tx_handles.value_handle) && (p_nus->data_handler != NULL))
    {
        p_nus->data_handler(p_nus, p_evt_write->data, p_evt_write->len);
    }
    else
    {
        // Do Nothing. This event is not relevant for this service.
    }

Can anyone explain where the message with p_evt_write->handle == p_nus->rx_handles.cccd_handle and with a length of 2 comes from? If this part of the code is never called, then i cant send any data to the master. Much appreciated.

Parents
  • That part of the code called when you enable notification from master. For example in Master Control Panel in Android connect to your device, choose service and then on right hand side of characteristic you will see three down arrows. Press on them and notification will be enabled. If you are using your own application then you need to enable notification in your application before the first SendString used in the device

  • Hi Alex, Thanks again for all the information and I am sorry for all the questions. Is this the only way to send data to the application? The reason I ask is I had the communication working perfectly, but lost the nrf project code when my PC crashed. I have the original windows App code and I didn't have to enable notifications. I have re-written the nrf51 code, but am getting the above error. Is there a way to send data to the server without notifications? I only need to read about 100 bytes of configuration data on connection from the app, and I don't need to notify when it gets changed. Again, thanks for all the help.

Reply
  • Hi Alex, Thanks again for all the information and I am sorry for all the questions. Is this the only way to send data to the application? The reason I ask is I had the communication working perfectly, but lost the nrf project code when my PC crashed. I have the original windows App code and I didn't have to enable notifications. I have re-written the nrf51 code, but am getting the above error. Is there a way to send data to the server without notifications? I only need to read about 100 bytes of configuration data on connection from the app, and I don't need to notify when it gets changed. Again, thanks for all the help.

Children
No Data
Related