1
- // This example code is in the Public Domain (or CC0 licensed, at your option.)
2
- // By Richard Li - 2020
1
+ // This example code is in the Public Domain (or CC0 licensed, at your option.)
2
+ // By Richard Li - 2020
3
3
//
4
- // This example creates a bridge between Serial and Classical Bluetooth (SPP with authentication)
5
- // and also demonstrate that SerialBT have the same functionalities of a normal Serial
4
+ // This example creates a bridge between Serial and Classical Bluetooth (SPP with authentication)
5
+ // and also demonstrate that SerialBT have the same functionalities of a normal Serial
6
+ // SSP - Simple Secure Pairing - The device (ESP32) will display random number and the user is responsible of comparing it to the number
7
+ // displayed on the other device (for example phone).
8
+ // If the numbers match the user authenticates the pairing.
6
9
7
10
#include " BluetoothSerial.h"
8
11
14
17
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
15
18
#endif
16
19
20
+ const char * deviceName = " ESP32_SSP_example" ;
21
+
17
22
BluetoothSerial SerialBT;
18
23
boolean confirmRequestPending = true ;
19
24
20
25
void BTConfirmRequestCallback (uint32_t numVal)
21
26
{
22
27
confirmRequestPending = true ;
23
- Serial.println ( numVal);
28
+ Serial.printf ( " The PIN is: %lu \n " , numVal);
24
29
}
25
30
26
31
void BTAuthCompleteCallback (boolean success)
@@ -43,8 +48,8 @@ void setup()
43
48
SerialBT.enableSSP ();
44
49
SerialBT.onConfirmRequest (BTConfirmRequestCallback);
45
50
SerialBT.onAuthComplete (BTAuthCompleteCallback);
46
- SerialBT.begin (" ESP32test " ); // Bluetooth device name
47
- Serial.println (" The device started, now you can pair it with bluetooth! " );
51
+ SerialBT.begin (deviceName ); // Bluetooth device name
52
+ Serial.printf (" The device started with name \" %s \" , now you can pair it with Bluetooth! \n " , deviceName );
48
53
}
49
54
50
55
void loop ()
0 commit comments