🛠 Wi-Fi + BLE 5 : mesurer la coexistence
Objectives
The ESP32-C3 combines Wi-Fi and Bluetooth 5 on a single core and a single 2.4 GHz radio. This tutorial measures the actual degradation when both protocols run together, and establishes engineering rules: BLE connection intervals, packet sizes, and Wi-Fi modem wake-up. You will learn how to size a mixed product without unpleasant surprises.
Hardware
- 1 ESP32-C3 board
- 1 2.4 GHz router and a test HTTP server
- Smartphone with nRF Connect for the BLE part
Complete code
#include <WiFi.h>
#include <HTTPClient.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
BLECharacteristic* cNotif;
void setup {
Serial.begin(115200);
BLEDevice::init("C3-COEX");
BLEServer* srv = BLEDevice::createServer;
BLEService* svc = srv->createService("180A");
cNotif = svc->createCharacteristic("2A19",
BLECharacteristic::PROPERTY_NOTIFY);
cNotif->addDescriptor(new BLE2902);
svc->start;
BLEDevice::getAdvertising->start;
WiFi.mode(WIFI_STA);
WiFi.begin("MON_SSID", "MA_CLE");
while (WiFi.status != WL_CONNECTED) { delay(300); Serial.print('.'); }
Serial.println;
}
void loop {
uint32_t t0 = millis;
HTTPClient http;
http.begin("http://exemple.local/test-1mo.bin");
int code = http.GET;
int32_t octets = http.getSize;
http.end;
uint8_t v = (uint8_t)(millis / 1000);
cNotif->setValue(&v, 1);
cNotif->notify;
Serial.printf("HTTP %d, %d o en %lu ms + notify BLE\n",
code, octets, millis - t0);
delay(3000);
}
Expected verification
Both protocols function simultaneously, but the HTTP transfer time increases significantly as soon as BLE is active (advertising then notifications). By disabling BLE advertising, the same transfer becomes fast again: the penalty indeed comes from sharing the single radio, not from the core.
Common errors
- Believing that a second core mitigates the cost: the C3 is single-core, coexistence is purely time-based on the radio.
- BLE notifications every 10 ms during a Wi-Fi stream: high-priority BLE events starve throughput; space out or group the data.
- Forgetting the Wi-Fi modem-sleep mode (WiFi.setSleep(true)) in a battery-powered product.
- Wi-Fi channels 12-14 overlapping with BLE advertising channels 37-38: prefer Wi-Fi channels 1 to 11 and keep BLE advertising channels free.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinorespiration.inoArduinodht22.inoArduinooled-i2c.inoArduinoserveur-web.inoArduino