Problem using BLE scan with WiFi webserver
Posted: Fri Apr 30, 2021 7:04 am
I'm trying to make a "continous" advertising scan while serving a webserver webpage.
I have the BLE scan working in one side and WiFi webpage webserver in another.
The problem begins when I try to merge them.
I want to give priority to the BLE scan because the webpage is only for configuration and rarely used.
Here is the code:
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp32")) {
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.on("/inline", []() {
server.send(200, "text/plain", "this works as well");
});
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop(void)
{
//printf("Async Scanning sample starting\n");
BLEDevice::init("");
uint8_t ADDR[6] = {0xd6,0x60,0xa2,0xda,0x9d,0xc4};
BLEDevice::whiteListAdd(ADDR);
BLEScan* pBLEScan = BLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks(), true);
pBLEScan->setActiveScan(true);
//pBLEScan->setScanFilter(true,true);
//printf("About to start scanning for 10 seconds\n");
pBLEScan->setInterval(100);
pBLEScan->setWindow(99);
pBLEScan->start(0, scanCompleteCB);
//printf("Now scanning in the background ... scanCompleteCB() will be called when done.\n");
//
// Now going into a loop logging that we are still alive.
//
while(1) {
server.handleClient();
//printf("Tick! - still alive\n");
//FreeRTOS::sleep(1000);
}
printf("Scanning sample ended\n");
} // app_main
Another try is to make 1s scan rutines with pBLEScan->start(1, scanCompleteCB); bur it doesn't work either.
Has anyone an example to do this?
Thank you a lot.
I have the BLE scan working in one side and WiFi webpage webserver in another.
The problem begins when I try to merge them.
I want to give priority to the BLE scan because the webpage is only for configuration and rarely used.
Here is the code:
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp32")) {
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.on("/inline", []() {
server.send(200, "text/plain", "this works as well");
});
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop(void)
{
//printf("Async Scanning sample starting\n");
BLEDevice::init("");
uint8_t ADDR[6] = {0xd6,0x60,0xa2,0xda,0x9d,0xc4};
BLEDevice::whiteListAdd(ADDR);
BLEScan* pBLEScan = BLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks(), true);
pBLEScan->setActiveScan(true);
//pBLEScan->setScanFilter(true,true);
//printf("About to start scanning for 10 seconds\n");
pBLEScan->setInterval(100);
pBLEScan->setWindow(99);
pBLEScan->start(0, scanCompleteCB);
//printf("Now scanning in the background ... scanCompleteCB() will be called when done.\n");
//
// Now going into a loop logging that we are still alive.
//
while(1) {
server.handleClient();
//printf("Tick! - still alive\n");
//FreeRTOS::sleep(1000);
}
printf("Scanning sample ended\n");
} // app_main
Another try is to make 1s scan rutines with pBLEScan->start(1, scanCompleteCB); bur it doesn't work either.
Has anyone an example to do this?
Thank you a lot.