File tree 3 files changed +23
-4
lines changed
libraries/BluetoothSerial
examples/SerialToSerialBT
3 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 6
6
7
7
#include " BluetoothSerial.h"
8
8
9
- #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
10
- #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
11
- #endif
12
-
13
9
BluetoothSerial SerialBT;
14
10
15
11
void setup () {
16
12
Serial.begin (115200 );
17
13
SerialBT.begin (" ESP32test" ); // Bluetooth device name
14
+ SerialBT.pinCode (" 3456" );
18
15
Serial.println (" The device started, now you can pair it with bluetooth!" );
19
16
}
20
17
Original file line number Diff line number Diff line change @@ -384,6 +384,22 @@ bool BluetoothSerial::begin(String localName)
384
384
return _init_bt (local_name.c_str ());
385
385
}
386
386
387
+ bool BluetoothSerial::pinCode ( char * pswd)
388
+ {
389
+ if (strlen (pswd)==4 ){
390
+ esp_bt_pin_type_t pin_type = ESP_BT_PIN_TYPE_FIXED;
391
+ esp_bt_pin_code_t pin_code;
392
+ pin_code[0 ] = pswd[0 ];
393
+ pin_code[1 ] = pswd[1 ] ;
394
+ pin_code[2 ] = pswd[2 ];
395
+ pin_code[3 ] = pswd[3 ];
396
+ esp_bt_gap_set_pin (pin_type, 4 , pin_code);
397
+ return true ;
398
+ }
399
+ else
400
+ return false ;
401
+ }
402
+
387
403
int BluetoothSerial::available (void )
388
404
{
389
405
if (_spp_rx_queue == NULL ){
Original file line number Diff line number Diff line change 22
22
#include " Arduino.h"
23
23
#include " Stream.h"
24
24
#include < esp_spp_api.h>
25
+ #include " esp_gap_bt_api.h"
26
+
27
+ #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
28
+ #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
29
+ #endif
25
30
26
31
class BluetoothSerial : public Stream
27
32
{
@@ -31,6 +36,7 @@ class BluetoothSerial: public Stream
31
36
~BluetoothSerial (void );
32
37
33
38
bool begin (String localName=String());
39
+ bool pinCode (char * pswd);
34
40
int available (void );
35
41
int peek (void );
36
42
bool hasClient (void );
You can’t perform that action at this time.
0 commit comments