Bluetooth Classic (BluetoothSerial) with Arduino-Esp32 V2.0.X

agent-r
Posts: 1
Joined: Mon Feb 14, 2022 7:50 pm

Bluetooth Classic (BluetoothSerial) with Arduino-Esp32 V2.0.X

Postby agent-r » Mon Feb 14, 2022 8:09 pm

Hallo,

i am facing some trouble with the bluetooth classic "BluetoothSerial.h" library and arduino-esp32 Version 2.0.1 / 2.0.2
I try to connect the esp32 as BT-Master to a HC-05 slave module. I want to use arduino-esp 2.0.X because the BT discovery-function is not available in previous Version (1.0.6 and lower). The following Code (taken from the SerialToSerialBTM example) compiles, uploads and connects with 1.0.6., but with 2.0.1 and 2.0.2 I can compile and upload, but I do not get any connection.

By the way: the whole project is a wireless CNC-pendant where i want to be able to search for available bluetooth CNC-machine controllers and choose the right on (through a graphical interface). The "discoverAsync"-Part of my Code already works perfectly with V2.0.X.

Any Ideas?

Code: Select all

#include "BluetoothSerial.h"
BluetoothSerial SerialBT;

// String MACadd = "AA:BB:CC:11:22:33";
uint8_t address[6]  = { 0x00,0x21,0x13,0x01,0x3C,0x6F };
// String name = "GRBLHAL";
const char *pin = "1234"; //<- standard pin would be provided by default
bool connected;

void setup() {
  Serial.begin(115200);
  SerialBT.setPin(pin);
  SerialBT.begin("ESP32Master", true); 
  Serial.println("The device started in master mode, make sure remote BT device is on!");
  
  // connected = SerialBT.connect(name);
 connected = SerialBT.connect(address);
  
  if(connected) {
    Serial.println("Connected Succesfully!");
  } else {
    while(!SerialBT.connected(10000)) {
      Serial.println("Failed to connect. Make sure remote device is available and in range, then restart app."); 
    }
  }
  // disconnect() may take upto 10 secs max
  if (SerialBT.disconnect()) {
    Serial.println("Disconnected Succesfully!");
  }
  // this would reconnect to the name(will use address, if resolved) or address used with connect(name/address).
  SerialBT.connect();
}

void loop() {
  if (Serial.available()) {
    SerialBT.write(Serial.read());
  }
  if (SerialBT.available()) {
    Serial.write(SerialBT.read());
  }
  delay(20);
}

Who is online

Users browsing this forum: No registered users and 85 guests