🛠 Coexistence Wi-Fi + Bluetooth sur antenne partagée

ESP32 (original, ESP32-WROOM-32 class) · avance · Schéma : IMG-esp32-avance-2-coexistence-wifi-bt-antenne.svg — Puce ESP32 avec un seul radio 2,4 GHz et une antenne partagée, découpage du temps entre Wi-Fi et BLE

Objectives

Understand that the ESP32 has only one 2.4 GHz radio and an antenna shared between Wi-Fi and Bluetooth: the coexistence layer time-slices between the two protocols. You will measure the impact of BLE activity on a Wi-Fi transfer and learn best practices (connection intervals, channels, role distribution between the two cores).

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("ESP32-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.printf("\nIP %s, RSSI %d\n",
                WiFi.localIP.toString.c_str, WiFi.RSSI);
}

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 (BLE notify emis)\n",
                code, octets, millis - t0);
  delay(3000);
}

Expected verification

The HTTP transfer and BLE notifications work simultaneously: coexistence is operational. However, by comparing transfer times with and without BLE advertising, a clear degradation in Wi-Fi throughput is observed: the single radio time-slices between the two protocols.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials