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.
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;
Is it okay for me continue using the above method, or do I have to use:
ESP_ERROR_CHECK(esp_bluedroid_disable());
ESP_ERROR_CHECK(esp_bluedroid_deinit());
ESP_ERROR_CHECK(esp_bt_controller_disable());
ESP_ERROR_CHECK(esp_bt_controller_deinit());
before going to light sleep and then
ESP_ERROR_CHECK(esp_bt_controller_init(&bt_cfg));
ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BLE));
ESP_ERROR_CHECK(esp_bluedroid_init());
ESP_ERROR_CHECK(esp_bluedroid_enable());
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.