Skip to content

Commit b866a1e

Browse files
committed
Reuse BLEClient on connection failure and increase websocket ping timeouts
1 parent 66c2f9a commit b866a1e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/ble_api.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ bool BLEApi::connect(BLEPeripheralID id)
161161
bool connected = false;
162162
int8_t retry = 5;
163163
log_i("Connect attempt start");
164+
peripheral = BLEDevice::createClient();
164165
do
165166
{
166-
peripheral = BLEDevice::createClient();
167167
// TODO: sometimes the connect fails and remains hanging in the semaphore, patch BLE lib ?
168168
// ----------------------------
169169
// Connect attempt start
@@ -180,8 +180,8 @@ bool BLEApi::connect(BLEPeripheralID id)
180180
}
181181
else
182182
{
183-
log_d("Removing peripheral");
184-
delete peripheral;
183+
// log_d("Removing peripheral");
184+
// delete peripheral;
185185
if (retry > 0)
186186
{
187187
log_i("Retry connection in 1s");
@@ -196,6 +196,8 @@ bool BLEApi::connect(BLEPeripheralID id)
196196
}
197197
else
198198
{
199+
log_d("Removing peripheral");
200+
delete peripheral;
199201
log_e("Could not connect to [%s][%d]\n", address.toString().c_str(), retry);
200202
}
201203
return connected;

src/noble_api.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void NobleApi::init()
4444
BLEApi::onDeviceDisconnected(onBLEDeviceDisconnected);
4545
BLEApi::onCharacteristicNotification(onCharacteristicNotification);
4646
ws = new WebSocketsServer(ESP_GW_WEBSOCKET_PORT);
47-
ws->enableHeartbeat(10000, 2000, 1);
47+
ws->enableHeartbeat(30000, 5000, 3);
4848
ws->begin();
4949
ws->onEvent(onWsEvent);
5050
}

0 commit comments

Comments
 (0)