cancel
Showing results for 
Search instead for 
Did you mean: 

BlueNRG-LP I am not able to send raw value (or External sensor)over BLE

Nikhil Gayke
Associate III

I have STEVAL-IDB011V1 board i want to send raw data or externa sensor data over BLE i have modified BLE sensor Demo example the firmware link is attached with this. I getting error like Failed to read from characteristics properly.@Sebastien DENOUAL​ @Salvo​ @Salvatore DI SALVO​ @Bluetooth® LE Application Development’​ @BlueNRG-LP Hands-On: Expanding Bluetooth​ @Salvatore DI SALVO​ @st

https://drive.google.com/file/d/1eW1U4etTRc4LxzT4VK90WwzSKMZ7jJxI/view?usp=sharing

1 ACCEPTED SOLUTION

Accepted Solutions
Sebastien DENOUAL
ST Employee

HI @Nikhil Gayke​ ,

I tested your code together with Smartphone debug app (BLE scanner) and was able to get read function working.

Looks in the aci_gatt_srv_read_event function you were returning BLE_ATT_ERR_APPL_MIN error when reading batCharHandle. Because of this error, result is indeed not valid and not disppaly on smartphone side.

I also added descriptor in your Bat Characteristic definition.

Please note that code examples from this SDK are optimized in terms of RAM. So to add a characteristic or a service, you should update SensorDemo_Config.h to take new number of characteristics. More detaisl in SDK documentation.

FYI, I attached my modified gatt_db.h to make things working - Was a quick and dirty test - sorry if I didn't comment my modifications.

Regards,

Sebastien.

View solution in original post

7 REPLIES 7
Sebastien DENOUAL
ST Employee

HI @Nikhil Gayke​ ,

I tested your code together with Smartphone debug app (BLE scanner) and was able to get read function working.

Looks in the aci_gatt_srv_read_event function you were returning BLE_ATT_ERR_APPL_MIN error when reading batCharHandle. Because of this error, result is indeed not valid and not disppaly on smartphone side.

I also added descriptor in your Bat Characteristic definition.

Please note that code examples from this SDK are optimized in terms of RAM. So to add a characteristic or a service, you should update SensorDemo_Config.h to take new number of characteristics. More detaisl in SDK documentation.

FYI, I attached my modified gatt_db.h to make things working - Was a quick and dirty test - sorry if I didn't comment my modifications.

Regards,

Sebastien.

Nikhil Gayke
Associate III

Thank you @Sebastien DENOUAL​ 

can i know what sequence of event happening after the connection complete

 if(connected)

{

AxesRaw_t acc_data;

   /* Activity Led */

   BSP_LED_Toggle(BSP_LED1);  

   

if (GetAccBno(&acc_data) == 1) 

{

Bno_Update(&acc_data);

    }

  }

Is it like that we we connect to phone we will get data from sensor and update that data in attribute table if i am not wrong?

uint8_t GetAccBno(AxesRaw_t * acceleration_data)

{

 int temp=1;

if(temp)

{

get_data();

acceleration_data->AXIS_X=Acc_x;

acceleration_data->AXIS_Y=Acc_y;

acceleration_data->AXIS_Z=Acc_z;

recieve_flag=0;

return 1;

}

else

{

return 0;

}

}

tBleStatus Bno_Update(AxesRaw_t *data)

{  

 uint8_t buff[6];

 tBleStatus ret;

 HOST_TO_LE_16(buff,-data->AXIS_Y);

 HOST_TO_LE_16(buff+2,-data->AXIS_X);

 HOST_TO_LE_16(buff+4,-data->AXIS_Z);

 ret = aci_gatt_srv_notify(connection_handle, bnoCharHandle + 1, 0, 6, buff);

 if (ret != BLE_STATUS_SUCCESS){

  PRINTF("Error while updating Acceleration characteristic: 0x%02X\n",ret) ;

  return BLE_STATUS_ERROR ;

 }

 return BLE_STATUS_SUCCESS;

}

and once the user make the read request we will get the data.

void aci_gatt_srv_read_event(uint16_t Connection_Handle, uint16_t Attribute_Handle, uint16_t Data_Offset)

