2023-09-09 06:45 AM
Hello,
I am pretty new to BLE-Application and trying to build my first own app using the STM-BLE-Stack.
I've been writing about my process in a previous thread (https://community.st.com/t5/stm32-mcus-wireless/stm32wb-ble-update-char-from-main-c/m-p/589220#M16405), but want to be more precise now.
My STM32 should work as server and send sensor data to a client, at first just a smartphone using the BLE Toolbox application.
I generated a project according to ST's YouTube-Tutorial (https://www.youtube.com/watch?v=CKYWy7LKL68&list=PLnMKNibPkDnG9JRe2fbOOpVpWY7E4WbJ-&index=16) and can read and write to my characteristics from my smartphone.
Now I want to update a BLE-characteristic from my main application, i.e. main.c. I want to transfer sensor data and send a notification to my client that new data is available.
I know about the functions
aci_gatt_update_char_value()
and in my case (cause I used the custom template)
Custom_STM_App_Update_Char()
, but they are causing HardFaults if I'm calling them in my main-loop.
Can you help me to find the simpliest way to transfer custom data using the BLE interface and triggering a notification that new data is available from the main-function?
Many thanks in advance :)
Solved! Go to Solution.
2023-09-09 07:15 AM - edited 2023-09-09 07:18 AM
Hello again @werner_f
You can keep the program as it is and Always test if Custom_STM_App_Update_Char() is updated . You can change a variable value that you can include in the main.c (as we have done in the first case) and when this variable's value change you can create an acknowledge in the main function (don't forget to send this variable back to the original value to stop this acknowledge and wait for the next one).
Best regards.
II
2023-09-09 07:15 AM - edited 2023-09-09 07:18 AM
Hello again @werner_f
You can keep the program as it is and Always test if Custom_STM_App_Update_Char() is updated . You can change a variable value that you can include in the main.c (as we have done in the first case) and when this variable's value change you can create an acknowledge in the main function (don't forget to send this variable back to the original value to stop this acknowledge and wait for the next one).
Best regards.
II
2023-09-10 06:19 AM
Thank you very much. With your help I could manage to write some code so I can easilly send data from my main program code using BLE.
If anybody else has some problems to start with here is how I did it:
uint8_t ble_flag;
uint8_t ble_buffer[247];
//Prototype
void ble_updateChar(uint8_t char_identifier);
//External buffer
extern uint8_t ble_flag;
extern uint8_t ble_buffer[]
//Function
void ble_updateChar(uint8_t char_identifier)
{
//Check for idetifier to update
if(char_identifier == myChar)
{
//Check if new data is available
if(ble_flag == ON)
{
//Update Char
Custom_STM_App_Update_Char(CUSTOM_STM_CHAR, ble_buffer);
//Reset Flag
ble_flag = OFF;
}
}
}
//Fill BLE-Buffer with data
ble_buffer[0] = 5;
//Send buffer
ble_flag = ON;
ble_updateChar(myChar);
I know this is a really quick and dirty approach and definitely this can be done better.
But in my opinion it was quite difficult to start and the resources and tutorial aren't that straight forward like I wanted them to be.
So maybe this helps somebody with the first BLE-Steps on a STM32WB-Chip. I think from there you can improve your code and make something better and more professional.
2023-09-10 06:23 AM
Happy to now about your progress. I wish to see more as soon as possible.
Best regards.
II
2024-05-09 01:49 AM
Hi @werner_f
Could you be knowing the cause of the disconnections in the st ble toolbox app whenever the notifications are enabled? i have been following up your response but am getting disconnections from the app every time i enable notifications
thank you so much for the great work