Advertisement
Guest User

Untitled

a guest
Sep 17th, 2024
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1.  
  2. #include "BluetoothSerial.h"
  3. BluetoothSerial SerialBT;
  4. uint8_t address[6] = {0x98, 0xDA, 0x50, 0x02, 0x4A, 0xFE};  // Change this to reflect real MAC address of your slave BT device
  5. bool connected;
  6.  
  7. void setup() {
  8.  
  9.   Serial.begin(115200);
  10.   //SerialBT.deleteAllBondedDevices(); // Uncomment this to delete paired devices; Must be called after begi
  11.  //Bluetooth setup and connection
  12.   SerialBT.begin("ESP32test", true);
  13.   Serial.println("The device started in master mode, make sure remote BT device is on!");
  14.   connected = SerialBT.connect(address);
  15.  
  16.   if (connected) {
  17.     Serial.println("Connected Succesfully!");
  18.   } else {
  19.     while (!SerialBT.connected(10000)) {
  20.       Serial.println("Failed to connect. Make sure remote device is available and in range, then restart app.");
  21.     }
  22.   }
  23.   SerialBT.connect();
  24. }
  25.  
  26. void loop() {
  27.   if (Serial.available()) {
  28.     SerialBT.write(Serial.read());
  29.   }
  30.   if (SerialBT.available()) {
  31.     Serial.write(SerialBT.read());
  32.   }
  33.   delay(20);
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement