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

ble sending 4 bytes of data with custom service

Hello i am trying to send 4 bytes of data over ble with custom service but im getting an unknown error and i am stuck in a dead end please help me .I am greatfull to any kind of help . 

this is my main function 

int main(void)
{

uint8_t Falll;
uint8_t temp_value;
uint8_t hum_value;
uint32_t pres_value;

    bool erase_bonds;

    I2C_init();

    BME280_Turn_On();
    NRF_LOG_INFO("bme280 open.");
    mpu6050_init();
    NRF_LOG_INFO("mpu6050 open");
    // Initialize.
    log_init();
    timers_init();
    buttons_leds_init(&erase_bonds);
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();    
    conn_params_init();
    peer_manager_init();



    application_timers_start();

    advertising_start(erase_bonds);

    // Enter main loop.
    for (;;)
    {
     //   idle_state_handle();
nrf_delay_ms(500);
Falll = MPU6050_FallDet();

temp_value=BME280_Temp_value();
NRF_LOG_INFO("TEMP value = %d ", temp_value);
NRF_LOG_FLUSH();

pres_value=BME280_Pres_value();
NRF_LOG_INFO("PRES value = %d ", pres_value);
NRF_LOG_FLUSH();

hum_value=BME280_Hum_value();
NRF_LOG_INFO("HUM value = %d ", hum_value);
NRF_LOG_FLUSH();

if(m_conn_handle != NULL ) {
pres_value_update(pres_value);
temp_value_update(temp_value);
hum_value_update(hum_value);
fall_value_update(Falll);
}

    }
}

<error> app: ERROR 536883716 [Unknown error code] at C:\Users\HP\Desktop\nrf_sdk_17\nRF5_SDK_17.0.0_9d13099\examples\MY PROJECT\ble_app_deneme\main.c:181
PC at: 0x0002BFB7
<error> app: End of error report

at 181 i have this

static void pres_value_update(presvalue)
{
ret_code_t err_code;
err_code = ble_cus_pres_level_update(&m_cus, presvalue , m_conn_handle);
if(err_code != NRF_SUCCESS &&
err_code != NRF_ERROR_INVALID_STATE &&
err_code != NRF_ERROR_RESOURCES &&
err_code != NRF_ERROR_BUSY &&
err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
{ 
APP_ERROR_CHECK(err_code);
}
}

this is my update function

uint32_t ble_cus_pres_level_update(ble_cus_t * p_cus, uint32_t presvalue, uint16_t conn_handle)
{
if (p_cus->conn_handle != BLE_CONN_HANDLE_INVALID)
{
    ble_gatts_hvx_params_t params;
    uint16_t len = sizeof(presvalue);

    memset(&params, 0, sizeof(params));
    params.type   = BLE_GATT_HVX_NOTIFICATION;
    params.handle = p_cus->bme280_presvalue_char_handles.value_handle;
    params.p_data = (uint8_t*)presvalue;
    params.p_len  = &len;

     return sd_ble_gatts_hvx(p_cus->conn_handle, &params);
}
}

this is my character add function 

    
    uint8_t bme280_pres_char_init_value [4] = {0};

    memset(&add_char_params, 0, sizeof(add_char_params));
    add_char_params.uuid              = BME280_PRESVALUE_CHAR_UUID;
    add_char_params.uuid_type         = p_cus->uuid_type;

    add_char_params.init_len          = 4;
    add_char_params.max_len           = 4;
    add_char_params.p_init_value      = bme280_pres_char_init_value;

    add_char_params.char_props.read   = 1;
    add_char_params.char_props.notify = 1;

    add_char_params.read_access       = SEC_OPEN;
    add_char_params.cccd_write_access = SEC_OPEN;

    err_code = characteristic_add(p_cus->service_handle,
                                  &add_char_params,
                                  &p_cus->bme280_presvalue_char_handles);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

Parents
  • Hi,

    I can't find any error codes corresponding to that value, but my guess would be that ble_cus_pres_level_update() is called with p_cus->conn_handle = BLE_CONN_HANDLE_INVALID, which will cause it to return without any return statement. The return code could then possibly be some garbage data from RAM (it looks like it could be a pointer-address). Try returning an error from all calls, for instance like this:

    uint32_t ble_cus_pres_level_update(ble_cus_t * p_cus, uint32_t presvalue, uint16_t conn_handle)
    {
    	if (p_cus->conn_handle != BLE_CONN_HANDLE_INVALID)
    	{
    		ble_gatts_hvx_params_t params;
    		uint16_t len = sizeof(presvalue);
    
    		memset(&params, 0, sizeof(params));
    		params.type   = BLE_GATT_HVX_NOTIFICATION;
    		params.handle = p_cus->bme280_presvalue_char_handles.value_handle;
    		params.p_data = (uint8_t*)presvalue;
    		params.p_len  = &len;
    
    		 return sd_ble_gatts_hvx(p_cus->conn_handle, &params);
    	}
    	else
    	{
    		return BLE_ERROR_INVALID_CONN_HANDLE;
    	}
    }

    Then you can filter this error code like the others:

    static void pres_value_update(presvalue)
    {
        ret_code_t err_code;
        err_code = ble_cus_pres_level_update(&m_cus, presvalue , m_conn_handle);
        if(err_code != NRF_SUCCESS &&
        err_code != NRF_ERROR_INVALID_STATE &&
        err_code != NRF_ERROR_RESOURCES &&
        err_code != NRF_ERROR_BUSY &&
        err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING &&
        err_code != BLE_ERROR_INVALID_CONN_HANDLE)
        { 
            APP_ERROR_CHECK(err_code);
        }
    }

    Best regards,
    Jørgen

  • i think my error is caused because i cant change connection handle it stays as BLE_CONN_HANDLE_INVALID and i tried some coding and now when i connect to the device my connection handle becames 0  "m_conn_handle = 0" so it becames null what can i do to fix this thanks again for your help. 

    Best regards 

    Efe

  • m_conn_handle is usually assigned in the CONNECTED event. This is from the ble_app_template example in SDK 17.0.2:

    case BLE_GAP_EVT_CONNECTED:
        NRF_LOG_INFO("Connected.");
        err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
        APP_ERROR_CHECK(err_code);
        m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
        err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
        APP_ERROR_CHECK(err_code);
        break;

Reply
  • m_conn_handle is usually assigned in the CONNECTED event. This is from the ble_app_template example in SDK 17.0.2:

    case BLE_GAP_EVT_CONNECTED:
        NRF_LOG_INFO("Connected.");
        err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
        APP_ERROR_CHECK(err_code);
        m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
        err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
        APP_ERROR_CHECK(err_code);
        break;

Children
No Data
Related