2024-12-04 06:38 AM
Hello
For now, I have a Bluetooth application that sends data through a custom app with notify.
I see my device on the ST bluetooth tool box with my data.
However, to update my application, I want to send data only if I am correctly connected to my phone to not miss data.
I tried to work with aci_hal_get_link_status() function but the status stay at 0.
Here's a snippet of my code :
uint8_t link_status = 0;
uint16_t link_connection_handle = 0;
aci_hal_get_link_status(&link_status,&link_connection_handle);
main_CreateBufferBle("color:red\n size:1.5\n length:100 \n",0,count);
Custom_APP_Send_Data(0);
So I do see the data on my phone but the link status and link connection handle stay at 0.
I haven't found an example of using this function so I might use it wrongly.
Kind regards,
Pierre Lobert
Solved! Go to Solution.
2024-12-13 05:21 AM
To check if the device is connected you can use in custom_app.c the switch case with the event CUSTOM_CONN_HANDLE_EVT and CUSTOM_DISCON_HANDLE_EVT. Here you can add some flag t know if you are connected or not.
Concerning the advertising. To cut the connection and the advertising you can use these two function :
hci_disconnect(CurrentConnectionHandle,0x13);
UTIL_SEQ_SetTask(1 << CFG_TASK_ADV_CANCEL_ID, CFG_SCH_PRIO_0);
And to restart the advertising
`APP_BLE_Init();`
That maybe not the best option but these are the option we found that work
2024-12-06 05:26 AM
I have found that I misuse it but it still does not work
I change like this :
uint8_t link_status[8]; uint16_t link_handles[8]; tBleStatus status; foo() { status = aci_hal_get_link_status(link_status, link_handles); main_CreateBufferBle("color:red\n size:1.5\n length:100 \n",0,count); Custom_APP_Send_Data(0); }
With this, status = 1, it came from the line
if ( resp.Status ) return resp.Status;
inside aci_hal_get_link_status
2024-12-13 05:21 AM
To check if the device is connected you can use in custom_app.c the switch case with the event CUSTOM_CONN_HANDLE_EVT and CUSTOM_DISCON_HANDLE_EVT. Here you can add some flag t know if you are connected or not.
Concerning the advertising. To cut the connection and the advertising you can use these two function :
hci_disconnect(CurrentConnectionHandle,0x13);
UTIL_SEQ_SetTask(1 << CFG_TASK_ADV_CANCEL_ID, CFG_SCH_PRIO_0);
And to restart the advertising
`APP_BLE_Init();`
That maybe not the best option but these are the option we found that work