ArduinoCore-arc32 icon indicating copy to clipboard operation
ArduinoCore-arc32 copied to clipboard

Jira 913 BLESubscribed, BLEUnsubscribed Event Handlers are not called

Open vshymanskyy opened this issue 7 years ago • 15 comments

For example, in following scenario (Nordic UART Service implementation):

#include <CurieBLE.h>

BLEService        NUS    ("713D0000-503E-4C75-BA94-3148F18D941E");
BLECharacteristic rxChar ("713D0003-503E-4C75-BA94-3148F18D941E", BLEWrite | BLEWriteWithoutResponse, BLE_MAX_ATTR_DATA_LEN);
BLECharacteristic txChar ("713D0002-503E-4C75-BA94-3148F18D941E", BLERead  | BLENotify,               BLE_MAX_ATTR_DATA_LEN);

void setup() {
  Serial.begin(9600);

  // begin initialization
  BLE.begin();

  // set the local name peripheral advertises
  BLE.setLocalName("NUS test");

  BLE.setAdvertisedService(NUS);

  // add the characteristic to the service
  NUS.addCharacteristic(rxChar);
  NUS.addCharacteristic(txChar);

  // add service
  BLE.addService(NUS);

  // assign event handlers for connected, disconnected to peripheral
  BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
  BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);

  // assign event handlers for characteristics
  rxChar.setEventHandler(BLEWritten,      rxCharWritten);
  txChar.setEventHandler(BLESubscribed,   txCharSubscribed);
  txChar.setEventHandler(BLEUnsubscribed, txCharUnsubscribed);

  // set an initial value for characteristics
  unsigned char empty[0] = {};
  rxChar.setValue(empty, 0);
  txChar.setValue(empty, 0);

  // start advertising
  BLE.advertise();

  Serial.println("Bluetooth device active, waiting for connections...");
}

void loop() {
  // poll for BLE events
  BLE.poll();
}

void blePeripheralConnectHandler(BLEDevice central) {
  // central connected event handler
  Serial.print("Connected event, central: ");
  Serial.println(central.address());
}

void blePeripheralDisconnectHandler(BLEDevice central) {
  // central disconnected event handler
  Serial.print("Disconnected event, central: ");
  Serial.println(central.address());
}

void txCharSubscribed(BLEDevice central, BLECharacteristic ch) {
    Serial.println("Subscribed");
}

void txCharUnsubscribed(BLEDevice central, BLECharacteristic ch) {
    Serial.println("Unsubscribed");
}

void rxCharWritten(BLEDevice central, BLECharacteristic ch) {
    const uint8_t* data = ch.value();
    uint32_t len = ch.valueLength();

    Serial.print("Got data:");
    Serial.write(data, len);

    txChar.setValue((uint8_t*)data, len);
}

vshymanskyy avatar Apr 12 '17 08:04 vshymanskyy

@vshymanskyy thanks for the excellent issue report! I've confirmed the issue on my board using the sketch you provided.

@SidLeung can something at Intel look into this please?

sandeepmistry avatar Apr 12 '17 14:04 sandeepmistry

I reproduced the results using another 101 as the central and the sketch in this issue is not seeing the subscribe/unsubscribe events.

russmcinnis avatar Apr 12 '17 19:04 russmcinnis

tracked by jira 913

russmcinnis avatar Apr 12 '17 19:04 russmcinnis

The event handlers are being called. Jira 913 has been updated and resolved. This is not released yet.

russmcinnis avatar May 02 '17 22:05 russmcinnis

Will re-test when merged for Elnath.

russmcinnis avatar May 10 '17 13:05 russmcinnis

testing other BLE issues, this will be re-tested when we get something final for Elnath.

russmcinnis avatar May 17 '17 15:05 russmcinnis

Any news on this?

d1runberg avatar May 22 '17 20:05 d1runberg

Issue duplicated, failure determined, correction implemented, and it is in the pipeline for official release.

SidLeung avatar May 22 '17 21:05 SidLeung

Will retest for the official release.

russmcinnis avatar May 30 '17 14:05 russmcinnis

will test when bootes/elnath released.

russmcinnis avatar Jun 06 '17 18:06 russmcinnis

Any updates?

vshymanskyy avatar Oct 24 '17 20:10 vshymanskyy

Maybe Dino can provide info @bigdinotech

russmcinnis avatar Oct 24 '17 20:10 russmcinnis

@bigdinotech hey are there any news?

vshymanskyy avatar Oct 30 '17 21:10 vshymanskyy

ping ping ping ))

vshymanskyy avatar Nov 10 '17 18:11 vshymanskyy

Guys, what's the plan?

vshymanskyy avatar Dec 21 '17 16:12 vshymanskyy