Disabling Bluetooth before Light Sleep

leogs01
Posts: 9
Joined: Wed Jun 24, 2020 6:53 pm

Disabling Bluetooth before Light Sleep

Postby leogs01 » Fri Jun 26, 2020 1:37 pm

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?

noweare
Posts: 78
Joined: Tue Jul 02, 2019 11:35 am

Re: Disabling Bluetooth before Light Sleep

Postby noweare » Sun Jun 28, 2020 2:42 am

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.

leogs01
Posts: 9
Joined: Wed Jun 24, 2020 6:53 pm

Re: Disabling Bluetooth before Light Sleep

Postby leogs01 » Mon Jun 29, 2020 1:17 pm

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:
  1. case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
  2.         //adv start complete event to indicate adv start successfully or failed
  3.         if ((err = param->adv_start_cmpl.status) != ESP_BT_STATUS_SUCCESS) {
  4.             ESP_LOGE(DEMO_TAG, "Adv start failed: %s", esp_err_to_name(err));
  5.         }
  6.         else {
  7.             ESP_LOGI(DEMO_TAG, "woke up and now starting adv successfully");
  8.         }
  9.  
  10.         int64_t t_before_us = esp_timer_get_time();
  11.         vTaskDelay((1000*1) / portTICK_PERIOD_MS);
  12.         int64_t t_after_us = esp_timer_get_time();
  13.         printf("Returned from vTaskDelay, t=%lld ms, delayed for %lld ms\n",
  14.                 t_after_us / 1000, (t_after_us - t_before_us) / 1000);
  15.  
  16.         esp_ble_gap_stop_advertising();
  17.  
  18.         break;
  19.  
  20.     case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
  21.         if ((err = param->adv_stop_cmpl.status) != ESP_BT_STATUS_SUCCESS){
  22.             ESP_LOGE(DEMO_TAG, "Adv stop failed: %s", esp_err_to_name(err));
  23.         }
  24.         else {
  25.             ESP_LOGI(DEMO_TAG, "Stopped adv successfully and now going to sleep");
  26.         }
  27.  
  28.         //below using light sleep
  29.         esp_sleep_enable_timer_wakeup(4000000);
  30.         /* Enter sleep mode */
  31.         uart_tx_wait_idle(CONFIG_ESP_CONSOLE_UART_NUM);
  32.  
  33.  
  34.         ESP_ERROR_CHECK(esp_light_sleep_start());
  35.  
  36.         esp_ble_gap_start_advertising(&ble_adv_params);
  37.  
  38.  
  39.         break;
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.

Who is online

Users browsing this forum: No registered users and 138 guests