void bt_app_gap_start_up(void) { char *dev_name = "ESP_GAP_INQRUIY"; esp_bt_dev_set_device_name(dev_name); /* set discoverable and connectable mode, wait to be connected */ esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE); /* register GAP callback function */ esp_bt_gap_register_callback(bt_app_gap_cb); /* inititialize device information and status */ app_gap_cb_t *p_dev = &m_dev_info; memset(p_dev, 0, sizeof(app_gap_cb_t)); /* start to discover nearby Bluetooth devices */ p_dev->state = APP_GAP_STATE_DEVICE_DISCOVERING; esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, 10, 0); }
void app_main() { for (int i = 0; i < SPP_DATA_LEN; ++i) { spp_data[i] = i; } 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 ); ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_BLE)); esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); if (esp_bt_controller_init(&bt_cfg) != ESP_OK) { ESP_LOGE(SPP_TAG, "%s initialize controller failed", __func__); return; } if (esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT) != ESP_OK) { ESP_LOGE(SPP_TAG, "%s enable controller failed", __func__); return; } if (esp_bluedroid_init() != ESP_OK) { ESP_LOGE(SPP_TAG, "%s initialize bluedroid failed", __func__); return; } if (esp_bluedroid_enable() != ESP_OK) { ESP_LOGE(SPP_TAG, "%s enable bluedroid failed", __func__); return; } if (esp_bt_gap_register_callback(esp_bt_gap_cb) != ESP_OK) { ESP_LOGE(SPP_TAG, "%s gap register failed", __func__); return; } if (esp_spp_register_callback(esp_spp_stack_cb) != ESP_OK) { ESP_LOGE(SPP_TAG, "%s spp register failed", __func__); return; } esp_spp_vfs_register(); spp_task_task_start_up(); if (esp_spp_init(esp_spp_mode) != ESP_OK) { ESP_LOGE(SPP_TAG, "%s spp init failed", __func__); return; } #if (CONFIG_BT_SSP_ENABLED == true) /* Set default parameters for Secure Simple Pairing */ esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t)); #endif /* * Set default parameters for Legacy Pairing * Use variable pin, input pin code when pairing */ esp_bt_pin_type_t pin_type = ESP_BT_PIN_TYPE_VARIABLE; esp_bt_pin_code_t pin_code; esp_bt_gap_set_pin(pin_type, 0, pin_code); }