I'm creating a beacon that advertises using BLE for one second and then goes into light sleep for 4 seconds and then wakes up again and advertises for one second. This repeats continuously.
I was wondering if you have have to repeat the process of disabling bluetooth before going into light sleep and then enabling bluetooth once you wakeup?
Disabling Bluetooth before Light Sleep
Re: Disabling Bluetooth before Light Sleep
I found this in the docs
Docs » API Reference » System API » Sleep Modes
In deep sleep and light sleep modes, wireless peripherals are powered down. Before entering deep sleep or light sleep modes, applications must disable WiFi and BT using appropriate calls (esp_bluedroid_disable(), esp_bt_controller_disable(), esp_wifi_stop()). WiFi and BT connections will not be maintained in deep sleep or light sleep, even if these functions are not called.
Docs » API Reference » System API » Sleep Modes
In deep sleep and light sleep modes, wireless peripherals are powered down. Before entering deep sleep or light sleep modes, applications must disable WiFi and BT using appropriate calls (esp_bluedroid_disable(), esp_bt_controller_disable(), esp_wifi_stop()). WiFi and BT connections will not be maintained in deep sleep or light sleep, even if these functions are not called.
Re: Disabling Bluetooth before Light Sleep
I read that part too, but I ended up coding my application such that even if I didn't disable BT using the appropriate calls, my device was able to go into light sleep after advertising and then come out of it and continue advertising before going back into light sleep. The code I used for it is below:
This saves a lot more power than disabling and enabling BT continuously but because it doesn't follow the recommended methods in the documentation, I was wondering if it was ok for me to continue doing it this way.
- case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
- //adv start complete event to indicate adv start successfully or failed
- if ((err = param->adv_start_cmpl.status) != ESP_BT_STATUS_SUCCESS) {
- ESP_LOGE(DEMO_TAG, "Adv start failed: %s", esp_err_to_name(err));
- }
- else {
- ESP_LOGI(DEMO_TAG, "woke up and now starting adv successfully");
- }
- int64_t t_before_us = esp_timer_get_time();
- vTaskDelay((1000*1) / portTICK_PERIOD_MS);
- int64_t t_after_us = esp_timer_get_time();
- printf("Returned from vTaskDelay, t=%lld ms, delayed for %lld ms\n",
- t_after_us / 1000, (t_after_us - t_before_us) / 1000);
- esp_ble_gap_stop_advertising();
- break;
- case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
- if ((err = param->adv_stop_cmpl.status) != ESP_BT_STATUS_SUCCESS){
- ESP_LOGE(DEMO_TAG, "Adv stop failed: %s", esp_err_to_name(err));
- }
- else {
- ESP_LOGI(DEMO_TAG, "Stopped adv successfully and now going to sleep");
- }
- //below using light sleep
- esp_sleep_enable_timer_wakeup(4000000);
- /* Enter sleep mode */
- uart_tx_wait_idle(CONFIG_ESP_CONSOLE_UART_NUM);
- ESP_ERROR_CHECK(esp_light_sleep_start());
- esp_ble_gap_start_advertising(&ble_adv_params);
- break;
Who is online
Users browsing this forum: Baidu [Spider] and 204 guests