-
Notifications
You must be signed in to change notification settings - Fork 7.6k
BLE Client and WiFi Client simultaneously #2162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Did you try to have 2 separate tasks? |
Version with tasks: Code:#include <Arduino.h>
#include <WiFi.h>
#include "BLEDevice.h"
BLEClient* bleClient;
BLEAddress bleAddress = BLEAddress("<address>");
WiFiClient wifiClient;
void doBleStuff(void * parameter) {
delay(6000);
BLEDevice::init("");
bleClient = BLEDevice::createClient();
while(true) {
Serial.println("Connecting (BLE)...");
bleClient->connect(bleAddress);
Serial.println("Reading...");
std::string value = bleClient->getValue(BLEUUID("00001800-0000-1000-8000-00805f9b34fb"), BLEUUID("00002a00-0000-1000-8000-00805f9b34fb"));
Serial.print("Value: ");
Serial.println(value.c_str());
bleClient->disconnect();
Serial.println("Waiting (BLE)...");
delay(10000);
}
delete bleClient;
vTaskDelete(NULL);
}
void doWifiStuff(void * parameter) {
wifiClient = WiFiClient();
while(true) {
Serial.println("Connecting (WiFI)...");
WiFi.begin("<SSID>", "<PASSWD>");
delay(5000);
if (WiFi.waitForConnectResult() == WL_CONNECTED) {
Serial.print("WiFi connected. IP address: ");
Serial.println(WiFi.localIP());
}
Serial.println("Waiting (WiFi)...");
delay(500000);
Serial.println("Disconnecting (WiFI)...");
WiFi.disconnect();
}
vTaskDelete(NULL);
}
void setup() {
Serial.begin(115200);
xTaskCreate(doWifiStuff, "WifiTask", 10000, NULL, 1, NULL);
xTaskCreate(doBleStuff, "BleTask", 10000, NULL, 1, NULL);
}
void loop() {
delay(10000);
} Log:
For delay 5000 instead of 6000 it throw an exception:
or:
and for delay 1000 instead of 6000 it reads data for the first run and the second run is blecked again:
|
One more thing, if its possible try first obtain IP address and then start with ble. This is how i am doing my stuff. |
That's what i did in the the example with 6sec delay. Isn't it?
but it is still stopped on:
|
@nb-ceffa Please try this: Sorry for bad support from my side, i am very occupied lately. |
@chegewara I'm glad for any support from your side ;) the behavior is still the same :( and it sometimes throws an exception:
|
Could you try with different service UUID, it should work for all services, but i think its something wrong in here. |
This should be version with some improvements, but is not prepared PR yet: |
Hi @chegewara sorry for a long pause. I have updated to the newest lib (platformio "Espressif 32" 1.7.0): and current stacktrace is:
last few lines of log:
|
Second crash looks like this: Stacktrace:
last few lines of log:
|
any update on dis issue? facing the same... |
this error seems to be generated by BLERemoteCharacteristic::readValue() try this my fix: |
after applying #2800 I am facing new issue
|
|
|
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
It still does not work :(
stacktrace:
|
[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future. |
Try my repository, which fixes many bugs in BLEClient You can replace it completely, or you can copy only the minimum required files.
|
if you have fixes, why not contribute them here? |
@wakwak-koba I have copied your version of BLE but with the same result. BUT! I finally have found one of two issues!!! I will prepare pull request. The second issue is still present:
any idea? |
I also sometimes disconnected Bluetooth while using Bluetooth and WiFi at the same time. WiFi and Bluetooth share antennas, and when used at the same time, they seem to interfere and become unstable. |
@nb-ceffa |
@mrdc hmm that's really interesting! Could you please share the compiled version for MAC: 7D:D8:BE:22:96:21. I would like to try it on my HW. |
No problem. BTW MAC is not in compiled binary or I'm missing something? |
Unfortunately, after some tests with WiFI+BLE+HTTPS my ESP32 reboots after this error: |
@mdr the ESP FreeRTOS implementation of a counting semaphore results in a memory buffer of MAXCOUNT integers. so if you specify a CountingSempahore of 1000 max, it allocates a QUEUE of 1000 integer members. Base on the error, you are probably running out of RAM. Chuck. |
@stickbreaker 640kb ought to be enough for anybody, surely? |
I wonder how many kids get that joke? I remember trying to figure out DRAM refresh rates for a 16MHz 80386 CPU and 4GB DRAM. This was when the largest DRAM (16pin dip) was 64kbit. It was only theoretical, because to get 4GB you would have to have 524,288 chips at $10 each that is a bit much for a desktop PC! I really question the decision to use a QUEUE to simulate a CountingSemaphore. It seems to me to be a lazy approach. Chuck. |
Will ESP32 Wrover alone solve the issue with additional PSRAM - sketch will use bigger heap by default (some checks during compilation if PSRAM option enabled)? Or changes should be made? Is BT classic disabled by default during compilation? I've checked BLEDevice.cpp for
We are pretty close with ESP32: it has 520KB) |
Have tried code from @chegewara #2401 (comment) - it works OK without Firebase libs, but with libs again reboot because of panic (this time panic is different compared to my code):
Will try a different Firebase lib - maybe it will have less memory usage. |
Here is my debug log for BTE+WIFI+Firebase.
|
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions. |
Description:
Hi, I'm trying to use BLE Client and WiFi Client simultaneously but reading value from BLE device when WiFi is connected seems to be impossible. :( I have created simple demo attached below. Reading works fine when WiFi part is removed. Any idea what is wrong?
Thank you in advance!
Sketch:
Debug Messages:
Build log:
The text was updated successfully, but these errors were encountered: