Skip to content

Commit ab8d4f7

Browse files
committed
Enable MAC/Name connect.
1 parent ee75b98 commit ab8d4f7

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

Firmware/BlueSMiRF-v2/Bluetooth.ino

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ void bluetoothBegin()
4141
snprintf(broadcastNamePaired, sizeof(broadcastNamePaired), "%s%s-Paired", broadcastName, bluetoothTypeString) < 0
4242
? snprintfAbort()
4343
: (void)0;
44-
snprintf(broadcastNamePairing, sizeof(broadcastNamePairing), "%s%s-Pairing", broadcastName, bluetoothTypeString) < 0
45-
? snprintfAbort()
46-
: (void)0;
4744
snprintf(broadcastNameConnected, sizeof(broadcastNameConnected), "%s%s-Connected", broadcastName,
4845
bluetoothTypeString) < 0
4946
? snprintfAbort()
@@ -69,7 +66,7 @@ void bluetoothBegin()
6966
recordSystemSettings();
7067

7168
// Broadcast the standard name
72-
if (bluetoothSetBroadcastName(broadcastName))
69+
if (bluetoothSetBroadcastName(broadcastName) == false)
7370
{
7471
systemPrintln("An error occurred initializing Bluetooth in paired mode");
7572
return;
@@ -179,7 +176,7 @@ bool bluetoothSetBroadcastName(char *castName)
179176
{
180177
if (settings.debugBluetooth == true)
181178
{
182-
systemPrint("Bluetooth broadcasting as: ");
179+
systemPrint("Bluetooth broadcast name set to: ");
183180
systemPrintln(castName);
184181
}
185182

@@ -294,7 +291,7 @@ bool connectToDeviceMac(uint8_t *macAddress, int maxTries)
294291
{
295292
#ifdef COMPILE_BT
296293
if (settings.debugBluetooth == true)
297-
systemPrintf("Connecting to %s", stringMac(macAddress));
294+
systemPrintf("Connecting to MAC: %s", stringMac(macAddress));
298295

299296
ledState = LED_CONNECTING;
300297

@@ -305,13 +302,15 @@ bool connectToDeviceMac(uint8_t *macAddress, int maxTries)
305302

306303
bluetoothSerial->end();
307304

308-
// Move to master mode, '-Paired'
309-
if (bluetoothSetBroadcastName(broadcastNamePaired))
305+
// Start BT in master mode with the name '-Paired'
306+
if(bluetoothSerial->begin(broadcastNamePaired, true, settings.btRxSize, settings.btTxSize) == false)
310307
{
311308
systemPrintln("An error occurred initializing Bluetooth in master mode");
312309
return (false);
313310
}
314311

312+
bluetoothState = BT_NOTCONNECTED;
313+
315314
// After discovery, if we immediately try to connect, it will always fail
316315
// If we wait 250ms, it works ~50% of the time, and usually connects on 2nd attempt
317316
delay(250);
@@ -322,6 +321,8 @@ bool connectToDeviceMac(uint8_t *macAddress, int maxTries)
322321
{
323322
if (settings.debugBluetooth == true)
324323
systemPrintln("Connected!");
324+
325+
bluetoothState = BT_CONNECTED;
325326
return (true);
326327
}
327328
}
@@ -344,7 +345,7 @@ bool connectToDeviceName(char *deviceName, int maxTries)
344345
{
345346
#ifdef COMPILE_BT
346347
if (settings.debugBluetooth == true)
347-
systemPrintf("Connecting to %s", deviceName);
348+
systemPrintf("Connecting to name: %s", deviceName);
348349

349350
ledState = LED_CONNECTING;
350351

@@ -355,13 +356,15 @@ bool connectToDeviceName(char *deviceName, int maxTries)
355356

356357
bluetoothSerial->end();
357358

358-
// Move to broadcast mode '-Paired'
359-
if (bluetoothSetBroadcastName(broadcastNamePaired))
359+
// Start BT in master mode with the name '-Paired'
360+
if(bluetoothSerial->begin(broadcastNamePaired, true, settings.btRxSize, settings.btTxSize) == false)
360361
{
361-
systemPrintln("An error occurred initializing Bluetooth in paired name mode");
362+
systemPrintln("An error occurred initializing Bluetooth in master mode");
362363
return (false);
363364
}
364365

366+
bluetoothState = BT_NOTCONNECTED;
367+
365368
// After discovery, if we immediately try to connect, it will always fail
366369
// If we wait 250ms, it works ~50% of the time, and usually connects on 2nd attempt
367370
delay(250);

0 commit comments

Comments
 (0)