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
33//
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.
69
710#include " BluetoothSerial.h"
811
1417#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
1518#endif
1619
20+ const char * deviceName = " ESP32_SSP_example" ;
21+
1722BluetoothSerial SerialBT;
1823boolean confirmRequestPending = true ;
1924
2025void BTConfirmRequestCallback (uint32_t numVal)
2126{
2227 confirmRequestPending = true ;
23- Serial.println ( numVal);
28+ Serial.printf ( " The PIN is: %lu \n " , numVal);
2429}
2530
2631void BTAuthCompleteCallback (boolean success)
@@ -43,8 +48,8 @@ void setup()
4348 SerialBT.enableSSP ();
4449 SerialBT.onConfirmRequest (BTConfirmRequestCallback);
4550 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 );
4853}
4954
5055void loop ()
0 commit comments