Arduino Hack… Required or Not? (Notifications)

Please run the following code on a Nano 33 BLE (Links to the hack are included at the top)

 #include <ArduinoBLE.h>  
 
  // Custom ArduinoBLE library required, download it from https://github.com/ysoldak/ArduinoBLE/tree/cccd_hack
  // Diff: https://github.com/ysoldak/ArduinoBLE/compare/master...ysoldak:cccd_hack          
  
  BLEService para("FFF0");
           
  // BLECharacteristic fff6("FFF6", BLEWriteWithoutResponse | BLENotify | BLEAutoSubscribe, 32);
  BLECharacteristic fff6("FFF6", BLEWriteWithoutResponse | BLENotify, 32);
  
  void setup() {  
    pinMode(LED_BUILTIN, OUTPUT);  
    Serial.begin(115200);
  
    BLE.begin();
    Serial.println("Notification Test...");              
    BLE.setLocalName("Notification Test!!!");
  
    BLE.setAdvertisedService(para);           
    para.addCharacteristic(fff6);  
    BLE.addService(para);  
    BLE.advertise();
    
    Serial.println(BLE.address());  
  }
  
  void loop() {  
    BLEDevice central = BLE.central();
  
    if (central) {
      Serial.print("Connected to central: ");
      Serial.println(central.address());
      Serial.println(central.localName());
  
      if (central.connected()) {
        BLE.stopAdvertise();
        digitalWrite(LED_BUILTIN, HIGH);
      }
  
      while (central.connected()) {
        sendFakeTrainer();
        delay(20);
      }
  
      Serial.println("Disconnected");
      BLE.advertise();
    }
  
    digitalWrite(LED_BUILTIN, LOW);
    Serial.print("Waiting for central, our address: ");
    Serial.println(BLE.address());
    delay(100);
  }  
  
  void sendFakeTrainer() {
    uint8_t data[17] = { 0x7E, 0x80, 0xDD, 0x5D, 0xC5, 0xDC, 0x7D, 0x5D, 0xC5, 0xDC, 0x5D, 0xC5, 0xDC, 0x5D, 0xC5, 0xA1, 0x7E };
    fff6.writeValue(data, 17);
  }

2nd and 3rd lines “BLECharacteristic” results in the following…

1) Referring to screenshot: “Notifications Are Disabled” (When not using “BLEAutoSubscribe”)

2) Referring to screenshot: “Notifications Automatically Enabled” (Using “BLEAutoSubscribe”)

When connecting via the above test program to my Android tablet without using BLEAutoSubscribe, notifications are disabled until tapping on the three little down arrows. My RC transmitter doesn’t receive the notifications values either.

However, when connecting via the above test program to my Android tablet with BLEAutoSubscribe, notifications are automatically enabled… and… my RC transmitter receives the notifications :blush:

Therefore please can someone take a look at this and then hopefully explain if there is a standard way to auto enable notifications instead of using the ArduinoBLE.h hack?

Solution: Feature Request... Option To Set CCCD Value

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.