Wednesday, April 22, 2026

0000 0001 0000 1110

A little ripper!

In the middle of weeks of rabbit holes regarding the sleeping PFS154, a ray of light arrived in the form of the XIAO ESP-32 C5.

I'd ordered it for projects where a strong 5GHz connection was more preferable to the crowded 2.4GHz band in my house where "smart" lights jostled for attention on my horrible router (another video sometime perhaps).

All I wanted to do was to test if it really was dual band, so the following code emerged after a brief session with Gemini - and yes - the little guy came through.

Here is the code you will need...


/*
  OneCircuit ESP32-C5 Dual-Band Discovery Demo
  Target: Espressif ESP32-C5 (Dual-Band Wi-Fi 6)

  YouTube: https://www.youtube.com/@onecircuit-as
  Blog: https://onecircuit.blogspot.com/
  Github: https://github.com/bovineck/
  
  IMPORTANT: This code requires ESP32 Arduino Core v3.0.0 or higher.
  The ESP32-C5 is a dual-band SoC (2.4GHz and 5GHz). 
  1. This demo scans each band separately using setBandMode().
  2. To protect privacy, SSIDs are NOT printed to the Serial Monitor.
  3. Signal strength (RSSI) is used to verify the discovery of local bands.
  4. An external antenna is required for optimal 5GHz performance.

  Wed 22 Apr 2026 18:45:00 AEST

  DEVICE = XIAO ESP32-C5
       __________
      /  FRONT   |
  1--|D0       5V|--14
  2--|D1      GND|--13
  3--|D2     3.3V|--12
  4--|D3      D10|--11
  5--|D4       D9|--10
  6--|D5       D8|--9
  7--|D6       D7|--8
     |___________| 

*/

#include "WiFi.h"

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA); // Set to station mode
  WiFi.disconnect();
  delay(100);
  Serial.println("--- ESP32-C5 Privacy Dual-Band Scan ---");
}

void scanBand(const char* bandLabel, wifi_band_mode_t bandMode) {
  // Set the hardware to the specific band
  WiFi.setBandMode(bandMode);
  
  Serial.printf("Scanning %s band... ", bandLabel);
  int n = WiFi.scanNetworks();
  
  if (n <= 0) {
    Serial.printf("No %s SSIDs discovered.\n", bandLabel);
  } else {
    int strongestRSSI = -100; // Start low
    
    // Find the strongest signal without storing or printing SSIDs
    for (int i = 0; i < n; ++i) {
      if (WiFi.RSSI(i) > strongestRSSI) {
        strongestRSSI = WiFi.RSSI(i);
      }
    }
    
    Serial.printf("A %s SSID has been discovered with the following strength: %d dBm\n", 
                  bandLabel, strongestRSSI);
  }
  
  WiFi.scanDelete(); // Clear results from memory
}

void loop() {
  // 1. Scan 2.4 GHz
  scanBand("2.4GHz", WIFI_BAND_MODE_2G_ONLY);
  delay(1000);

  // 2. Scan 5 GHz
  scanBand("5GHz", WIFI_BAND_MODE_5G_ONLY);
  
  Serial.println("------------------------------------------");
  delay(5000); // Wait 5 seconds before the next update
}

One caveat - there is no onboard antenna, you will need to plug in the provided external antenna to ensure a strong connection - the difference is remarkable, see results below.

Before external antenna:

------------------------------------------
Scanning 2.4GHz band... A 2.4GHz SSID has been discovered with the following strength: -86 dBm
Scanning 5GHz band... A 5GHz SSID has been discovered with the following strength: -56 dBm
------------------------------------------

After external antenna:

------------------------------------------
Scanning 2.4GHz band... A 2.4GHz SSID has been discovered with the following strength: -17 dBm
Scanning 5GHz band... A 5GHz SSID has been discovered with the following strength: -26 dBm
------------------------------------------

Here's the (brief and interrupted) video below - enjoy!



No comments:

Post a Comment