Skip to content

Writing >20 Bytes to Characteristic causes all registered Write Callbacks to fire #4046

Closed
@emitategh

Description

@emitategh

As explained in title: When sending more than 20 bytes to any Characteristic causes all registered Write Callbacks to fire.

Board: ESP32 DevKit v1
Chip: ESP32D0WDQ6 (revision
Features: WiFi, BT, Dual Core, 240MHz
Auto-detected Flash size: 4MB
Core Instalation date: 01/05/2020
IDE: Arduino 1.8.12
Upload Speed: 115200
Computer OS: Windows 10 Pro

Description:
Same as title

Example Sketch

#include <Arduino.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include <BLECharacteristic.h>
// See the following for generating UUIDs:
// https://www.uuidgenerator.net/

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

class Characteristic1_Callbacks: public BLECharacteristicCallbacks {
  void onRead(BLECharacteristic *pCharacteristic){
    Serial.println("Characteristic1 Read");
  }
  void onWrite(BLECharacteristic *pCharacteristic){
    Serial.print("Characteristic1 Written: ");
    Serial.println((char *) pCharacteristic->getData());
  }
};

class Characteristic2_Callbacks: public BLECharacteristicCallbacks {
  void onRead(BLECharacteristic *pCharacteristic){
    Serial.println("Characteristic2 Read");
  }
  void onWrite(BLECharacteristic *pCharacteristic){
    Serial.print("Characteristic2 Written: ");
    Serial.println((char *) pCharacteristic->getData());
  }
};

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(
                                         CHARACTERISTIC1_UUID,
                                         BLECharacteristic::PROPERTY_READ |
                                         BLECharacteristic::PROPERTY_WRITE
                                       );
  pCharacteristic->setCallbacks(new Characteristic1_Callbacks());
  pCharacteristic->setValue("I am Characteristic #1");


  pCharacteristic = pService->createCharacteristic(
                                         CHARACTERISTIC2_UUID,
                                         BLECharacteristic::PROPERTY_READ |
                                         BLECharacteristic::PROPERTY_WRITE
                                       );
  pCharacteristic->setCallbacks(new Characteristic2_Callbacks());
  pCharacteristic->setValue("I am Characteristic #2");

  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 Messages:

Starting BLE work!
[D][FreeRTOS.cpp:189] take(): Semaphore taking: name: RegisterAppEvt (0x3ffdd05c), owner: <N/A> for registerApp
[D][FreeRTOS.cpp:198] take(): Semaphore taken:  name: RegisterAppEvt (0x3ffdd05c), owner: registerApp
[D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... Unknown
[D][FreeRTOS.cpp:189] take(): Semaphore taking: name: CreateEvt (0x3ffdd2b4), owner: <N/A> for createService
[D][FreeRTOS.cpp:198] take(): Semaphore taken:  name: CreateEvt (0x3ffdd2b4), owner: createService
[D][FreeRTOS.cpp:189] take(): Semaphore taking: name: CreateEvt (0x3ffdd518), owner: <N/A> for executeCreate
[D][FreeRTOS.cpp:198] take(): Semaphore taken:  name: CreateEvt (0x3ffdd518), owner: executeCreate
[D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... Unknown
[D][BLEService.cpp:225] addCharacteristic(): Adding characteristic: uuid=aeb5483e-36e1-4688-b7f5-ea07361b26a8 to service: UUID: 4fafc201-1fb5-459e-8fcc-c5c9c331914b, handle: 0x0028
[D][FreeRTOS.cpp:189] take(): Semaphore taking: name: SetValue (0x3ffddb88), owner: <N/A> for <Unknown>
[D][FreeRTOS.cpp:198] take(): Semaphore taken:  name: SetValue (0x3ffddb88), owner: <Unknown>
[D][BLEService.cpp:225] addCharacteristic(): Adding characteristic: uuid=beb5483e-36e1-4688-b7f5-ea07361b26a8 to service: UUID: 4fafc201-1fb5-459e-8fcc-c5c9c331914b, handle: 0x0028
[D][FreeRTOS.cpp:189] take(): Semaphore taking: name: SetValue (0x3ffde714), owner: <N/A> for <Unknown>
[D][FreeRTOS.cpp:198] take(): Semaphore taken:  name: SetValue (0x3ffde714), owner: <Unknown>
[D][BLECharacteristic.cpp:90] executeCreate(): Registering characteristic (esp_ble_gatts_add_char): uuid: aeb5483e-36e1-4688-b7f5-ea07361b26a8, service: UUID: 4fafc201-1fb5-459e-8fcc-c5c9c331914b, handle: 0x0028
[D][FreeRTOS.cpp:189] take(): Semaphore taking: name: CreateEvt (0x3ffddac8), owner: <N/A> for executeCreate
[D][FreeRTOS.cpp:198] take(): Semaphore taken:  name: CreateEvt (0x3ffddac8), owner: executeCreate
[D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... Unknown
[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
[D][FreeRTOS.cpp:189] take(): Semaphore taking: name: CreateEvt (0x3ffde654), owner: <N/A> for executeCreate
[D][FreeRTOS.cpp:198] take(): Semaphore taken:  name: CreateEvt (0x3ffde654), owner: executeCreate
[D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... Unknown
[D][FreeRTOS.cpp:189] take(): Semaphore taking: name: StartEvt (0x3ffdd5d8), owner: <N/A> for start
[D][FreeRTOS.cpp:198] take(): Semaphore taken:  name: StartEvt (0x3ffdd5d8), owner: start
[D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... Unknown
[I][BLEDevice.cpp:554] getAdvertising(): create advertising
[D][BLEDevice.cpp:556] getAdvertising(): get advertising
[D][BLEDevice.cpp:556] getAdvertising(): get advertising
[D][BLEAdvertising.cpp:189] start(): - advertising service: 4fafc201-1fb5-459e-8fcc-c5c9c331914b
Characteristic defined! Now you can read it in your phone!
[D][BLEDevice.cpp:556] getAdvertising(): get advertising
[D][BLEAdvertising.cpp:491] handleGAPEvent(): handleGAPEvent [event no: 0]
[D][BLEDevice.cpp:556] getAdvertising(): get advertising
[D][BLEAdvertising.cpp:491] handleGAPEvent(): handleGAPEvent [event no: 1]
[D][BLEDevice.cpp:556] getAdvertising(): get advertising
[D][BLEAdvertising.cpp:491] handleGAPEvent(): handleGAPEvent [event no: 6]
[D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... Unknown
[D][BLEDevice.cpp:556] getAdvertising(): get advertising
[D][BLEAdvertising.cpp:491] handleGAPEvent(): handleGAPEvent [event no: 20]
[D][BLEDevice.cpp:556] getAdvertising(): get advertising
[D][BLEAdvertising.cpp:491] handleGAPEvent(): handleGAPEvent [event no: 20]
[D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... Unknown
[D][BLECharacteristic.cpp:285] handleGATTServerEvent():  - Response to write event: New value: handle: 2a, uuid: aeb5483e-36e1-4688-b7f5-ea07361b26a8
[D][BLECharacteristic.cpp:288] handleGATTServerEvent():  - Data: length: 18, data: 71776572747975696f707177657274797569
[D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... Unknown
[D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... Unknown
[D][BLECharacteristic.cpp:285] handleGATTServerEvent():  - Response to write event: New value: handle: 2a, uuid: aeb5483e-36e1-4688-b7f5-ea07361b26a8
[D][BLECharacteristic.cpp:288] handleGATTServerEvent():  - Data: length: 3, data: 6f7031
[D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... Unknown
[D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... Unknown
Characteristic1 Written: qwertyuiopqwertyuiop1
Characteristic2 Written: I am Characteristic #2
[D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... Unknown
[D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 4] ... Unknown

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions