2025-06-23 8:17 AM
P-Nucleo STM32WB55
I have two 3-axis accelerometers & toe temperature sensors on an I2C bus. I taking measurements at 1 Hz.
I would like to send this data over BLE. Every tutorial so far seems to skip how to read the data into a characteristic & then send it. At this point I am only interested in broadcasting.
I've managed to set up an attribute for reading, given the service its names. I can see the device & the service advertised on my phone via ST's BLE app. So how do I get the data into the service?
I'm going around in circles here!!
Please no "have you looked at the examples", yes I have they aren't making any sense to me, I need to talk to a human about this.
2025-06-25 7:52 AM - edited 2025-06-25 7:53 AM
Thankyou, yes, I watched the series prior to posting & have watched it since. It just doesn't go into the detail needed & skips bits of information on how to just do basic operations with BLE at a code level. Also its at least 4 years out of date with the current examples.
I've even did an online course that says it was specifically for the STM32WB55 which also fails to just go into the basic API calls to use BLE but spent a lot of time explaining what BLE was. So I get the whole layer thing, the services, attributes, characteristics, how to flash the firmware onto the M0, how to set up in CubeIDE, etc. Just not how to populate said characteristics with data.
Find attached my project, I'm reading data from 2 x ADT7410 temperature sensors & 2x ADXL345 3-axis accelerometers over an I2C bus. Currently I'm sending this over UART via the ST-Link to a terminal on my laptop.
I would like to also broadcast the same data via BLE. As it stands I can see the board when I open up ST BLE Toolbox, so I know its advertising OK.
2025-06-26 4:37 AM
Hello,
I have modified your project and moved your code to custom_app.c file.
In the while loop there should be only MX_APPE_Process() function for running the sequencer.
If you have a look at Custom_APP_Init() function, you will see there a task for reading data from sensors and updating the characteristic value. This task is set to run periodically each second.
You can update the characteristic value with Custom_STM_App_Update_Char() function as it is done in sensor_update() function. I have increased the length of the characteristic just for demonstration, you can change the length in STM32CubeMX configuration. Variable "data" is used for sending the values, you can add there your own real values from the sensors. If you open ST BLE Toolbox and enable notification in Sensors service, you can see how the value is changing each second. I'm attaching the project also with git, so you can see the changes in any git client.
Please let me know if you need any further explanation.
Best regards,
Filip Kremen
2025-06-30 2:21 AM
Hi thankyou Filip, this is making much more sense now.
As far as the "data" variable goes, I'm assuming that this has to be uint8_t for transmission. In which case will I have to parse my floats to 4 x uint8_t prior to transmission?
2025-06-30 4:10 AM
Hello,
yes, that's correct. The input parameter for function Custom_STM_App_Update_Char() is an array of uint8_t.
You can work with bytes on the MCU and then convert it to floats in your mobile app, however you have to implement it in your own mobile app.
Best regards,
Filip Kremen
2025-06-30 6:18 AM - edited 2025-06-30 6:23 AM
I've added my sensors following the config you provided each with its own service & characteristic, see below
When I check using LightBlue I can see the device, link to it & read the characteristics of each service. The only problem now is that the values read are all the same 0x0000C341?
The values coming through the UART are as expected. Any idea what I'm not getting here?
union sensor_val
{
float sensor_float;
uint8_t sensor_bytes[4];
};
void sensor_update(void)
{
/* Temperature sensors */
union sensor_val temp_val_0;
union sensor_val temp_val_1;
ADT7410_ReadTemp(&temp_0);
temp_val_0.sensor_float = temp_0.deg_data;
ADT7410_ReadTemp(&temp_1);
temp_val_1.sensor_float = temp_1.deg_data;
printf("Temperature sensor 0 : %f\r\n", temp_0.deg_data);
printf("Temperature sensor 1 : %f\r\n", temp_1.deg_data);
/* Accelerometers */
acceleration_t ADXL345_data_0;
union sensor_val accel_x_0;
union sensor_val accel_y_0;
union sensor_val accel_z_0;
acceleration_t ADXL345_data_1;
union sensor_val accel_x_1;
union sensor_val accel_y_1;
union sensor_val accel_z_1;
ADXL345_ReadAcc(&acc_0, &ADXL345_data_0);
accel_x_0.sensor_float = ADXL345_data_0.ax;
accel_y_0.sensor_float = ADXL345_data_0.ay;
accel_z_0.sensor_float = ADXL345_data_0.az;
ADXL345_ReadAcc(&acc_1, &ADXL345_data_1);
accel_x_1.sensor_float = ADXL345_data_1.ax;
accel_y_1.sensor_float = ADXL345_data_1.ay;
accel_z_1.sensor_float = ADXL345_data_1.az;
Custom_STM_App_Update_Char(CUSTOM_STM_T_0, (uint8_t *)&temp_val_0.sensor_bytes);
Custom_STM_App_Update_Char(CUSTOM_STM_T_1, (uint8_t *)&temp_val_1.sensor_bytes);
Custom_STM_App_Update_Char(CUSTOM_STM_X_0, (uint8_t *)&accel_x_0.sensor_bytes);
Custom_STM_App_Update_Char(CUSTOM_STM_Y_0, (uint8_t *)&accel_y_0.sensor_bytes);
Custom_STM_App_Update_Char(CUSTOM_STM_Z_0, (uint8_t *)&accel_z_0.sensor_bytes);
Custom_STM_App_Update_Char(CUSTOM_STM_X_1, (uint8_t *)&accel_x_1.sensor_bytes);
Custom_STM_App_Update_Char(CUSTOM_STM_Y_1, (uint8_t *)&accel_y_1.sensor_bytes);
Custom_STM_App_Update_Char(CUSTOM_STM_Z_1, (uint8_t *)&accel_z_1.sensor_bytes);
}
2025-07-01 1:28 AM
Hello,
could you please send me the project again?
Thank you.
Best regards,
Filip Kremen
2025-07-01 2:52 AM - edited 2025-07-01 7:01 AM
Thanks, find attached.
I routed some debugger messages to the UART from the Custom_STM_App_Update_Char() function which which report that the aci_gatt_update_char_value() returns BLE_STATUS_SUCCESS for every characteristic.
I further noticed that the value is different today, it alternates between 0x0000B041 and 0x0080B041 for all characteristics.
2025-07-02 12:13 AM
Hello,
I have checked your project, and I think that you haven't assigned unique UUID for each service and characteristic. (all are 00 00)
I couldn't see all the services and I also couldn't read properly the characteristics. Please change the UUID for each service and characteristic and let me know if you can continue with your project.
Thank you.
Best regards,
Filip Kremen
2025-07-03 2:27 AM
Ahhh yes thankyou that appears to be it!
I naively assumed that MX would autogenerate the UUID for each characteristic.
Thanks again for walking me through this. Its all making so much more sense now.
2025-07-03 5:13 AM
Just a note, ST BLE Toolbox crashes when I connect the device yet LightBlue has no problems.