In my code, I set the scan parameters to only accept devices from the white list:
- #define TARGET_ADDR "90:ab:96:a0:85:86" //Shelly BLU button public address
- static esp_ble_scan_params_t ble_scan_params = {
- .scan_type = BLE_SCAN_TYPE_ACTIVE,
- .own_addr_type = BLE_ADDR_TYPE_PUBLIC,
- .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ONLY_WLST,
- .scan_interval = 0x50,
- .scan_window = 0x30,
- .scan_duplicate = BLE_SCAN_DUPLICATE_DISABLE
- };
- void gap_callback(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) {
- switch (event) {
- case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: {
- esp_ble_gap_start_scanning(0); //Scan forever
- break;
- }
- case ESP_GAP_BLE_SCAN_RESULT_EVT: {
- esp_ble_gap_cb_param_t *scan_result = (esp_ble_gap_cb_param_t *)param;
- switch (scan_result->scan_rst.search_evt) {
- case ESP_GAP_SEARCH_INQ_RES_EVT: {
- char addr_str[18];
- sprintf(addr_str, "%02x:%02x:%02x:%02x:%02x:%02x",
- scan_result->scan_rst.bda[0], scan_result->scan_rst.bda[1], scan_result->scan_rst.bda[2],
- scan_result->scan_rst.bda[3], scan_result->scan_rst.bda[4], scan_result->scan_rst.bda[5]);
- if (strcmp(addr_str, TARGET_ADDR) == 0)
- {
- if(scan_result->scan_rst.ble_adv[scan_result->scan_rst.adv_data_len - 1] != 0)
- {
- ESP_LOGI(TAG_BLE, "Advertised Device: %s", addr_str);
- }
- }
- break;
- }
- case ESP_GAP_SEARCH_INQ_CMPL_EVT: {
- ESP_LOGI(TAG_BLE, "Scan complete");
- scan_complete = true;
- break;
- }
- default:
- break;
- }
- break;
- }
- default:
- break;
- }
- }
- void ScanBT() {
- esp_err_t ret;
- // Initialize NVS
- ret = nvs_flash_init();
- if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
- ESP_ERROR_CHECK(nvs_flash_erase());
- ret = nvs_flash_init();
- }
- ESP_ERROR_CHECK(ret);
- ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
- esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
- 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());
- esp_ble_gap_clear_whitelist();
- ESP_ERROR_CHECK(esp_ble_gap_register_callback(gap_callback));
- uint8_t whitelist_addr[6] = {0x90, 0xab, 0x96, 0xa0, 0x85, 0x86}; //Shelly BLU button public address
- esp_ble_gap_update_whitelist(true, whitelist_addr, BLE_WL_ADDR_TYPE_PUBLIC);
- ESP_ERROR_CHECK(esp_ble_gap_set_scan_params(&ble_scan_params));
- esp_sleep_enable_bt_wakeup();
- ESP_LOGI(TAG_BLE, "Scanning...");
- scan_complete = false;
- esp_ble_gap_update_whitelist(true, whitelist_addr, BLE_WL_ADDR_TYPE_RANDOM);
- }
I have tried to set the automatic light mode, adding this code:
- esp_pm_config_t pm_config = {
- .max_freq_mhz = 80,
- .min_freq_mhz = 10,
- .light_sleep_enable = true
- };
- ESP_ERROR_CHECK( esp_pm_configure(&pm_config) );
But then the C6 keeps resetting itself everytime it tries to go to light sleep.
Can anyone offer some guide, please? I also attached the current sdkconfig file of the project, just in case someone sees something wrong there (right now there's no automatic light sleep configuration active)
Thank you in advance!