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.
Problem using BLE scan with WiFi webserver
Re: Problem using BLE scan with WiFi webserver
Any answer?
Re: Problem using BLE scan with WiFi webserver
1) use BBCode to format code you are posting to make it easier readable
2) why you init BLE in loop instead of setup?
3) you didnt say what is wrong with your code, what is not working for you
4) i would personally change this code, but it all depends on your needs:
2) why you init BLE in loop instead of setup?
3) you didnt say what is wrong with your code, what is not working for you
4) i would personally change this code, but it all depends on your needs:
Code: Select all
pBLEScan->setInterval(189);
pBLEScan->setWindow(49);
Who is online
Users browsing this forum: No registered users and 58 guests