BLE Advertising after light sleep

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

BLE Advertising after light sleep

Postby leogs01 » Thu Jun 25, 2020 8:22 pm

When starting light sleep using the below code, I am able to to go into light sleep and measure a current consumption of about 2mA, and when I exit light sleep and start advertising, I measure a peak consumption of about 16-20mA.
  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;
Is it okay for me continue using the above method, or do I have to use:
  1. ESP_ERROR_CHECK(esp_bluedroid_disable());
  2.         ESP_ERROR_CHECK(esp_bluedroid_deinit());
  3.         ESP_ERROR_CHECK(esp_bt_controller_disable());
  4.         ESP_ERROR_CHECK(esp_bt_controller_deinit());
before going to light sleep and then
  1.           ESP_ERROR_CHECK(esp_bt_controller_init(&bt_cfg));
  2.           ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BLE));
  3.           ESP_ERROR_CHECK(esp_bluedroid_init());
  4.           ESP_ERROR_CHECK(esp_bluedroid_enable());
  5.           ble_ibeacon_appRegister();
when waking up from light sleep. The problem with this 2nd method is that I measure a peak consumption of about 60-80mA when waking up from light sleep. I use a multimeter to measure current consumtion.

Who is online

Users browsing this forum: No registered users and 114 guests