Where to populate advertisement data and GATT tree on the fly

10 posts / 0 new
Last post
dhrishi
Offline
Last seen:3 years 6 months ago
Joined:2017-02-10 09:56
Where to populate advertisement data and GATT tree on the fly

Hi,

I am now able to populate the advertisement data and GATT services and characteristics using ke_send_msg and handle the events in user_catch_rest_hndl(). Although, I have done this in a hard coded manner.

Now, I have to do this by sending the same data over UART. I want to find the appropriate location where I can do this. What I find is, as soon as the control reaches user_app_init(), the advertisement is started. I want to control this and start advertisement whenever I get all the required data (advertisement data and GATT tree) over UART. What is the right way to do this?
Taking into consideration that the watchdog and other stuff is not affected.

Also, is there a specific function that is called by the Dialog BLE periodically that I can use for populating my data.

Device:
MT_dialog
Offline
Last seen:5 months 1 week ago
Staff
Joined:2015-06-08 11:34
Hi dhrishi,

Hi dhrishi,

The advertising of the device starts as soon as the .default_operation_adv is called, that means that the advertising starts either from the default_app_on_set_dev_config_complete() function is executed or from the default_app_on_db_init_complete() (it depends if the device has a database to create or not) so those are the two functions that you can start implementing code in order to first obtain data over UART and then start the advertising procedure. Regarding your second question there is no default function that is executed periodically in order for you to change the data, the examples that change the advertising data over time use the kernel timers, you can have a look at the ble_app_barebone example for more info on this.

Thanks MT_dialog

dhrishi
Offline
Last seen:3 years 6 months ago
Joined:2017-02-10 09:56
Hi,

Hi,

Thanks for the reply. I have quite a few questions in this regard:

1. When I start my timer in user_app_init() using app_easy_timer() call then the callback function does not get executed. Is it not allowed? How do I start a timer in user_app_init() itself?
2. Starting a periodic timer is equivalent to starting the timer again in the callback function, right? Also, I am using the timer callback delay as 100ms. The lowest value that can be set is 1 ms, right?
3. As I am working on UART, is it allowed to register uart callback for the next uart receive inside previous uart recv callback function. When I did that, I could not get the next data as my callback was never called. What is the right method for this?

Thanks,
Hrishikesh

MT_dialog
Offline
Last seen:5 months 1 week ago
Staff
Joined:2015-06-08 11:34
Hi dhrishi,

Hi dhrishi,

If the above answer was useful please mark it as accepted

1) Yes, you cannot invoke start a timer in the user_app_init() function, the system will issue a GAPM_RESET and if there was a timer it will be discarted along with other scheduled messages.

2) Yes in order for your timer to be periodic, you should reset the timer from the handler of the previous timer elapsed. The lowest value of the ke_timers is 10ms, if you set the timeout as 1 then the timer will elapse at its minimum value.

3) I am not sure i get the question, i used the uart2_async example and invoked the uart2_read() in order to begin a new UART read transaction, the callback was executed always after typing 5 characters.

Thanks MT_dialog

dhrishi
Offline
Last seen:3 years 6 months ago
Joined:2017-02-10 09:56
Thanks for clarifying point 1

Thanks for clarifying point 1) and 2)

To be specific:
I want to populate following things through UART:
1. Adv data (Action: save in an array)
2. Scan response data (Action: save in an array)
3. GATT Database one service/char at a time (Action: Send to kernel using ke_msg_send() for services and attributes)
For this, I need a function that is called periodically, through which I can receive requests from the host to take some actions (save in array or send kernel message) and send responses (and vice versa)
4. After all this is done then start advertising

So, where and how do I do all these things. Is app_on_ble_powered() or app_on_system_powered the right place to do this? If yes, what type of functionality should be included in both the functions. Also, it would be good if you could provide example of the usage of both these functions.
If not, then what is the right way to accomplish above tasks?

Thanks,
Hrishikesh

MT_dialog
Offline
Last seen:5 months 1 week ago
Staff
Joined:2015-06-08 11:34
Hi dhrishi,

Hi dhrishi,

app_on_ble_powered()和app_on_system_powered() are functions that are being invoked regularly and not only once during an active period of the 580 in the SDK5.0.4, that means that both of those callbacks can run more than once in an advertising event (that depends on the messages that the kernel has stored and has to serve) in the case of the app_on_ble_powered(), and in the case of the app_on_system_powered(). You can attach some code via the callbacks provided in the user space. You could apply code in both of these callbacks, the main difference is that in the app_on_ble_powered() you will know for sure that the BLE core is active, so in your case perhaps the app_on_system_powered() is more suitable. Please check the UM-B-051 DA1458x Software Platform Reference v1.0.pdf in section 7.1.3 in order to check their usage. Regarding the example on how to use them, there is no specific procedure, just have in mind that the code in these functions will always run when the device is active and also from those functions you can cancel the sleep under a condition (return KEEP_POWERED will keep the device awake return GOTO_SLEEP lets the device to continue with sleep mode). So from those functions i suppose that you could keep the 580 alive as long as you have UART transactions and as long as the provided advertising array isn't complete, as soon as the advertising string uart send is complete you can populate your custom array and trigger the advertising function.

Thanks MT_dialog

dhrishi
Offline
Last seen:3 years 6 months ago
Joined:2017-02-10 09:56
Thanks a lot for your answer.

Thanks a lot for your answer. It definitely is helpful.

MT_dialog
Offline
Last seen:5 months 1 week ago
Staff
Joined:2015-06-08 11:34
Hi dhrishi,

Hi dhrishi,

If any of the above answers was helpful, please mark it as Accepted.

Thanks MT_dialog

Ercei02
Offline
Last seen:1 year 9 months ago
Joined:2019-10-14 09:39
Thanks for sharing the

Thanks for sharing the characteristics and coding manners. Advertising all depends on the nature of business but ads and messages to be sent also play a vital role. I think we will have to hire a company whoSend sms from slackwith all other basic requirements. Data enhancement will bring more and more response from customers.

PM_Dialog
Offline
Last seen:1 week 5 days ago
Staff
Joined:2018-02-08 11:03
Hi Ercei02,

Hi Ercei02,

Thanks for posting on our Bluetooth forums. Can you please clarify which your issue is? I’d suggest you to create a new forum thread, as this one is very old.

Thanks, PM_Dialog