Cannot connect ESP32 (as master/initiator) with password over bluetooth

Jakboc
Posts: 2
Joined: Thu Dec 19, 2019 3:04 pm

Cannot connect ESP32 (as master/initiator) with password over bluetooth

Postby Jakboc » Thu Dec 19, 2019 3:18 pm

Hello,

I was trying to connect ESP32 with OBD II adapter - ELM327 over bluetooth. I tried various options and generally, ELM 327 is receiving my messages, but don't answer them.

I tried to communicate ESP32 with Android phone without password and BT Serial communication works properly.
But in my primary case, I'd connect ESP32 as master, initiator device to ELM327 (slave). I cannot turn off PIN in ELM device..

Code: Select all

#include "BluetoothSerial.h"

BluetoothSerial SerialBT;

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

void setup(){
  Serial.begin(115200);
  SerialBT.setPin(pin);
  SerialBT.begin("ESP32", true); 
  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 loop() {
  if(Serial.available()){
    SerialBT.write(Serial.read());
  }
  if(SerialBT.available()){
    Serial.write(SerialBT.read());
  }
  delay(20);
}

After uploading following code, I'm getting an error on serial monitor:

Code: Select all

ASSERT_WARN(1 8), in lc_task.c at line 5054
.
Could anybody give me some advices? :(

Thanks.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: Cannot connect ESP32 (as master/initiator) with password over bluetooth

Postby chegewara » Fri Dec 20, 2019 12:56 pm

Hi,
im not classic BT expert, but i believe that setPin() function sets esp32 local PIN for legacy pairing:
https://github.com/espressif/arduino-es ... l.cpp#L677

My suggestion is to register callback and see what events will be triggered, most likely one of them is related to pin request after which you have to send pin:
https://github.com/espressif/arduino-es ... l.cpp#L663

https://docs.espressif.com/projects/esp ... p_spp.html

Jakboc
Posts: 2
Joined: Thu Dec 19, 2019 3:04 pm

Re: Cannot connect ESP32 (as master/initiator) with password over bluetooth

Postby Jakboc » Mon Dec 23, 2019 5:23 pm

chegewara, thank you for a reply!

I tried to register the events:

Code: Select all

ESP_BT_GAP_AUTH_CMPL_EVT
ESP_BT_GAP_PIN_REQ_EVT
ESP_BT_GAP_KEY_REQ_EVT
ESP_BT_GAP_KEY_NOTIF_EVT
but without success. I don't received any message.

Here is my scrap of code:

Code: Select all

void gap_callback(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param){
  if (event == ESP_BT_GAP_AUTH_CMPL_EVT) {
    Serial.println ("authentication success: %s");
  }
  if (event == ESP_BT_GAP_PIN_REQ_EVT) {
    Serial.println ("ESP_BT_GAP_PIN_REQ_EVT min_16_digit:%d");
  }

    if (event == ESP_BT_GAP_KEY_REQ_EVT) {
    Serial.println ("ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");
  }
  
      if (event == ESP_BT_GAP_KEY_NOTIF_EVT) {
    Serial.println ("ESP_BT_GAP_KEY_NOTIF_EVT passkey:%d");
  }
}

and in setup()
esp_bt_gap_register_callback(gap_callback);
I tried the same with esp_spp_cb_event and I've received answers.

I noticed two things:
-when I do not supply ELM327 adapter, the ESP32 is not sending

Code: Select all

ASSERT_WARN(1 8), in lc_task.c at line 5054
error message
-on the first launch of ELM327 and ESP32 I'm getting a message "ELM327 v1.5>"

Any ideas? :(

digidax
Posts: 3
Joined: Thu Aug 27, 2020 7:05 am

Re: Cannot connect ESP32 (as master/initiator) with password over bluetooth

Postby digidax » Wed Sep 02, 2020 12:53 pm


Who is online

Users browsing this forum: Baldhead, Google [Bot] and 112 guests