cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WB55 - Update Characteristic and send a Notification

werner_f
Associate II

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 :)

 

1 ACCEPTED SOLUTION

Accepted Solutions
Issamos
Lead II

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

View solution in original post

4 REPLIES 4
Issamos
Lead II

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

 

 

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];​

 

  • Make ble_flag and ble_buffer globally accessable in custom_app.c using "extern".
    Also create a function ble_updateChar() in custom_app.c wich is called to update the specific characteristic.

 

//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;
		}
	}
}

 

  • Take care of the parameters for the Custom_STM_App_Update_Char()-Function. The first item is the CharOpcode and varies according to the name of your characteristic. You can find your correct Opcode for the characteristic you want to update in custom_stm.h. Edit the given function.
    Additionally, I am using the custom parameter char_parameter in my function. Like this, I can select my desired characteristic I want to update when calling ble_updateChar(char_parameter). In case you have multiple char's you want to access copy the if-condition and edit the CharOpcode,... according to it.
  •   Now you can fill your ble_buffer[] anywhere in the code you want with data. When finished, you can set your "new data indicator" ble_flag to 1 and call the function ble-updateChar(myChar).

 

//Fill BLE-Buffer with data
ble_buffer[0] = 5;
	
//Send buffer
ble_flag = ON;
ble_updateChar(myChar);​

 

  • The ble_updateChar() function is called, updates the characteristic and sends a notification to your client, e.g. the smartphone app "BLE Toolbox".

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.

Happy to now about your progress. I wish to see more as soon as possible.

Best regards.

II

PMato.1
Associate II

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