{

  uint8_t att_err;

  uint8_t buff[6], *data_p;

  uint16_t data_len;

  att_err = BLE_ATT_ERR_NONE;

  

if(Attribute_Handle == bnoCharHandle + 1)

  {

AxesRaw_t acc_data;

    if (GetAccBno(&acc_data) == 1)

    {

      HOST_TO_LE_16(buff, -acc_data.AXIS_Y);

      HOST_TO_LE_16(buff + 2,-acc_data.AXIS_X);

      HOST_TO_LE_16(buff + 4,-acc_data.AXIS_Z);

      data_len = 6;

      data_p = buff;

    }

    else

    {

      att_err = BLE_ATT_ERR_NONE; //Force value for test pupose

    }

  }

  aci_gatt_srv_resp(Connection_Handle, Attribute_Handle, att_err, data_len, data_p);

}

so inside the read request we are calling the get data function and we are sending that value to client then what is the use of initial GetAccBno. can you guide me what sequence of event is happing after the connection?

i have doubt in sensor demo example

inside the app_tick function they haven't call the below function. what are the reasons they not called this events confusing me regarding the event callback.

uint8_t GetTemperature(float * temperature_degC)

uint8_t GetPressure(float * pressure_hPa)

tBleStatus Press_Update(int32_t press)

tBleStatus Temp_Update(int16_t temp)

@Salvo​ @Sebastien DENOUAL​ @Salvatore DI SALVO​ @Narender Singh​ 

Nikhil Gayke
Associate III

Can we debug the code after the phone connection . if Yes how we can do that . i am not able debug after the connection.@Salvatore DI SALVO​ @Salvo​ @Sebastien DENOUAL​ @adam239955_stm1_stmicro_com​ 

Hi @Nikhil Gayke​ ,

I would advise at first to have a look to documentation "Debugging Tips & Main Guidelines"

This doc is part of BlueNRG-LP SDK doc package : SDKfolder/doc/index.html

Two points here regarding debug :

#1 Debug in low power :

Your code is implementing sleep mode (you are calling to HAL_PWR_MNGR_Request() ). When device in sleep mode, cortex-M0 core is switched off and you will loose connection with debug probe (or not be able to attach). For debug/prototyping, you can simply disable sleep mode.

#2 Debugging BLE connections :

  • if the execution is stopped for debug purpose, this will imply some delay on the radio ISR management which could lead to connection lost and bad radio behavior. IF connection already established, remote connected device may close it.
    • i.e.: if the application stops the code execution, the synchronization can’t be maintained and the connection can be lost;
    • i.e.: if the application stops the code execution, in case of advertising a back to back communication can be started.
  • As consequence, when debugging a Bluetooth LE application, please take in account that radio communication can be compromised and the connection can be lost

=> Usually, when debugging BLE communication, you can have only one break point - after that, connection is compromised.

Regards,

Sebastien.

Hi @Nikhil Gayke​ ,

Let me highlight you this doc ; PM0269 : Bluetooth LE stack v3.x programming guidelines

It explains how to develop a BLE app using BLE stackv3.x used in BlueNRG-LP.

Step1 : Advertising :

Step 2 : Connection . When Centra device connects to your device, you will receive /hci_le_connection_complete_event(). - similar event exists for disconnection.

Step3 : Once connected you can exchange data :

  • Either your smartphone perform a Read - in this case a aci_gatt_srv_read_event()
  • Either you push data to the smartphone - Here you are using notification - That means smartpoen will be informed automatically when your device will push new data. OF course, on smartphone side, you must enabled Notifications.

Regards,

Sebastien.

Nikhil Gayke
Associate III

Hi @Salvatore DI SALVO​ @Sebastien DENOUAL​ how to determine #define NUM_APP_GATT_CHAR_ATTRIBUTES_CONF (32) value for below serices and characteristic can you explain this.

note:- acc,gy,mag,rv,arvr has 6 byte data each and battery has 2 byte data

How many characteristc we can add in one service?

#define BNO_SERVICE_UUID  0x1b,0xc5,0xd5,0xa5,0x02,0x00,0xd0,0x82,0xe2,0x11,0x77,0xe4,0x40,0x1a,0x82,0x42

#define BNO_ACC_CHAR_UUID     0x1b,0xc5,0xd5,0xa5,0x02,0x00,0x0b,0x84,0xe2,0x11,0x8b,0xe4,0x80,0xc4,0x20,0xcd

#define BNO_GAY_CHAR_UUID      0x02,0x00,0x12,0xac,0x42,0x02,0x09,0xb9,0xec,0x11,0x2e,0xac,0x42,0x46,0x30,0x15

#define BNO_MAG_CHAR_UUID 0x02,0x00,0x12,0xac,0x42,0x02,0x09,0xb9,0xec,0x11,0x2e,0xac,0x12,0xcb,0xe5,0x23

#define BNO_RV_CHAR_UUID      0x02,0x00,0x12,0xac,0x42,0x02,0x09,0xb9,0xec,0x11,0x2e,0xac,0x78,0x8a,0xbb,0x2d

#define BNO_ARVR_S_RV_CHAR_UUID   0x02,0x00,0x12,0xac,0x42,0x02,0x09,0xb9,0xec,0x11,0x2e,0xac,0x08,0x47,0x44,0x35

#define Battery_SERVICE_UUID 0x02,0x00,0x12,0xac,0x42,0x02,0x09,0xb9,0xec,0x11,0x0a,0xac,0x12,0xa3,0x28,0x55

#define Battery_CHAR_UUID 0x02,0x00,0x12,0xac,0x42,0x02,0x09,0xb9,0xec,0x11,0x0a,0xac,0xee,0x24,0xf7,0xf5

uint16_t bnoAccServHandle, accCharHandle,gayCharHandle,magCharHandle,rvCharHandle,arvrCharHandle;  

uint16_t batteryServHandle, batteryCharHandle;  

extern uint16_t connection_handle;

extern BOOL sensor_board;

//BNO080 related service and characteristics

/* Client Configuration Characteristics Descriptor Definition: acceleration characteristic*/

BLE_GATT_SRV_CCCD_DECLARE(acc,

           NUM_LINKS,

           BLE_GATT_SRV_CCCD_PERM_DEFAULT,

           BLE_GATT_SRV_OP_MODIFIED_EVT_ENABLE_FLAG);

/* Client Configuration Characteristics Descriptor Definition: gayro characteristic*/

BLE_GATT_SRV_CCCD_DECLARE(gay,

           NUM_LINKS,

           BLE_GATT_SRV_CCCD_PERM_DEFAULT,

           BLE_GATT_SRV_OP_MODIFIED_EVT_ENABLE_FLAG);

/* Client Configuration Characteristics Descriptor Definition: magneto characteristic*/

BLE_GATT_SRV_CCCD_DECLARE(mag,

           NUM_LINKS,

           BLE_GATT_SRV_CCCD_PERM_DEFAULT,

           BLE_GATT_SRV_OP_MODIFIED_EVT_ENABLE_FLAG);

/* Client Configuration Characteristics Descriptor Definition: Rotation vector characteristic*/

BLE_GATT_SRV_CCCD_DECLARE(rv,

           NUM_LINKS,

           BLE_GATT_SRV_CCCD_PERM_DEFAULT,

           BLE_GATT_SRV_OP_MODIFIED_EVT_ENABLE_FLAG);

/* Client Configuration Characteristics Descriptor Definition: acceleration characteristic*/

BLE_GATT_SRV_CCCD_DECLARE(arvr,

           NUM_LINKS,

           BLE_GATT_SRV_CCCD_PERM_DEFAULT,

           BLE_GATT_SRV_OP_MODIFIED_EVT_ENABLE_FLAG);

/* Acceleration Service Characteristics Definition */

