Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Cannot send string data over BLE to iOS Nordic Connect app from board.

Hi everyone, so I have been trying to enable the nRF52840 to send notifications to the Nordic Connect app via a custom characteristic. The app can detect the custom service when it's being advertised and it connects successfully, but even after I enable Notifications, I cannot receive anything.

I used the ble_app_uart project and changed the main() function so that instead of being in an idle state, it repeatedly tries to send data in an infinite loop:

    BTLE_data[0] = '0';
    BTLE_data[1] = '1';
    BTLE_data[2] = '2';
for (;;) {

      ret_code_t err_code;
    
      uint8_t string[] = "serial updated\n\r";
      uint16_t length = sizeof(string);
    
      do
      {
        
          err_code = ble_nus_string_send(&m_nus, string, &length);
          if ( (err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_BUSY) )
          {
              APP_ERROR_CHECK(err_code);
          }
      } while (err_code == NRF_ERROR_BUSY);
    }

The other change I made is adding the custom characteristic.

/**@brief Function for adding the Custom Value characteristic.
 *
 * @param[in]   p_nus        Custom Service structure.
 * @param[in]   p_nus_init   Information needed to initialize the service.
 *
 * @return      NRF_SUCCESS on success, otherwise an error code.
 */
static uint32_t custom_char_add(ble_nus_t * p_nus, const ble_nus_init_t * p_nus_init)
{
    uint32_t            err_code;
    ble_gatts_char_md_t char_md;
    ble_gatts_attr_md_t cccd_md;
    ble_gatts_attr_t    attr_char_value;
    ble_uuid_t          ble_uuid;
    ble_gatts_attr_md_t attr_md;

    ble_uuid128_t custom_char_uuid = {CUSTOM_CHAR_UUID_BASE};

    memset(&char_md, 0, sizeof(char_md));

    char_md.char_props.read   = 0;
    char_md.char_props.write_wo_resp  = 1;
    char_md.char_props.notify = 1; 
    char_md.p_char_user_desc  = NULL;
    char_md.p_char_pf         = NULL;
    char_md.p_user_desc_md    = NULL;
    char_md.p_cccd_md         = NULL; 
    char_md.p_sccd_md         = NULL;

    memset(&attr_md, 0, sizeof(attr_md));

    attr_md.read_perm  = p_nus_init->custom_value_char_attr_md.read_perm;
    attr_md.write_perm = p_nus_init->custom_value_char_attr_md.write_perm;
    attr_md.vloc       = BLE_GATTS_VLOC_STACK;
    attr_md.rd_auth    = 0;
    attr_md.wr_auth    = 0;
    attr_md.vlen       = 0;

    ble_uuid.type = p_nus->uuid_type;
    ble_uuid.uuid = CUSTOM_CHAR_UUID;

    err_code = sd_ble_uuid_vs_add(&custom_char_uuid, &p_nus->uuid_type);	// Add new base UUID for add characteristic UUID
    VERIFY_SUCCESS(err_code);

    memset(&attr_char_value, 0, sizeof(attr_char_value));

    attr_char_value.p_uuid    = &ble_uuid;
    attr_char_value.p_attr_md = &attr_md;
    attr_char_value.init_len  = sizeof(uint8_t);
    attr_char_value.init_offs = 0;
    attr_char_value.max_len   = sizeof(uint8_t);

    err_code = sd_ble_gatts_characteristic_add(p_nus->service_handle, &char_md,
                                               &attr_char_value,
                                               &p_nus->custom_value_handles);
                                               
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    return NRF_SUCCESS;
}

I tried to figure out what's going on by setting breakpoints, and it seems like it gets stuck in the execution of ble_nus_string_send() because p_nus->conn_handle = BLE_CONN_HANDLE_INVALID.

Any suggestions?

Parents Reply Children
No Data
Related