This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to make the ble_app_uart demo not advertising once power on?

Hi guys, I design one custom application based on the ble_app_uart demo and find the device is advertising when power on. I want to set it auto connect once the device has bonded. I add the dm APIs into this project and modify the adverting_init() and advertising_start(), which do as the hid keyboard project, but nothing change. It seems the bond info does not write to the flash correctly. could you guide me how to make it true ? with the flow better.

Thanks a lot.

  • Hi Jimlin, What do you mean by not advertising and "auto connect" ? A connection can only be made when the peripheral advertises and the central send connect request to start the connection. In the case of HID device, you can see that it got connected almost immediatelly after start up and appear to not advertise at all. But actually it does. It just get connected very fast right at the few first advertising packets so that you sometime couldn't scan and capture the advertising packet from other scanner. This behaviour was due to the fact that the HID is connected automatically by the phone OS without any app needed. In your case that you want to use ble_app_uart, you would need to have the app running and try to connect constantly.

  • Hi Hung Bui, As your description, I know it needs the app running to find the device and connect every time on ble_app_uart project. What I want is to make it run as the hid keyboard, which not need to connect once it has bonded yet. So, as my understand, add the device manager function could store the bond info, and let the device to connect to the app auto, instead of connecting by hand every time when power on. But, something miss or wrong so that it does not work correctly, still advertising and wait for the app to connect. That is what I ask for help. Only hid could do it like this? How could I make it auto connect? Any guide or document should be better. Thanks for your reply.

  • @As mentioned, only HID is connected automatically by the operating system (Android or iOS).

    If you can create your mobile app running in the background and do scanning and connecting constantly, you can achieve the same thing. You don't need to have the end user to press the connect button by hand. However, be aware that running an app in the background to scan continuously may consume the phone's power more.

  • So, you mean that it could not use the BLE_DIRECTED_IND to reconnect with the bonded host yet, right? If so, the slave how to connect to the certain host when more than one app in different phone run? I think the other demo such as HRS, could connect to the bonded host when power restart, which is also not enum as HID class. Maybe I do not make my question quite clear. What I want is the UART connect with the APP only one time, and could connect again auto when disconnected, if NO BOND_DELETE_BUTTON pressed.

  • You meant this flag BLE_GAP_ADV_TYPE_ADV_DIRECT_IND? It's the directed advertising.

    However, it doesn't mean the phone OS need to connect to the device when it receive the advertising packet. What directed advertising does is to tell other device that it advertising exclusively for one central device only.

    There is only one connection between a central (phone) and the peripheral. When there are several apps running on the phone that communicate with the same device, they share the same connection.

    As long as your app is running, you can choose the option to let the operating system to reconnect automatically when the link is lost. Please have a look at the connectGatt function [here](developer.android.com/.../BluetoothDevice.html, boolean, android.bluetooth.BluetoothGattCallback)). There is an option to choose to autoConnect

    But if your app is closed the command will no longer be valid. You can of course keep it run in background as a service.

Related