-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Simultaneous BLE causes WiFiMulti.run to fail on 3.0.0 #9736
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
It has to be something really really subtle with the way BLE and WiFiMulti are instantiated and initialized. This code works, even though it should be functionally identical to the non-working example above: #define GLOBAL_WIFIMULTI 1
#define START_WIFIMULTI_BEFORE_BLE 0
#define START_BLE 1
#include <WiFi.h>
#include <WiFiMulti.h>
#if (GLOBAL_WIFIMULTI)
WiFiMulti wifiMulti;
#endif
#define WIFI_SSID "<ADD_YOUR_WIFI_SSID_HERE>"
#define WIFI_PASSWORD "<ADD_YOUR_WIFI_PASSWORD_HERE>"
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
void setup() {
delay(1000);
Serial.begin(115200);
#if (START_WIFIMULTI_BEFORE_BLE)
startWiFiMulti();
#endif
#if (START_BLE)
Serial.println("Starting BLE work!");
BLEDevice::init("Long name works now");
BLEServer *pServer = BLEDevice::createServer();
BLEService *pService = pServer->createService(SERVICE_UUID);
BLECharacteristic *pCharacteristic =
pService->createCharacteristic(CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE);
pCharacteristic->setValue("Hello World says Neil");
pService->start();
// BLEAdvertising *pAdvertising = pServer->getAdvertising(); // this still is working for backward compatibility
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
pAdvertising->addServiceUUID(SERVICE_UUID);
pAdvertising->setScanResponse(true);
pAdvertising->setMinPreferred(0x06); // functions that help with iPhone connections issue
pAdvertising->setMinPreferred(0x12);
BLEDevice::startAdvertising();
Serial.println("Characteristic defined! Now you can read it in your phone!\r\n");
delay(1000);
#endif
}
void loop() {
static int attempt = 0;
Serial.printf("\r\nLoop start : attempt %d\r\n\r\n", ++attempt);
startWiFiMulti();
}
void startWiFiMulti() {
Serial.println("\r\nLoop start\r\n");
WiFi.mode(WIFI_STA);
delay(1000);
#if (GLOBAL_WIFIMULTI)
static bool ssidAdded = false;
if(!ssidAdded) {
wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);
ssidAdded = true;
}
#else
WiFiMulti wifiMulti;
wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);
#endif
Serial.println("\r\nConnecting to Wifi\r\n");
if (wifiMulti.run() == WL_CONNECTED) {
Serial.print("\r\nWiFi connected with IP address: ");
Serial.println(WiFi.localIP());
Serial.println("");
}
else {
Serial.println("\r\nWiFi connect failed!\r\n");
// Wait for second scan to complete : [D][WiFiMulti.cpp:313] run(): [WIFI] start scan
for (int i = 0; i < 110; i++)
delay(100);
}
Serial.println("");
delay(1000);
WiFi.mode(WIFI_OFF);
delay(1000);
}
|
what actually happens is that for some reason the first sketch takes too long to scan (same on my end) and the second scans in about 8 seconds. Timeout is set to 10 seconds, so it timeouts before results come. I will add a fix for the timeout to WiFiMulti |
@PaulZC you can try this fix: https://github.com/espressif/arduino-esp32/pull/9738/files |
@me-no-dev : sincere thanks for the very fast fix! The fix works for me - both in my simple example and in our much larger product firmware. Thanks again - and have a great weekend, Just for information - for anyone else reading this issue:
|
Board
ESP32-WROOM-32E but also ESP32-WROVER-IE with PSRAM
Device Description
SparkFun ESP32 Thing Plus C
Hardware Configuration
No
Version
v3.0.0
IDE Name
Arduino IDE 1.8.19 - but also seen with the CLI
Operating System
Windows
Flash frequency
80MHz
PSRAM enabled
no
Upload speed
921600
Description
We have been using simultaneous BLE and WiFi successfully for at least two years, on arduino-esp32 <= 2.0.11. We are migrating to 3.0.0 and have noticed that having BLE enabled causes WiFiMulti.run to fail to connect... We've distilled the issue into the following sketch. Change START_BLE to 0 to disable BLE see the code run normally.
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: