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

Image Transfer Demo: ble_srv_is_notification_enabled flag not set

Hello.

I connected the Image transfer service (running on a nrf52840) to another nrf52840 running a modified BLE_NUS_C service.

However, a BLE packet won't be send out, because the function ble_its_img_info_send(&m_its, &image_info) (lined below) will be aborted because of the check: 

if ((!p_its->is_info_char_notification_enabled))
    {
        printf("Failed with NRF_ERROR_INVALID_STATE, because \"is_info_char_notification_enabled\"==false\n");
        return NRF_ERROR_INVALID_STATE;
    }

uint32_t ble_its_img_info_send(ble_its_t * p_its, ble_its_img_info_t * img_info)
{
    uint8_t data_buf[1 + sizeof(ble_its_img_info_t)];
    ble_gatts_hvx_params_t hvx_params;

    VERIFY_PARAM_NOT_NULL(p_its);

    if ((p_its->conn_handle == BLE_CONN_HANDLE_INVALID))
    {
        printf("Failed: BLE_CONN_HANDLE_INVALIDn");
        return NRF_ERROR_INVALID_STATE;
    }
    if ((!p_its->is_info_char_notification_enabled))
    {
        printf("Failed with NRF_ERROR_INVALID_STATE, because \"is_info_char_notification_enabled\"==false\n");
        return NRF_ERROR_INVALID_STATE;
    }


    uint16_t length = 1 + sizeof(ble_its_img_info_t);

    data_buf[0] = 1;
    memcpy(&data_buf[1], img_info, sizeof(ble_its_img_info_t));

    memset(&hvx_params, 0, sizeof(hvx_params));
    
    hvx_params.handle = p_its->img_info_handles.value_handle;
    hvx_params.p_data = data_buf;
    hvx_params.p_len  = &length;
    hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;

    return sd_ble_gatts_hvx(p_its->conn_handle, &hvx_params);
}

When searching for the is_info_char_notification_enabled variable/flag, it is controlled in the on_write() function triggered by the BLE_GATTS_EVT_WRITE event.

/**@brief Function for handling the @ref BLE_GATTS_EVT_WRITE event from the S110 SoftDevice.
 *
 * @param[in] p_its     Nordic UART Service structure.
 * @param[in] p_ble_evt Pointer to the event received from BLE stack.
 */
static void on_write(ble_its_t * p_its, ble_evt_t const * p_ble_evt)
{
    ble_gatts_evt_write_t const * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;

    if (
        (p_evt_write->handle == p_its->tx_handles.cccd_handle)
        &&
        (p_evt_write->len == 2)
       )
    {
        if (ble_srv_is_notification_enabled(p_evt_write->data))
        {
            p_its->is_notification_enabled = true;
        }
        else
        {
            p_its->is_notification_enabled = false;
        }
    }
    else if (
        (p_evt_write->handle == p_its->img_info_handles.cccd_handle)
        &&
        (p_evt_write->len == 2)
       )
    {
        if (ble_srv_is_notification_enabled(p_evt_write->data))
        {
            printf("CHAR NOTIFICATION ENABLED\n");
            p_its->is_info_char_notification_enabled = true;                    //HERE
        }
        else
        {
            printf("CHAR NOTIFICATION DISABLED\n");
            p_its->is_info_char_notification_enabled = false;
        }
    }
    else if (
             (p_evt_write->handle == p_its->rx_handles.value_handle)
             &&
             (p_its->data_handler != NULL)
            )
    {
        p_its->data_handler(p_its, p_evt_write->data, p_evt_write->len);
    }
    else
    {
        // Do Nothing. This event is not relevant for this service.
    }
}

What does this variable/flag mean?
What is missing that it won't be set when connecting to my BLE_NUS_C service, however, it is working when connecting to the Image_Transfer_Demo Andoid APP?
How can I solve that?


Thnaks!

  • Ok. Use nRF Connect for Desktop to see what services and Characteristic UUIDs you need to use. If I remember correctly, on the mobile application you need to select whether to take a photo or to send a stream, as well as selecting the picture quality. This means that there probably is a characteristic that you need to use to send messages to the nRF telling it to either send a picture or stream, and select the quality.

  • Thanks. It works.

    The thing acctually was that the image_transfer service has a third "image_info_send" characteristic which is obviously not implemented in the BLE_NUS service. The RX and TX Characteristics of the BLE_ITS and BLE_NUS Service have the same UUID.
    That is why part of my transfer worked, but the image size info couldn't be sent.

    And yes, I modified the image transfer demo already in a way that I do not need all those controlling messages.

    THANK YOU!!

Related