Closing a Bluetooth connection that hasn't been used.
Posted: 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):
In cases a and b I get this in the serial monitor:
In the case c I get this:
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:
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?
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");
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?