B4R Question Password in Bluetooth for ESP32

Gerardo Tenreiro

Active Member
Licensed User
Good again
In an ESP32 application I need to have a password for the Bluetooth connection so that when a device tries to connect to the ESP32 it is necessary to enter a password before pairing the device and the ESP32

The Bluetooth is the classic normal bt.

I am using the rESP32Bluetooth library version 1.00

Can you help me?

Thank you so much
 

peacemaker

Expert
Licensed User
Longtime User
IMHO, passwords it's the security task for the user, that can allow data exchange between some device and his device by the pairing.
 
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
Yes, but it is the user who wants to have a password on their ESP32 so that only they can pair the ESP32.
It is an ESP32 that is visible to many people and wants to have that password
What I don't see is the option from B4R to tell the ESP32 to have this option.
Any option?
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Searching on the internet:

 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Also then you can use in-line C:

B4X:
Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    If wifi.Connect2("SSID", "PASS") = True Then
        Log("Connected")
        RunNative("initiate", Null)
        AddLooper("letsaddtolooper")
    Else
        Log("Failed to connect")
    End If

End Sub

Private Sub letsaddtolooper
    RunNative("addaslooper", Null)
End Sub



#if C

//Example code that works fine with v1.0.1 and can't connect with v2 (v2.0.2 and latest):
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;

uint8_t address[6] = { 0x20, 0x13, 0x01, 0x18, 0x02, 0x26 };
const char *pin = "1234";
bool connected;

void initiate(B4R::Object* o) {
  SerialBT.begin("ESPBT", true);
  SerialBT.setPin(pin);
  Serial.println("The device started in master mode, make sure remote BT device is on!");
 
  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.");
    }
  }
}

void addaslooper(B4R::Object* o) {

  if (SerialBT.available()) {
    Serial.write(SerialBT.read());
  }
  delay(5);
}

#End if
 
Last edited:
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
Hello
Thanks for the help but it gives me the following error
I would also need to be able to know from B4R when the Bluetooth is connected and disconnected.

1700503869673.png
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Upvote 0
Top