From 0d564d7b1d7ed2a85dcbd80e4b4e6f6e393e486d Mon Sep 17 00:00:00 2001 From: Nikos Mouratidis <33179613+mouridis@users.noreply.github.com> Date: Tue, 20 Nov 2018 00:08:15 +0800 Subject: [PATCH] Limit the number of simultaneously connected devices to BluetoothSerial to only 1 (#2061) --- libraries/BluetoothSerial/src/BluetoothSerial.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libraries/BluetoothSerial/src/BluetoothSerial.cpp b/libraries/BluetoothSerial/src/BluetoothSerial.cpp index 9bfe7a68..001be966 100644 --- a/libraries/BluetoothSerial/src/BluetoothSerial.cpp +++ b/libraries/BluetoothSerial/src/BluetoothSerial.cpp @@ -50,6 +50,7 @@ static xQueueHandle _spp_tx_queue = NULL; static SemaphoreHandle_t _spp_tx_done = NULL; static TaskHandle_t _spp_task_handle = NULL; static EventGroupHandle_t _spp_event_group = NULL; +static boolean secondConnectionAttempt; #define SPP_RUNNING 0x01 #define SPP_CONNECTED 0x02 @@ -162,13 +163,22 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) break; case ESP_SPP_SRV_OPEN_EVT://Server connection open - _spp_client = param->open.handle; + if (!_spp_client){ + _spp_client = param->open.handle; + } else { + secondConnectionAttempt = true; + esp_spp_disconnect(param->open.handle); + } xEventGroupSetBits(_spp_event_group, SPP_CONNECTED); log_i("ESP_SPP_SRV_OPEN_EVT"); break; case ESP_SPP_CLOSE_EVT://Client connection closed - _spp_client = 0; + if(secondConnectionAttempt) { + secondConnectionAttempt = false; + } else { + _spp_client = 0; + } xEventGroupClearBits(_spp_event_group, SPP_CONNECTED); log_i("ESP_SPP_CLOSE_EVT"); break;