-
Notifications
You must be signed in to change notification settings - Fork 7.6k
BLE refuses to connect when WiFi is connected #2401
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
Hi, here is my log:
and my sketch:
|
Thanks! @chegewara Does your sketch connect fine via BLE even when WiFi has already established a connection? I think maybe your bits to help with iPhone connection issues may help my connection issues. |
As you can see from logs i am not even starting BLE before i connect to wifi, but i think that makes no difference. Just wanted to test if i can connect to esp32 with ble client when esp32 is already connected to wifi:
|
Yeah, since a WiFi connection on my device isn't always guaranteed I can't wait for WiFi to connect before starting BLE. My sketch does attempt to connect to WiFi before starting the BLE service, but as soon as WiFi establishes connection I can no longer connect to BLE (It still advertises though). Maybe this is because I'm starting the BLE service prematurely... I wonder if I should scan for the WiFi network first, have a connection timeout if it sees the SSID but can't connect, and then start my BLE service. I guess my only concern at that point is the ESP32 taking too long to connect to the WiFi network and causing a short period of time where BLE is unavailable. |
I changed order and now first i initialize BLE and all wifi connection calls are at the end of setup and still no issue with connection. Maybe try with https://github.com/nkolban/esp32-snippets master. I just pushed code with some bugfixes. |
Thank you! |
guys, one question. should I merge arduino-esp32 with nkolban/esp32-snippets to fix? thanks in advance :) |
Unfortunately, when I add simple code for Firebase communication, EPS32 reboots because of panic:
|
This can be anything, but most likely heap/ram shortage. |
I was able to fix it with |
Do you experience any delays with your code #2401 (comment) when using BLE? #include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
BLECharacteristic *pCharacteristic;
bool deviceConnected = false;
#define SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E" // UART service UUID
#define CHARACTERISTIC_UUID_RX "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
#define CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
class MyServerCallbacks: public BLEServerCallbacks {
void onConnect(BLEServer* pServer) {
deviceConnected = true;
};
void onDisconnect(BLEServer* pServer) {
deviceConnected = false;
}
};
class MyCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
std::string rxValue = pCharacteristic->getValue();
}
};
void setup() {
BLEDevice::init("Test"); // Give it a name
BLEServer *pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());
BLEService *pService = pServer->createService(SERVICE_UUID);
pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_TX,
BLECharacteristic::PROPERTY_NOTIFY
);
pCharacteristic->addDescriptor(new BLE2902());
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_RX,
BLECharacteristic::PROPERTY_WRITE
);
pCharacteristic->setCallbacks(new MyCallbacks());
pService->start();
pServer->getAdvertising()->start();
}
void loop() {
if (deviceConnected) {
pCharacteristic->setValue("Hello!");
pCharacteristic->notify(); // Send the value to the app!
}
} |
Since i posted that code i am now in so different esp32 world. Its hard to say now if i got delays or not. |
@chegewara it looks like the issue happens when heavy code is executed during BLE work. Or it's timing issue inside SDK. |
Right now I have my ESP32 configured to automatically connect to WiFi when it is turned on.
I'm also allowing it to be connected via BLE for additional configuration.
For some reason, when it is connected to WiFi it still advertises BLE, but when I'm trying to connect the connection will outright fail. The only wany to properly connect via BLE is to reset the device and connect before it connects to WiFi.
Is there a way to detect when the ESP32 is making that initial handshake with my other devices? This way I can disconnect WiFi whenever someone attempts to connect to the ESP.
The text was updated successfully, but these errors were encountered: