espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.5k stars 7.39k forks source link

BLE unstable/unusable on ESP32 revision 3 board #7532

Closed Staacks closed 1 year ago

Staacks commented 1 year ago

Board

ESP-32 Dev Kit C V4 (with revision 3 ESP32)

Device Description

ESP-32 Dev Kit C V4 recently bought from az-delivery with a revision 3 chip, tested on about 50 of these boards. Same code was tested on an older dev board by az-delivery (https://www.az-delivery.de/products/esp32-developmentboard) as well as the older Dev Kit C board without any issue. The obvious difference of the newer board is that it has an ESP32-D0WD-V3 (revision 3), while the older ones all have an ESP32-D0WDQ6 (revision 1).

Hardware Configuration

The boards were tested bare - just a USB connection to the PC.

Version

v2.0.5

IDE Name

Arduino IDE

Operating System

Linux Mint

Flash frequency

80MHz

PSRAM enabled

no

Upload speed

921600

Description

Uploaded the BLE_server.ino example to a new ESP-32 Dev Kit C V4 with ESP32-D0WD-V3 and tryed to connect with nRF Connect after its reset. nRF connect can see the board, but after a connection attempt, it immediately disconnects with the (rather generic) error 133 GATT error. The behavior is slightly erratic as retries sometimes succeed, but failure is the more common outcome.

The same code was uploaded to another ESP-32 Dev Kit C (identical board layout as far as I can tell) with an ESP32-D0WDQ6 (revision 1) and the BLE connection works like a charm. Same goes for an even older dev board by az-delivery (hardware details section).

This behavior was observed with about 50 of these boards during a workshop in which we wanted to teach the use of our Arduino library (phyphoxBLE) to teachers, so while not all occurrences have been investigated, we can certainly say that it is not only affecting the one board I am testing more thoroughly now after the workshop failed spectacularly.

On the phone side I have observed this behavior on a Pixel 3 (Android 12), Pixel 6 (Android 13) and Samsung Galaxy S10 5G (Android 12). On iPhones (iPhone 8 and iPhone 14 Pro) the success rate is higher, but disconnects are common and the initial connect in nRF connect can easily take 10 seconds while the older boards connect immediately (I suspect that iOS does some fallback reconnect work in the background or is just more patient).

Sketch

//This is the exact code from the BLE_server.ino example (except for this comment)

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>

// See the following for generating UUIDs:
// https://www.uuidgenerator.net/

#define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"

void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE work!");

  BLEDevice::init("Long name works now");
  BLEServer *pServer = BLEDevice::createServer();
  BLEService *pService = pServer->createService(SERVICE_UUID);
  BLECharacteristic *pCharacteristic = pService->createCharacteristic(
                                         CHARACTERISTIC_UUID,
                                         BLECharacteristic::PROPERTY_READ |
                                         BLECharacteristic::PROPERTY_WRITE
                                       );

  pCharacteristic->setValue("Hello World says Neil");
  pService->start();
  // BLEAdvertising *pAdvertising = pServer->getAdvertising();  // this still is working for backward compatibility
  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->addServiceUUID(SERVICE_UUID);
  pAdvertising->setScanResponse(true);
  pAdvertising->setMinPreferred(0x06);  // functions that help with iPhone connections issue
  pAdvertising->setMinPreferred(0x12);
  BLEDevice::startAdvertising();
  Serial.println("Characteristic defined! Now you can read it in your phone!");
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(2000);
}

Debug Message

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13864
load:0x40080400,len:3608
entry 0x400805f0
[     3][D][esp32-hal-cpu.c:244] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Starting BLE work!
[   713][V][BLEDevice.cpp:76] createServer(): >> createServer
[   713][V][BLEServer.cpp:290] registerApp(): >> registerApp - 0
[   713][V][FreeRTOS.cpp:189] take(): Semaphore taking: name: RegisterAppEvt (0x3ffdb664), owner: <N/A> for registerApp
[   723][V][FreeRTOS.cpp:198] take(): Semaphore taken:  name: RegisterAppEvt (0x3ffdb664), owner: registerApp
[   733][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: RegisterAppEvt (0x3ffdb664), owner: registerApp for registerApp
[   733][D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... ESP_GATTS_REG_EVT
[   755][V][BLEUtils.cpp:1530] dumpGattServerEvent(): GATT ServerEvent: ESP_GATTS_REG_EVT
[   763][V][BLEUtils.cpp:1673] dumpGattServerEvent(): [status: ESP_GATT_OK, app_id: 0]
[   771][V][BLEServer.cpp:144] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_REG_EVT
[   779][V][FreeRTOS.cpp:143] give(): Semaphore giving: name: RegisterAppEvt (0x3ffdb664), owner: registerApp
[   789][V][BLEServer.cpp:280] handleGATTServerEvent(): << handleGATTServerEvent
[   789][V][FreeRTOS.cpp:77] wait(): << wait: Semaphore released: name: RegisterAppEvt (0x3ffdb664), owner: <N/A>
[   806][V][BLEServer.cpp:294] registerApp(): << registerApp
[   812][V][BLEDevice.cpp:83] createServer(): << createServer
[   817][V][BLEServer.cpp:67] createService(): >> createService - 4fafc201-1fb5-459e-8fcc-c5c9c331914b
[   826][V][FreeRTOS.cpp:189] take(): Semaphore taking: name: CreateEvt (0x3ffdb958), owner: <N/A> for createService
[   836][V][FreeRTOS.cpp:198] take(): Semaphore taken:  name: CreateEvt (0x3ffdb958), owner: createService
[   846][V][BLEService.cpp:60] executeCreate(): >> executeCreate() - Creating service (esp_ble_gatts_create_service) service uuid: 4fafc201-1fb5-459e-8fcc-c5c9c331914b
[   860][V][FreeRTOS.cpp:189] take(): Semaphore taking: name: CreateEvt (0x3ffdbd68), owner: <N/A> for executeCreate
[   871][V][FreeRTOS.cpp:198] take(): Semaphore taken:  name: CreateEvt (0x3ffdbd68), owner: executeCreate
[   880][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: CreateEvt (0x3ffdbd68), owner: executeCreate for executeCreate
[   880][D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... ESP_GATTS_CREATE_EVT
[   902][V][BLEUtils.cpp:1530] dumpGattServerEvent(): GATT ServerEvent: ESP_GATTS_CREATE_EVT
[   911][V][BLEUtils.cpp:1599] dumpGattServerEvent(): [status: ESP_GATT_OK, service_handle: 40 0x28, service_id: [uuid: 4fafc201-1fb5-459e-8fcc-c5c9c331914b, inst_id: 0]]
[   925][V][BLEServer.cpp:144] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_CREATE_EVT
[   935][V][FreeRTOS.cpp:143] give(): Semaphore giving: name: CreateEvt (0x3ffdb958), owner: createService
[   944][V][BLEService.cpp:194] setHandle(): >> setHandle - Handle=0x28, service UUID=4fafc201-1fb5-459e-8fcc-c5c9c331914b)
[   955][V][BLEService.cpp:200] setHandle(): << setHandle
[   960][V][FreeRTOS.cpp:143] give(): Semaphore giving: name: CreateEvt (0x3ffdbd68), owner: executeCreate
[   969][V][BLEServer.cpp:280] handleGATTServerEvent(): << handleGATTServerEvent
[   969][V][FreeRTOS.cpp:77] wait(): << wait: Semaphore released: name: CreateEvt (0x3ffdbd68), owner: <N/A>
[   986][V][BLEService.cpp:76] executeCreate(): << executeCreate
[   992][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: CreateEvt (0x3ffdb958), owner: <N/A> for createService
[  1003][V][FreeRTOS.cpp:77] wait(): << wait: Semaphore released: name: CreateEvt (0x3ffdb958), owner: <N/A>
[  1012][V][BLEServer.cpp:83] createService(): << createService
[  1018][V][BLEService.cpp:222] addCharacteristic(): >> addCharacteristic()
[  1024][D][BLEService.cpp:225] addCharacteristic(): Adding characteristic: uuid=beb5483e-36e1-4688-b7f5-ea07361b26a8 to service: UUID: 4fafc201-1fb5-459e-8fcc-c5c9c331914b, handle: 0x0028
[  1041][V][BLEService.cpp:237] addCharacteristic(): << addCharacteristic()
[  1048][V][BLECharacteristic.cpp:659] setValue(): >> setValue: length=21, data=48656c6c6f20576f726c642073617973204e65696c, characteristic UUID=beb5483e-36e1-4688-b7f5-ea07361b26a8
[  1063][V][FreeRTOS.cpp:189] take(): Semaphore taking: name: SetValue (0x3ffdc048), owner: <N/A> for <Unknown>
[  1073][V][FreeRTOS.cpp:198] take(): Semaphore taken:  name: SetValue (0x3ffdc048), owner: <Unknown>
[  1082][V][FreeRTOS.cpp:143] give(): Semaphore giving: name: SetValue (0x3ffdc048), owner: <Unknown>
[  1091][V][BLECharacteristic.cpp:668] setValue(): << setValue
[  1097][V][BLEService.cpp:134] start(): >> start(): Starting service (esp_ble_gatts_start_service): UUID: 4fafc201-1fb5-459e-8fcc-c5c9c331914b, handle: 0x0028
[  1111][V][BLECharacteristic.cpp:79] executeCreate(): >> executeCreate()
[  1117][D][BLECharacteristic.cpp:90] executeCreate(): Registering characteristic (esp_ble_gatts_add_char): uuid: beb5483e-36e1-4688-b7f5-ea07361b26a8, service: UUID: 4fafc201-1fb5-459e-8fcc-c5c9c331914b, handle: 0x0028
[  1136][V][FreeRTOS.cpp:189] take(): Semaphore taking: name: CreateEvt (0x3ffdc208), owner: <N/A> for executeCreate
[  1147][V][FreeRTOS.cpp:198] take(): Semaphore taken:  name: CreateEvt (0x3ffdc208), owner: executeCreate
[  1156][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: CreateEvt (0x3ffdc208), owner: executeCreate for executeCreate
[  1156][D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... ESP_GATTS_ADD_CHAR_EVT
[  1179][V][BLEUtils.cpp:1530] dumpGattServerEvent(): GATT ServerEvent: ESP_GATTS_ADD_CHAR_EVT
[  1187][V][BLEUtils.cpp:1553] dumpGattServerEvent(): [status: ESP_GATT_OK, attr_handle: 42 0x2a, service_handle: 40 0x28, char_uuid: beb5483e-36e1-4688-b7f5-ea07361b26a8]
[  1202][V][BLEServer.cpp:144] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_ADD_CHAR_EVT
[  1211][V][BLECharacteristic.cpp:604] setHandle(): >> setHandle: handle=0x2a, characteristic uuid=beb5483e-36e1-4688-b7f5-ea07361b26a8
[  1223][V][BLECharacteristic.cpp:606] setHandle(): << setHandle
[  1229][V][BLECharacteristic.cpp:205] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_ADD_CHAR_EVT
[  1239][V][FreeRTOS.cpp:143] give(): Semaphore giving: name: CreateEvt (0x3ffdc208), owner: executeCreate
[  1248][V][BLECharacteristic.cpp:465] handleGATTServerEvent(): << handleGATTServerEvent
[  1248][V][FreeRTOS.cpp:77] wait(): << wait: Semaphore released: name: CreateEvt (0x3ffdc208), owner: <N/A>
[  1256][V][BLEServer.cpp:280] handleGATTServerEvent(): << handleGATTServerEvent
[  1265][V][BLECharacteristic.cpp:116] executeCreate(): << executeCreate
[  1279][V][FreeRTOS.cpp:189] take(): Semaphore taking: name: StartEvt (0x3ffdbe30), owner: <N/A> for start
[  1288][V][FreeRTOS.cpp:198] take(): Semaphore taken:  name: StartEvt (0x3ffdbe30), owner: start
[  1297][V][FreeRTOS.cpp:63] wait(): >> wait: Semaphore waiting: name: StartEvt (0x3ffdbe30), owner: start for start
[  1297][D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... ESP_GATTS_START_EVT
[  1318][V][BLEUtils.cpp:1530] dumpGattServerEvent(): GATT ServerEvent: ESP_GATTS_START_EVT
[  1326][V][BLEUtils.cpp:1686] dumpGattServerEvent(): [status: ESP_GATT_OK, service_handle: 0x28]
[  1334][V][BLEServer.cpp:144] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_START_EVT
[  1343][V][FreeRTOS.cpp:143] give(): Semaphore giving: name: StartEvt (0x3ffdbe30), owner: start
[  1352][V][BLECharacteristic.cpp:205] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_START_EVT
[  1352][V][FreeRTOS.cpp:77] wait(): << wait: Semaphore released: name: StartEvt (0x3ffdbe30), owner: <N/A>
[  1362][V][BLECharacteristic.cpp:465] handleGATTServerEvent(): << handleGATTServerEvent
[  1371][V][BLEService.cpp:159] start(): << start()
[  1379][V][BLEServer.cpp:280] handleGATTServerEvent(): << handleGATTServerEvent
[  1384][I][BLEDevice.cpp:577] getAdvertising(): create advertising
[  1397][D][BLEDevice.cpp:579] getAdvertising(): get advertising
[  1402][V][BLEDevice.cpp:584] startAdvertising(): >> startAdvertising
[  1409][D][BLEDevice.cpp:579] getAdvertising(): get advertising
[  1414][V][BLEAdvertising.cpp:187] start(): >> start: customAdvData: 0, customScanResponseData: 0
[  1423][D][BLEAdvertising.cpp:199] start(): - advertising service: 4fafc201-1fb5-459e-8fcc-c5c9c331914b
[  1432][V][BLEAdvertising.cpp:252] start(): << start
[  1437][V][BLEDevice.cpp:586] startAdvertising(): << startAdvertising
[  1436][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT
Characteristic defined! Now you can read it in your phone!
[  1453][V][BLEUtils.cpp:1056] dumpGapEvent(): [status: 0]
[  1463][D][BLEDevice.cpp:579] getAdvertising(): get advertising
[  1469][D][BLEAdvertising.cpp:506] handleGAPEvent(): handleGAPEvent [event no: 0]
[  1476][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT
[  1486][V][BLEUtils.cpp:1206] dumpGapEvent(): [status: 0]
[  1491][D][BLEDevice.cpp:579] getAdvertising(): get advertising
[  1497][D][BLEAdvertising.cpp:506] handleGAPEvent(): handleGAPEvent [event no: 1]
[  1504][V][BLEUtils.cpp:1049] dumpGapEvent(): Received a GAP event: ESP_GAP_BLE_ADV_START_COMPLETE_EVT
[  1513][V][BLEUtils.cpp:1074] dumpGapEvent(): [status: 0]
[  1518][D][BLEDevice.cpp:579] getAdvertising(): get advertising
[  1524][D][BLEAdvertising.cpp:506] handleGAPEvent(): handleGAPEvent [event no: 6]

(Note that this is all dumped before the connection attempt and there is no additional output when nRF Connect tries to connect to the device but fails.)

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

Staacks commented 1 year ago

Update: I have bought several ESP32-DevKitC-32E and ESP32-Wroom-32E-N4 and none of them exhibit the issue. Therefore I would say that this issue can be closed here and I have to discuss this with AZ-Delivery.

ollivierv commented 1 year ago

@Staacks I have EXACTLY the same problem as you. I have TWO "ESP-32 Dev Kit C V4 (with revision 3 ESP32)" boards from AZ-Delivery. One with ESP32-D0WDQ6 and the other with a ESP32-D0WDQ5, both use ESP32-D0WD-V3. I lost days to figure what happened here, the ESP32-D0WDQ6 work perfectly in BLE (Arduino example), the other, the ESP32-D0WDQ5, appear and disappear while PC is scanning BLE, and connection never succeed ! To be SURE, I built and used raw example from the Espressif SDK 5.0.1 (ble/gatt_server), and SAME behaviour !

I guess there is a VERY problematic PCB/Antenna adaptation with ESP32-D0WDQ5 in this design !

Here a shot of linux "bluetoothctl" while scanning. The board appear/disappear even without any interaction. image