🛠 Coexistence Wi-Fi + Bluetooth sur antenne partagée
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
- 1 ESP32 DevKit v1 board
- 1 2.4 GHz Wi-Fi access point
- 1 BLE central (smartphone with nRF Connect)
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
- Expecting full Wi-Fi throughput while running intensive BLE: it is time-shared, not two radios.
- Minimal BLE connection interval (7.5 ms) combined with heavy Wi-Fi traffic: missed BLE events and disconnections.
- Forgetting that BLE and Wi-Fi occupy the same 2.4 GHz band: a congested Wi-Fi channel and a dense BLE environment interfere with each other.
- Board with external antenna: the RF switch selects only one; check the module's antenna pin (GPIO25/27 depending on variants).
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinorespiration.inoArduinodht22.inoArduinooled-i2c.inoArduinoserveur-web.inoArduino