Closing a Bluetooth connection that hasn't been used.

xgarbxgarb
Posts: 21
Joined: Fri Jan 25, 2019 3:36 pm

Closing a Bluetooth connection that hasn't been used.

Postby xgarbxgarb » Tue Dec 24, 2019 3:29 pm

I'm using serial Bluetooth so a user can set Wi-Fi details and read the IP address from a phone. I want to kill the Bluetooth connection when either:

a) The details have been entered correctly (via Bluetooth)
b) The device restarts and the user has viewed the IP address on their phone (via Bluetooth)
c) The device restarts and the user enters a previously known IP address in their browser

I'm using the following code to kill the connection (Not sure every command is necessary but I couldn't find documentation for this):

Code: Select all

  Serial.println("BT stopping");
  SerialBT.flush();  
  SerialBT.disconnect();
  SerialBT.end();
  Serial.println("BT stopped");
In cases a and b I get this in the serial monitor:
BT stopping
[V][BluetoothSerial.cpp:271] esp_spp_cb(): ESP_SPP_WRITE_EVT: 16 FREE
[V][BluetoothSerial.cpp:271] esp_spp_cb(): ESP_SPP_WRITE_EVT: 2 FREE
[BluetoothSerial.cpp:757] disconnect(): disconnecting
[BluetoothSerial.cpp:247] esp_spp_cb(): ESP_SPP_CLOSE_EVT
BT stopped


In the case c I get this:

BT stopping
BT stopped


The difference is that in a and b a callback has been called. For example b where the user has connected and has been sent the IP address looks like this:

Code: Select all

void callback_show_ip(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
{
  if (event == ESP_SPP_SRV_OPEN_EVT) {
    SerialBT.println("Device IP: ");
    SerialBT.println(WiFi.localIP());
  }
}

So... the question is. Why don't I see the 'ESP_SPP_CLOSE_EVT' message when I close a Bluetooth connection that hasn't been used?

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

Re: Closing a Bluetooth connection that hasn't been used.

Postby chegewara » Wed Dec 25, 2019 1:29 am

CLOSE event means close previously opened connection with peer device, not close bluetooth.

xgarbxgarb
Posts: 21
Joined: Fri Jan 25, 2019 3:36 pm

Re: Closing a Bluetooth connection that hasn't been used.

Postby xgarbxgarb » Fri Jan 31, 2020 5:53 pm

Thanks for the information. I've finished the project and put the code here: https://github.com/robotzero1/esp32-bluewifi if anyone is interested

Who is online

Users browsing this forum: No registered users and 88 guests