🛠 Wi-Fi + BLE 5 : mesurer la coexistence

ESP32-C3 · avance · Schéma : IMG-esp32-c3-avance-1-wifi-ble5-coexistence.svg — ESP32-C3 mono-cœur avec radio unique 2,4 GHz, calendrier entrelaçant trames Wi-Fi et événements BLE

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials