How to disable/enable BLE? esp-idf (solved)
Posted: Thu Jul 25, 2019 4:26 pm
Hello,
In my project I need to use BLE and Wi-Fi. There's only one radio. I want to disable the BLE to use Wi-Fi. After Wi-Fi serves it's purpose, disable Wi-Fi, enable BLE. If user finished using BLE, disable BLE, enable Wi-Fi. So on and so on.
I tried using a command which is called FROM GATT (the user sends a command to the ESP from phone saying that he's finished using BLE). The command calls bluedroid disable and BT Controller disable. But the ESP gets stuck as soon as the bluedroid disable is called. My guess is that since I'm calling the disable functionality from the GATT itself, the rest of the code in that function (the BT Controller disable) doesn't get executed (since the bluedroid is disabled, the function is interrupted from completing).
I also tried moving the disable function to the main .c file, and calling the function from GATT, but the same behavior occurs, probably because though I moved the function, it's STILL called from GATT, so that's why I see same behavior.
Lastly, I moved the function to the app_main() just to test if the code is doing what I want. After the BLE server is set up there's a vTaskDelay which waits for 10 seconds then disables the BLE. This works as expected, on start I can see the GATT server and connect to it, the delay runs so after 10 seconds the GATT disconnects and the signal is lost (since it was disabled). Then there is a second vTaskDelay for another 10 seconds and then I want to enable BLE. Again, this is just to test that I'm doing BLE disable/enable correctly. Clearly, I am not, because when I call bluedroid and BT Controller enables (after second vTaskDelay), the ESP throws error:
BT_HCI: command_timed_out hci layer timeout waiting for response to a command. opcode: 0xc03
The BLE does not enable at this point.
So my question is: How can I enable/disable the BLE at will at any point in my code? I need my phone to connect for a bit, then say it's done which the ESP will disconnect and disable BLE. Then later, the BLE will be reenabled by some conditional statement, and the phone can reconnect!
I thought I just had to use bluedroid & BT Controller disable, then later, use bluedroid & BT Controller enable, but that isn't working. Also what's the correct way to make the ESP disable if I send the command from the phone itself?
By the way: I am using only esp-idf; NO Kolban, NO Arduino
Anything helps!
In my project I need to use BLE and Wi-Fi. There's only one radio. I want to disable the BLE to use Wi-Fi. After Wi-Fi serves it's purpose, disable Wi-Fi, enable BLE. If user finished using BLE, disable BLE, enable Wi-Fi. So on and so on.
I tried using a command which is called FROM GATT (the user sends a command to the ESP from phone saying that he's finished using BLE). The command calls bluedroid disable and BT Controller disable. But the ESP gets stuck as soon as the bluedroid disable is called. My guess is that since I'm calling the disable functionality from the GATT itself, the rest of the code in that function (the BT Controller disable) doesn't get executed (since the bluedroid is disabled, the function is interrupted from completing).
I also tried moving the disable function to the main .c file, and calling the function from GATT, but the same behavior occurs, probably because though I moved the function, it's STILL called from GATT, so that's why I see same behavior.
Lastly, I moved the function to the app_main() just to test if the code is doing what I want. After the BLE server is set up there's a vTaskDelay which waits for 10 seconds then disables the BLE. This works as expected, on start I can see the GATT server and connect to it, the delay runs so after 10 seconds the GATT disconnects and the signal is lost (since it was disabled). Then there is a second vTaskDelay for another 10 seconds and then I want to enable BLE. Again, this is just to test that I'm doing BLE disable/enable correctly. Clearly, I am not, because when I call bluedroid and BT Controller enables (after second vTaskDelay), the ESP throws error:
BT_HCI: command_timed_out hci layer timeout waiting for response to a command. opcode: 0xc03
The BLE does not enable at this point.
So my question is: How can I enable/disable the BLE at will at any point in my code? I need my phone to connect for a bit, then say it's done which the ESP will disconnect and disable BLE. Then later, the BLE will be reenabled by some conditional statement, and the phone can reconnect!
I thought I just had to use bluedroid & BT Controller disable, then later, use bluedroid & BT Controller enable, but that isn't working. Also what's the correct way to make the ESP disable if I send the command from the phone itself?
By the way: I am using only esp-idf; NO Kolban, NO Arduino
Anything helps!