diff --git a/components/esp_local_ctrl/CMakeLists.txt b/components/esp_local_ctrl/CMakeLists.txt index 92df4d4db9..5c7da2fc49 100644 --- a/components/esp_local_ctrl/CMakeLists.txt +++ b/components/esp_local_ctrl/CMakeLists.txt @@ -11,7 +11,7 @@ set(srcs "src/esp_local_ctrl.c" "proto-c/esp_local_ctrl.pb-c.c") if(CONFIG_BT_ENABLED) - if(CONFIG_BT_BLUEDROID_ENABLED) + if(CONFIG_BT_BLUEDROID_ENABLED OR CONFIG_BT_NIMBLE_ENABLED) list(APPEND srcs "src/esp_local_ctrl_transport_ble.c") endif() diff --git a/components/esp_local_ctrl/include/esp_local_ctrl.h b/components/esp_local_ctrl/include/esp_local_ctrl.h index 2e9a56a0d3..30b00fd0ae 100644 --- a/components/esp_local_ctrl/include/esp_local_ctrl.h +++ b/components/esp_local_ctrl/include/esp_local_ctrl.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -195,7 +195,7 @@ const esp_local_ctrl_transport_t *esp_local_ctrl_get_transport_httpd(void); * @brief Configuration for transport mode BLE * * This is a forward declaration for `protocomm_ble_config_t`. - * To use this, application must set CONFIG_BT_BLUEDROID_ENABLED + * To use this, application must set CONFIG_BT_ENABLED * and include `protocomm_ble.h`. */ typedef struct protocomm_ble_config esp_local_ctrl_transport_config_ble_t; diff --git a/examples/protocols/esp_local_ctrl/main/Kconfig.projbuild b/examples/protocols/esp_local_ctrl/main/Kconfig.projbuild index 0e6d06c3b1..661ac8fa7b 100644 --- a/examples/protocols/esp_local_ctrl/main/Kconfig.projbuild +++ b/examples/protocols/esp_local_ctrl/main/Kconfig.projbuild @@ -1,5 +1,22 @@ menu "Example Configuration" + choice EXAMPLE_LOCAL_CTRL_TRANSPORT + bool "Local Control Transport" + default EXAMPLE_LOCAL_CTRL_TRANSPORT_BLE if !SOC_WIFI_SUPPORTED + default EXAMPLE_LOCAL_CTRL_TRANSPORT_SOFTAP + help + Local Control component offers both, SoftAP and BLE transports. Choose any one. + + config EXAMPLE_LOCAL_CTRL_TRANSPORT_SOFTAP + bool "Soft AP" + select LWIP_IPV4 + depends on SOC_WIFI_SUPPORTED + + config EXAMPLE_LOCAL_CTRL_TRANSPORT_BLE + bool "BLE" + select BT_ENABLED + endchoice + choice EXAMPLE_PROTOCOMM_SECURITY_VERSION bool "Protocomm security version" default EXAMPLE_PROTOCOMM_SECURITY_VERSION_2 @@ -41,4 +58,13 @@ menu "Example Configuration" security version 2. endchoice + config EXAMPLE_LOCAL_CTRL_USING_BLUEDROID + bool + depends on (BT_BLUEDROID_ENABLED && !IDF_TARGET_ESP32) + select BT_BLE_42_FEATURES_SUPPORTED + default y + help + This enables BLE 4.2 features for Bluedroid which are required for + the API definitions that are present in the esp_gap_ble_api header. + endmenu diff --git a/examples/protocols/esp_local_ctrl/main/app_main.c b/examples/protocols/esp_local_ctrl/main/app_main.c index 1fd98fd219..ee2a2ff224 100644 --- a/examples/protocols/esp_local_ctrl/main/app_main.c +++ b/examples/protocols/esp_local_ctrl/main/app_main.c @@ -38,12 +38,17 @@ void app_main(void) ret = nvs_flash_init(); } ESP_ERROR_CHECK(ret); + +#ifdef CONFIG_EXAMPLE_LOCAL_CTRL_TRANSPORT_SOFTAP ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_event_loop_create_default()); - if (example_connect() == ESP_OK) { - start_esp_local_ctrl_service(); - } else { + if (example_connect() != ESP_OK) { ESP_LOGI(TAG, "Connection failed, not starting esp_local_ctrl service"); + vTaskDelay(portMAX_DELAY); } +#endif /* CONFIG_EXAMPLE_LOCAL_CTRL_TRANSPORT_SOFTAP */ + + start_esp_local_ctrl_service(); + ESP_LOGI(TAG, "esp_local_ctrl service started"); } diff --git a/examples/protocols/esp_local_ctrl/main/esp_local_ctrl_service.c b/examples/protocols/esp_local_ctrl/main/esp_local_ctrl_service.c index 6b38202eff..595952d06a 100644 --- a/examples/protocols/esp_local_ctrl/main/esp_local_ctrl_service.c +++ b/examples/protocols/esp_local_ctrl/main/esp_local_ctrl_service.c @@ -20,6 +20,7 @@ #include #include #include +#include static const char *TAG = "control"; @@ -224,6 +225,7 @@ static void free_str(void *arg) /* Function used by app_main to start the esp_local_ctrl service */ void start_esp_local_ctrl_service(void) { +#ifdef CONFIG_EXAMPLE_LOCAL_CTRL_TRANSPORT_SOFTAP #ifdef CONFIG_ESP_HTTPS_SERVER_ENABLE /* Set the configuration */ httpd_ssl_config_t https_conf = HTTPD_SSL_CONFIG_DEFAULT(); @@ -242,6 +244,26 @@ void start_esp_local_ctrl_service(void) #else httpd_config_t http_conf = HTTPD_DEFAULT_CONFIG(); #endif +#else /* CONFIG_EXAMPLE_LOCAL_CTRL_TRANSPORT_BLE */ + protocomm_ble_config_t *ble_conf = & (protocomm_ble_config_t) { + .device_name = SERVICE_NAME, + /* Set a random 128 bit UUID which will be included in the BLE advertisement + * and will correspond to the primary GATT service that provides provisioning + * endpoints as GATT characteristics. Each GATT characteristic will be + * formed using the primary service UUID as base, with different auto assigned + * 12th and 13th bytes (assume counting starts from 0th byte). The client side + * applications must identify the endpoints by reading the User Characteristic + * Description descriptor (0x2901) for each characteristic, which contains the + * endpoint name of the characteristic */ + .service_uuid = { + /* LSB <--------------------------------------- + * ---------------------------------------> MSB */ + 0x21, 0xd5, 0x3b, 0x8d, 0xbd, 0x75, 0x68, 0x8a, + 0xb4, 0x42, 0xeb, 0x31, 0x4a, 0x1e, 0x98, 0x3d, + } + }; +#endif /* CONFIG_EXAMPLE_LOCAL_CTRL_TRANSPORT_SOFTAP */ + #ifdef CONFIG_EXAMPLE_PROTOCOMM_SECURITY_VERSION_1 /* What is the security level that we want (0, 1, 2): * - PROTOCOMM_SECURITY_0 is simply plain text communication. @@ -284,6 +306,7 @@ void start_esp_local_ctrl_service(void) #endif esp_local_ctrl_config_t config = { +#ifdef CONFIG_EXAMPLE_LOCAL_CTRL_TRANSPORT_SOFTAP .transport = ESP_LOCAL_CTRL_TRANSPORT_HTTPD, .transport_config = { #ifdef CONFIG_ESP_HTTPS_SERVER_ENABLE @@ -292,6 +315,12 @@ void start_esp_local_ctrl_service(void) .httpd = &http_conf, #endif }, +#else /* CONFIG_EXAMPLE_LOCAL_CTRL_TRANSPORT_BLE */ + .transport = ESP_LOCAL_CTRL_TRANSPORT_BLE, + .transport_config = { + .ble = ble_conf, + }, +#endif /* CONFIG_EXAMPLE_LOCAL_CTRL_TRANSPORT_SOFTAP */ .proto_sec = { .version = security, .custom_handle = NULL, @@ -308,8 +337,10 @@ void start_esp_local_ctrl_service(void) .max_properties = 10 }; +#ifdef CONFIG_EXAMPLE_LOCAL_CTRL_TRANSPORT_SOFTAP mdns_init(); mdns_hostname_set(SERVICE_NAME); +#endif /* Start esp_local_ctrl service */ ESP_ERROR_CHECK(esp_local_ctrl_start(&config)); diff --git a/examples/protocols/esp_local_ctrl/scripts/esp_local_ctrl.py b/examples/protocols/esp_local_ctrl/scripts/esp_local_ctrl.py index dbbd629724..597a977634 100644 --- a/examples/protocols/esp_local_ctrl/scripts/esp_local_ctrl.py +++ b/examples/protocols/esp_local_ctrl/scripts/esp_local_ctrl.py @@ -136,7 +136,7 @@ async def get_transport(sel_transport, service_name, check_hostname): tp = esp_prov.transport.Transport_HTTP(service_name, ssl_ctx) elif (sel_transport == 'ble'): tp = esp_prov.transport.Transport_BLE( - devname=service_name, service_uuid='0000ffff-0000-1000-8000-00805f9b34fb', + service_uuid='3d981e4a-31eb-42b4-8a68-75bd8d3bd521', nu_lookup={'esp_local_ctrl/version': '0001', 'esp_local_ctrl/session': '0002', 'esp_local_ctrl/control': '0003'} diff --git a/examples/protocols/esp_local_ctrl/sdkconfig.defaults.esp32h2 b/examples/protocols/esp_local_ctrl/sdkconfig.defaults.esp32h2 new file mode 100644 index 0000000000..1a95b7094c --- /dev/null +++ b/examples/protocols/esp_local_ctrl/sdkconfig.defaults.esp32h2 @@ -0,0 +1,5 @@ +# Override some defaults so BT stack is enabled and +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y + +CONFIG_EXAMPLE_LOCAL_CTRL_TRANSPORT_BLE=y