BT Classic communication between two ESP32

Crisos
Posts: 1
Joined: Fri May 11, 2018 10:34 am

BT Classic communication between two ESP32

Postby Crisos » Fri May 11, 2018 11:24 am

Hi Everyone,

I have a very simple application where one ESP32 sends a message over BT to another ESP32. I have been playing mostly with Arduinos till now and using that this kind of application was quite easy, but now I want to move to this platform.

Using BluetoothSerial.h library I can happily connect to an Android device and send those messages, but I can't start the connection from another ESP32. This library doesn't have a connect command, so I went and found out what is the control to connect via SPP and I seem to be able to find the other device and connect to it, but also seems like the connection crashes immediately afterwards.

Here the code I am using:

Code: Select all

#include "esp_bt_main.h"
#include "esp_gap_bt_api.h"
#include "esp_spp_api.h"
#include <BluetoothSerial.h>

uint8_t address[6] = {0x30, 0xAE, 0xA4, 0x21, 0xBA, 0xBA};
String MACadd = "30:AE:A4:21:BA:BA";

static const esp_spp_sec_t sec_mask = ESP_SPP_SEC_NONE;
static const esp_spp_role_t role_slave = ESP_SPP_ROLE_MASTER;
esp_err_t connHan;


BluetoothSerial SerialBT;

void setup() {
  Serial.begin(9600);
  Serial.println("The device is ready!");
  SerialBT.begin("Glove ESP");
  Serial.println("Looking for device...");
  if(esp_spp_start_discovery(address) == ESP_OK){
    Serial.println("Device found!");
  }
    else{
    Serial.println("Device not found :(");
  }
  
  connHan = esp_spp_connect(ESP_SPP_SEC_NONE, ESP_SPP_ROLE_MASTER, 3,address);
  if(connHan == ESP_OK){
    Serial.println("Device Connected!");
  }
    else{
    Serial.println("Device not connected :(");
  }
  delay(1000);
  
  if (SerialBT.hasClient() == true) {
        Serial.print("Client connected");
        
        //SerialBT.println("some text");
    } else {
        Serial.println("Client disconnected");
        esp_spp_disconnect(connHan);
        SerialBT.begin("Glove ESP");
        delay(1500);
    }
  
}
 
void loop() {
}
I tried with different SCN, but all the time I get this message: (not sure why it is not clear, like wrong baud)

Code: Select all

