Bluetooth scanner on wiki page example can't see adverts from server example

Hi

I have been having a problem using Bluetooth code examples on the “Bluetooth Usage on Seeed Studio XIAO ESP32C3” in the Seeed Wiki (Bluetooth Usage on Seeed Studio XIAO ESP32C3 - Seeed Wiki). I have been unable to pick up an advertisement from the Bluetooth server example using the Bluetooth client example.

Here is the problem.

I acquired a pair of Seeed Xiao ESP32C3 modules. I used the Arduino IDE to upload the examples from the Seeed Xiao Wiki to the two devices. I uploaded the Bluetooth scanner example code to Xiao #1, and I uploaded ran the Bluetooth server example to Xiao #2. I made no changes to the example code.

Using the two independently, I could run the Bluetooth scanner example on Xiao #1, and the output in the Serial Monitor showed Bluetooth advertisements from both my desktop PC and my iPhone. But Xiao #1 would not show advertisements from Xiao #2. However, both Bluetooth and other devices section in the Windows Control Panel on my desktop PC and the Light Blue app on my iPhone would show that they could detect advertisements from Xiao #2.

What am I doing wrong? Why can’t Xiao #1 detect the Bluetooth server running on Xiao #2.

Can you put up the code for XIAO #1?

It is essentially the code from the SEEED Wiki article.
Here it is.

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>

int scanTime = 10; //In seconds
BLEScan* pBLEScan;

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
Serial.printf(“Advertised Device: %s \n”, advertisedDevice.toString().c_str());
}
};

void setup() {
Serial.begin(115200);
Serial.println(“Scanning…”);

BLEDevice::init("");
pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
pBLEScan->setInterval(100);
pBLEScan->setWindow(99); // less or equal setInterval value
}

void loop() {
// put your main code here, to run repeatedly:
BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
Serial.print("Devices found: ");
Serial.println(foundDevices.getCount());
Serial.println(“Scan done!”);
pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
delay(2000);
}

Hi rjz,
I tried the wiki sketches.
Once connected to the PC or iPhone and reading “Hello World”, the XIAO#1 will not be able to detect it.
Turn off BLE on the PC or iPhone. Reset XIAO#2. Then XIAO#2 will be visible.
You should see on the XIAO#2 serial monitor “Advertised Device: Name: MyESP32, Address: xx:xx:xx:xx:xx:xx:xx, txPower: 9”.

To be sure, add a delay after Serial.begin(), like delay(5000), and bring up the serial monitor during this time.

Hi msfujino,

Yes.

That appears to have been the problem.

I think that I did the server example first and somehow paired it with the Light Blue app on my iPhone.

Once I broke the connection and reset everything. Xiao #2 started to
show up in the scan on Xiao#1.

Thanks.