#include "my_nimble_tracker.h" #include "esphome/core/log.h" #include "esp_log.h" #include "nvs_flash.h" /* BLE */ /* #include "nimble/nimble_port.h" #include "nimble/nimble_port_freertos.h" #include "host/ble_hs.h" #include "host/util/util.h" #include "console/console.h" #include "services/gap/ble_svc_gap.h" #include "ble_prox_cent.h" */ namespace esphome { namespace my_nimble_tracker { static const char *const TAG = "my_nimble_tracker"; /* class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks { void onResult(BLEAdvertisedDevice *advertisedDevice) { ESP_LOGI(TAG, "Received advertisement for %s", advertisedDevice->getAddress().toString().c_str()); delay(1); } }; */ void MyNimbleTracker::setup() { /* NimBLEDevice::init("my_nimble_tracker"); pBLEScan_ = NimBLEDevice::getScan(); //create new scan pBLEScan_->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); pBLEScan_->setActiveScan(false); //active scan uses more power, but get results faster pBLEScan_->setInterval(1200); pBLEScan_->setWindow(500); // less or equal setInterval value */ #if 0 int rc; /* Initialize NVS — it is used to store PHY calibration data */ esp_err_t 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); nimble_port_init(); /* Configure the host. */ ble_hs_cfg.reset_cb = ble_prox_cent_on_reset; ble_hs_cfg.sync_cb = ble_prox_cent_on_sync; ble_hs_cfg.store_status_cb = ble_store_util_status_rr; /* Initialize data structures to track connected peers. */ rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64); assert(rc == 0); /* Set the default device name. */ rc = ble_svc_gap_device_name_set("nimble-prox-cent"); assert(rc == 0); /* XXX Need to have template for store */ ble_store_config_init(); nimble_port_freertos_init(ble_prox_cent_host_task); #endif } void MyNimbleTracker::loop() { /* auto completion_func = [](NimBLEScanResults) { }; //ESP_LOGI(TAG, "Entering loop"); if(!pBLEScan_->isScanning()) { ESP_LOGI(TAG, "Starting scan"); pBLEScan_->start(4, completion_func, false); } vTaskDelay(1); //ESP_LOGI(TAG, "Exiting loop"); delay(1); */ } } // namespace my_nimble_tracker } // namespace esphome