ESP32 - BT Classic setup to hard code MAC Address

Looking for how the syntax must be to hard code a MAC address in the following function ("uint8_t remoteAddress[]").
SerialBT.connect (uint8_t remoteAddress[], int channel=0, ESP_SPP_SEC_NONE, ESP_SPP_ROLE_MASTER)

Tried the following 0xa1,0xb2,0xc3,0x4d,0x5e,0x6f
" 0xa1,0xb2,0xc3,0x4d,0x5e,0x6f"
a1:b2:c3:4d:5e:6f
Nothing works and the documentation is poor for a mechanical guy. Its in the library, but nothing is explained in an example to force an address. My app is in a remote place with no security concerns and we want to control the device that is connected so end user cant screw it up.

Could you post all your code.

red_car, I took the example from ESP32>BluetoothSerial>SerialToSerialBTM and commented out the address array, because that did not work by changing to my devices MAC. I also added the set the SSP_SEC to NONE in the function because neither device has a display or button for pairing.

//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Victor Tchistiak - 2019
//
//This example demostrates master mode bluetooth connection and pin 
//it creates a bridge between Serial and Classical Bluetooth (SPP)
//this is an extention of the SerialToSerialBT example by Evandro Copercini - 2018
//

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif

BluetoothSerial SerialBT;

//String MACadd = "AA:BB:CC:11:22:33";
//uint8_t address[6]  = {0xAA, 0xBB, 0xCC, 0x11, 0x22, 0x33};
//uint8_t address[6]  = {0x00, 0x1D, 0xA5, 0x02, 0xC3, 0x22};
//String name = "OBDII";
const char *pin = "1234"; //<- standard pin would be provided by default
bool connected;

void setup() {
  Serial.begin(115200);
  //SerialBT.setPin(pin);
  SerialBT.begin("ESP32test", true); 
  //SerialBT.setPin(pin);
  Serial.println("The device started in master mode, make sure remote BT device is on!");
  
  // connect(address) is fast (upto 10 secs max), connect(name) is slow (upto 30 secs max) as it needs
  // to resolve name to address first, but it allows to connect to different devices with the same name.
  // Set CoreDebugLevel to Info to view devices bluetooth address and device names
  //connected = SerialBT.connect(name);
  connected = SerialBT.connect("0xa9,0x97,0x33,0xba,0x61,0x88",ESP_SPP_SEC_NONE);
  
  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);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.