Bluetooth pairing in "client" mode

deepakt
Posts: 24
Joined: Tue Feb 26, 2019 12:23 pm

Bluetooth pairing in "client" mode

Postby deepakt » Tue Jul 09, 2019 10:35 am

Experts!

In my project, I'm using BT SPP to communicate between ESP32 and an Android device. I'm using the Arduino IDE and currently works fine. When the ESP32 comes up, I connect the Android device to the already paired ESP32 over BT. I use a Bluetooth Serial Terminal app on the Android. Data is sent and received on both devices - no issues.
Code that we're using effectively is this:

Code: Select all

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
}

void loop() {
  if (Serial.available()) {
    SerialBT.write(Serial.read());
  }
  if (SerialBT.available()) {
    Serial.write(SerialBT.read());
  }
  delay(20);
}
The problem I see is this: Any other device could just pair and connect to the ESP32 and send/receive data. In my project, security is needed and this issue leaves my design exposed.

What I'm looking for is:
1. How could I possibly setup the ESP32 as "client" and Android as "server". Once paired, the Android device will be in hidden/invisible/non-discoverable mode to new devices. Only the paired ESP32 "client" will be able to connect to the ANdroid device when it restarts.
2. Any "PIN" that I could set up on the ESP32 to provide some level of security?
3. Any other means by which I could make the design "intrusion" proof?

We've built quite a good system with our project using ESP32 and it has been performing very well, but this last bit is troubling us. Any help would be truly appreciated.

Regards,
Deepak

deepakt
Posts: 24
Joined: Tue Feb 26, 2019 12:23 pm

Re: Bluetooth pairing in "client" mode

Postby deepakt » Tue Jul 09, 2019 10:43 am

Going through the file arduino-esp32/tools/sdk/include/bt/esp_spp_api.h, I came across this piece of code. Would this help me achieve what I am looking for?

Code: Select all

typedef enum {
    ESP_SPP_ROLE_MASTER     = 0,          /*!< Role: master */
    ESP_SPP_ROLE_SLAVE      = 1,          /*!< Role: slave */
} esp_spp_role_t;

deepakt
Posts: 24
Joined: Tue Feb 26, 2019 12:23 pm

Re: Bluetooth pairing in "client" mode

Postby deepakt » Wed Jul 10, 2019 9:42 am

Hi,

Anyone out there who could help?

vinots
Posts: 3
Joined: Mon Jul 15, 2019 10:21 pm

Re: Bluetooth pairing in "client" mode

Postby vinots » Mon Jul 15, 2019 10:41 pm

Hi,

sorry I'm not an expert.

As told viewtopic.php?t=5537 at the end, can use pairing. Maybe encrypt packets for ethereal?

good luck!

toni

deepakt
Posts: 24
Joined: Tue Feb 26, 2019 12:23 pm

Re: Bluetooth pairing in "client" mode

Postby deepakt » Tue Jul 16, 2019 4:35 pm

Thankyou Toni for replying.

The link you referred to was for BLE, while we're using BT Classic. Moving to BLE would take a lot of effort for us at this stage.

I'm not even sure if BT Classic on Arduino supports master/socket server configuration currently. The library does not have any examples for a master/server configuration, and hence call for help here. Hopefully I can get some information on this soon.

Thanks again.

Regards,
Deepak

bilalchaudry9
Posts: 1
Joined: Sun Jan 24, 2021 11:45 am

Re: Bluetooth pairing in "client" mode

Postby bilalchaudry9 » Sun Jan 24, 2021 11:48 am

Hi,
Did you find any solution to this?

Regards,
Bilal Chaudry,

Who is online

Users browsing this forum: No registered users and 33 guests