C'΂⸮⸮Θb⸮⸮`<⸮!⸮The device is ready!
Looking for device...
Device found!
Device Connected!
[0;31mE (1520) BT: btm_sec_connected
[0m
[0;31mE (1545) BT: l2cu_adjust_out_mps bad packet size: 0  will use MPS: 0[0m
[0;31mE (1554) BT: process_service_search_attr_rsp
[0m
[0;31mE (1604) BT: port_rfc_closed RFCOMM connection in state 1 closed: Closed (res: 19)[0m
Client disconnected
[0;31mE (2146) BT: btc_spp_disconnect unable to find RFCOMM slot! disconnect fail![0m
[0;31mE (2146) BT: JVenable fails[0m

Anyone can help? I have spent like two days on this and I couldn't imagine it could be so complicated!
Thank you in advance!

PeterWay
Posts: 1
Joined: Sun May 13, 2018 4:00 pm

Re: BT Classic communication between two ESP32

Postby PeterWay » Sun May 13, 2018 4:06 pm

Hello,

i will add at this topis my question.

I like to use BT classic commninication.
At first im loking for Arduino example for search classic BT equ. near.
Second i like to make pair od them and serial cimmunication over.

Im loking and searcing all google, but i found only examples for BLE.

TNX for help and answer

Peter

alwurts
Posts: 4
Joined: Sat Jun 30, 2018 2:49 pm

Re: BT Classic communication between two ESP32

Postby alwurts » Sat Jun 30, 2018 2:57 pm

Hi

Im trying to make a two way bluetooth connection between two ESP32, same as you.
If you managed to make it work please let me know, it would be of great help.

Alejandro

petitan
Posts: 3
Joined: Fri Aug 31, 2018 10:33 am

Re: BT Classic communication between two ESP32

Postby petitan » Fri Aug 31, 2018 10:35 am

Hey guys, i want to solve same problem, is there any solving already? :)

Thank you.

ESP_Tianhao
Posts: 27
Joined: Thu Jan 05, 2017 10:46 am

Re: BT Classic communication between two ESP32

Postby ESP_Tianhao » Fri Aug 31, 2018 10:47 am

Could you test the SPP demos (receiver and initiator) in official ESP-IDF master branch or release/v3.1 or other branches?

All of the same problems happened with Arduino platform?

petitan
Posts: 3
Joined: Fri Aug 31, 2018 10:33 am

Re: BT Classic communication between two ESP32

Postby petitan » Mon Sep 03, 2018 10:22 am

So should i upload acceptor file into an ESP32, and upload initator file to an other ESP32?
And they can communicate with each other.
Am i thinking right?

To be honest i want to connect and OBD reader (that has Bluetooth) with an ESP32, but esp must start communicate.
I cant upload a code into OBD reader, it can just advertise itself.

Can it be possible?

Thanks answer.

ESP_Tianhao
Posts: 27
Joined: Thu Jan 05, 2017 10:46 am

Re: BT Classic communication between two ESP32

Postby ESP_Tianhao » Tue Sep 04, 2018 4:05 am

petitan wrote:So should i upload acceptor file into an ESP32, and upload initator file to an other ESP32?
And they can communicate with each other.
Am i thinking right?

To be honest i want to connect and OBD reader (that has Bluetooth) with an ESP32, but esp must start communicate.
I cant upload a code into OBD reader, it can just advertise itself.

Can it be possible?

Thanks answer.
Does your OBD reader support SPP? If yes, you can use ESP32 connect your OBD reader with SPP then do what you want.
You can take a look at the esp-idf/examples/bluetooth/bt_spp_acceptor and bt_spp_initiator.

petitan
Posts: 3
Joined: Fri Aug 31, 2018 10:33 am

Re: BT Classic communication between two ESP32

Postby petitan » Thu Sep 06, 2018 6:50 am

Thanks your answer :)

Now i can run all esp-idf example, spp_initiator and acceptor too.
But, when i run initiator, it lists all device around me with Name and with ADDRESS.
I see my odb reader too, its address: 00:80:98:25:CA:E8

Where should i change the example code to put this address.
I just want to connect to my obd.

Or should i run both of codes in same time?
Sry for being beginner :)

salento1201
Posts: 2
Joined: Thu Mar 15, 2018 5:14 pm

Re: BT Classic communication between two ESP32

Postby salento1201 » Mon Oct 29, 2018 11:23 pm

Crisos wrote:Hi Everyone,

I have a very simple application where one ESP32 sends a message over BT to another ESP32. I have been playing mostly with Arduinos till now and using that this kind of application was quite easy, but now I want to move to this platform.

Using BluetoothSerial.h library I can happily connect to an Android device and send those messages, but I can't start the connection from another ESP32. This library doesn't have a connect command, so I went and found out what is the control to connect via SPP and I seem to be able to find the other device and connect to it, but also seems like the connection crashes immediately afterwards.

Here the code I am using:

Code: Select all

#include "esp_bt_main.h"
#include "esp_gap_bt_api.h"
#include "esp_spp_api.h"
#include <BluetoothSerial.h>

uint8_t address[6] = {0x30, 0xAE, 0xA4, 0x21, 0xBA, 0xBA};
String MACadd = "30:AE:A4:21:BA:BA";

static const esp_spp_sec_t sec_mask = ESP_SPP_SEC_NONE;
static const esp_spp_role_t role_slave = ESP_SPP_ROLE_MASTER;
esp_err_t connHan;


BluetoothSerial SerialBT;

void setup() {
  Serial.begin(9600);
  Serial.println("The device is ready!");
  SerialBT.begin("Glove ESP");
  Serial.println("Looking for device...");
  if(esp_spp_start_discovery(address) == ESP_OK){
    Serial.println("Device found!");
  }
    else{
    Serial.println("Device not found :(");
  }
  
  connHan = esp_spp_connect(ESP_SPP_SEC_NONE, ESP_SPP_ROLE_MASTER, 3,address);
  if(connHan == ESP_OK){
    Serial.println("Device Connected!");
  }
    else{
    Serial.println("Device not connected :(");
  }
  delay(1000);
  
  if (SerialBT.hasClient() == true) {
        Serial.print("Client connected");
        
        //SerialBT.println("some text");
    } else {
        Serial.println("Client disconnected");
        esp_spp_disconnect(connHan);
        SerialBT.begin("Glove ESP");
        delay(1500);
    }
  
}
 
void loop() {
}
I tried with different SCN, but all the time I get this message: (not sure why it is not clear, like wrong baud)

Code: Select all

C'΂⸮⸮Θb⸮⸮`<⸮!⸮The device is ready!
Looking for device...
Device found!
Device Connected!
[0;31mE (1520) BT: btm_sec_connected
[0m
[0;31mE (1545) BT: l2cu_adjust_out_mps bad packet size: 0  will use MPS: 0[0m
[0;31mE (1554) BT: process_service_search_attr_rsp
[0m
[0;31mE (1604) BT: port_rfc_closed RFCOMM connection in state 1 closed: Closed (res: 19)[0m
Client disconnected
[0;31mE (2146) BT: btc_spp_disconnect unable to find RFCOMM slot! disconnect fail![0m
[0;31mE (2146) BT: JVenable fails[0m

Anyone can help? I have spent like two days on this and I couldn't imagine it could be so complicated!
Thank you in advance!
You could post the code to have a connection and bluetooth communication between two ESP32, I'm not succeeding
thank you

Who is online

Users browsing this forum: Bing [Bot] and 8 guests