static ble_gatt_chr_def_t bno_chars[] = {

  

  /* Acceleration characteristic */

  {

    .properties = BLE_GATT_SRV_CHAR_PROP_NOTIFY | BLE_GATT_SRV_CHAR_PROP_READ,

    .permissions = BLE_GATT_SRV_PERM_NONE,

    .min_key_size = BLE_GATT_SRV_MAX_ENCRY_KEY_SIZE,

    .uuid = BLE_UUID_INIT_128(BNO_ACC_CHAR_UUID),

    .descrs = {

      .descrs_p =&BLE_GATT_SRV_CCCD_DEF_NAME(acc),

      .descr_count = 1U,

    },

  },

// Gyro characteristic 

  {

    .properties = BLE_GATT_SRV_CHAR_PROP_NOTIFY | BLE_GATT_SRV_CHAR_PROP_READ,

    .permissions = BLE_GATT_SRV_PERM_NONE,

    .min_key_size = BLE_GATT_SRV_MAX_ENCRY_KEY_SIZE,

    .uuid = BLE_UUID_INIT_128(BNO_GAY_CHAR_UUID),

    .descrs = {

      .descrs_p = &BLE_GATT_SRV_CCCD_DEF_NAME(gay),

      .descr_count = 1U,

    },

  },

// mag characteristic 

  {

    .properties = BLE_GATT_SRV_CHAR_PROP_NOTIFY | BLE_GATT_SRV_CHAR_PROP_READ,

    .permissions = BLE_GATT_SRV_PERM_NONE,

    .min_key_size = BLE_GATT_SRV_MAX_ENCRY_KEY_SIZE,

    .uuid = BLE_UUID_INIT_128(BNO_MAG_CHAR_UUID),

    .descrs = {

      .descrs_p = &BLE_GATT_SRV_CCCD_DEF_NAME(mag),

      .descr_count = 1U,

    },

  },

// RR characteristic 

  {

    .properties = BLE_GATT_SRV_CHAR_PROP_NOTIFY | BLE_GATT_SRV_CHAR_PROP_READ,

    .permissions = BLE_GATT_SRV_PERM_NONE,

    .min_key_size = BLE_GATT_SRV_MAX_ENCRY_KEY_SIZE,

    .uuid = BLE_UUID_INIT_128(BNO_RV_CHAR_UUID),

    .descrs = {

      .descrs_p = &BLE_GATT_SRV_CCCD_DEF_NAME(rv),

      .descr_count = 1U,

    },

  },

// ARVR characteristic 

  {

    .properties = BLE_GATT_SRV_CHAR_PROP_NOTIFY | BLE_GATT_SRV_CHAR_PROP_READ,

    .permissions = BLE_GATT_SRV_PERM_NONE,

    .min_key_size = BLE_GATT_SRV_MAX_ENCRY_KEY_SIZE,

    .uuid = BLE_UUID_INIT_128(BNO_ARVR_S_RV_CHAR_UUID),

    .descrs = {

      .descrs_p = &BLE_GATT_SRV_CCCD_DEF_NAME(arvr),

      .descr_count = 1U,

    },

  }

};

/* Acceleration service definition */

static ble_gatt_srv_def_t bno_service = {

  .type = BLE_GATT_SRV_PRIMARY_SRV_TYPE,

  .uuid = BLE_UUID_INIT_128(BNO_SERVICE_UUID),

  .chrs = {

    .chrs_p = bno_chars,

    .chr_count = 5U,

  },

};

//Battery related service and characteristics

/* Client Configuration Characteristics Descriptor Definition: battery characteristic*/

BLE_GATT_SRV_CCCD_DECLARE(battery,

           NUM_LINKS,

           BLE_GATT_SRV_CCCD_PERM_DEFAULT,

           BLE_GATT_SRV_OP_MODIFIED_EVT_ENABLE_FLAG);

/* battery Service Characteristics Definition */

static ble_gatt_chr_def_t battery_chars[] = {

  

  /* battery characteristic */

  {

    .properties = BLE_GATT_SRV_CHAR_PROP_NOTIFY | BLE_GATT_SRV_CHAR_PROP_READ,

    .permissions = BLE_GATT_SRV_PERM_NONE,

    .min_key_size = BLE_GATT_SRV_MAX_ENCRY_KEY_SIZE,

    .uuid = BLE_UUID_INIT_128(Battery_CHAR_UUID),

    .descrs = {

      .descrs_p =&BLE_GATT_SRV_CCCD_DEF_NAME(battery),

      .descr_count = 1U,

    },

  }

};

/* battery service definition */

static ble_gatt_srv_def_t battery_service = {

  .type = BLE_GATT_SRV_PRIMARY_SRV_TYPE,

  .uuid = BLE_UUID_INIT_128(Battery_SERVICE_UUID),

  .chrs = {

    .chrs_p = battery_chars,

    .chr_count = 1U,

  },

};

@Salvo​ @Salvatore DI SALVO​ @Sebastien DENOUAL​ 

Sebastien DENOUAL
ST Employee

Hi @Nikhil Gayke​ ,

A tool named "BlueNRG-X radio init wizzard" is part of BlueNRG-LP SDK.

This is easiest way to calculate NUM_APP_GATT_CHAR_ATTRIBUTES_CONF and other settings. This toll will generate for you conf.h file.

Now, purpose of those settings are to optimize RAM consumption. If you don't need to optimize RAM .. you can also increase number such as NUM_APP_GATT_CHAR_ATTRIBUTES_CONF with some margins.

Regards,

Sebastien.