Hi ,
I am trying to advertise HID Keyboard Example forever untill the device is powered off
Please let me know how to do this and also how to power optimise.
Kind Regards, Ven
Hi ,
I am trying to advertise HID Keyboard Example forever untill the device is powered off
Please let me know how to do this and also how to power optimise.
Kind Regards, Ven
In the ble_app_hids_keyboard example you have 6 advertising modes:
typedef enum
{
BLE_NO_ADV, /**< No advertising running. */
BLE_DIRECTED_ADV, /**< Direct advertising to the latest central. */
BLE_FAST_ADV_WHITELIST, /**< Advertising with whitelist. */
BLE_FAST_ADV, /**< Fast advertising running. */
BLE_SLOW_ADV, /**< Slow advertising running. */
BLE_SLEEP, /**< Go to system-off. */
} ble_advertising_mode_t;
The first time you start up your device, on reset, or wake from System OFF the mode will be BLE_NO_ADV. If you see the switch statement in advertising_start() this mode will set the mode to BLE_FAST_ADV_WHITELIST.
In the BLE_FAST_ADV_WHITELIST mode it will create a whitelist with the addresses/IRKs of the bonded devices. If there are bonded it devices it will advertise with whitelist with the APP_ADV_INTERVAL_FAST interval for APP_FAST_ADV_TIMEOUT(30) seconds, and set the mode to BLE_FAST_ADV. If there are no bonded devices it will advertise without whitelist with APP_ADV_INTERVAL_FAST interval for APP_FAST_ADV_TIMEOUT(30) seconds, and set the mode to BLE_SLOW_ADV.
In the BLE_FAST_ADV mode it will advertise without whitelist with APP_ADV_INTERVAL_FAST interval for APP_FAST_ADV_TIMEOUT(30) seconds, and set the mode to BLE_SLOW_ADV.
In the BLE_SLOW_ADV mode it will advertise without whitelist with APP_ADV_INTERVAL_SLOW interval for APP_SLOW_ADV_TIMEOUT(180) seconds, and set the mode to BLE_SLEEP.
The advertising mode will be changed when you get a BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT, see the BLE_GAP_EVT_TIMEOUT event in on_ble_evt(). BLE_SLEEP will put the chip into System OFF, any other mode will call advertising_start(); which changes to the next mode.
The mode will be set to BLE_DIRECTED_ADV on disconnect, see BLE_GAP_EVT_DISCONNECTED event in on_ble_evt(). In the BLE_DIRECTED_ADV mode it will use directed advertising with a vert short advertising interval for APP_DIRECTED_ADV_TIMEOUT(5) seconds, and set the mode to BLE_FAST_ADV_WHITELIST.
I guess you have read the documentation, there you have:
The application will stop advertising and go to system-off mode after
3 minutes and 30 seconds, if no advertising with whitelist was done OR
4 minutes, if advertising with whitelist was done.
You get these times if you add the timeouts of the different modes.
I can't tell you what modes to use, what timeouts and intervals to use in the different modes; it depends on your application. However, I can tell you how to stay in the BLE_SLOW_ADV mode forever.
In case BLE_SLOW_ADV in advertising_start() you can do:
advertising_init(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); // Has to be in this mode to advertise for more than 180 seconds
adv_params.interval = APP_ADV_INTERVAL_SLOW; // Application specific
adv_params.timeout = 0x00000000; // No timeout - advertise forever
m_advertising_mode = BLE_SLEEP; // You can remove this, the timeout will never happen
nrf_gpio_pin_set(ADV_INTERVAL_SLOW_LED_PIN_NO);
break;
Regarding power optimization, the longer and more frequent you advertise, the more power you use, so advertising forever and optimizing for power are kind of contradictions. Also, the more frequent you advertise, the quicker you will get connected, but only if there is something to connect to, if not you are only wasting power. You save power by having the chip in System OFF as much as possible, and then advertise when you know there is something to connect to. A keyboard is perfect for this, because it has buttons, so you can use a button, or all buttons, to trigger advertising.
I didn't explain what for example directed advertising or advertising with whitelist is here, but you should find other questions regarding this. If not, add a new question.
Thank You Petter.
Thank You Petter.