toughc5-ble-sensor-hub.ino
BLE 5.0 device scanning and displaying MAC addresses and RSSI on the IPS screen.
Uses the native BLE stack of the ESP32-C5. Active mode improves detection but consumes more power. The touchscreen allows visual validation of nearby sensors. Ideal for IoT troubleshooting.
toughc5-ble-sensor-hub.ino
#include <M5ToughC5.h>
#include <BLEDevice.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
int scanTime = 5; //In seconds
BLEScan* pBLEScan;
void setup() {
M5.begin();
M5.Display.init();
M5.Display.setTextColor(WHITE);
M5.Display.drawString("BLE Scanner", 10, 10);
BLEDevice::init("ToughC5-Hub");
pBLEScan = BLEDevice::getScan();
pBLEScan->setActiveScan(true);
pBLEScan->setInterval(100);
pBLEScan->setWindow(99);
}
void loop() {
M5.Display.clear();
M5.Display.drawString("Scanning BLE...", 10, 10);
BLEScanResults* foundDevices = pBLEScan->start(scanTime, false);
M5.Display.clear();
M5.Display.drawString("Devices Found:", 10, 10);
int count = foundDevices->getCount();
for (int i = 0; i < count && i < 5; i++) {
BLEAdvertisedDevice d = foundDevices->getDevice(i);
M5.Display.printf("%s\nRSSI: %d\n", d.getAddress().toString().c_str(), d.getRSSI());
}
pBLEScan->clearResults();
delay(2000);
}