Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a second characteristic stops the service to be reachable #309

Open
MicheleMas opened this issue Jul 16, 2023 · 1 comment
Open
Labels
status: waiting for information More information must be provided before work can proceed type: imperfection Perceived defect in any part of project

Comments

@MicheleMas
Copy link

Hello,

I am trying to create a service with two characteristics using an Arduino uno r4 wifi. With one service and one characteristic everything works fine, if I define a second characteristic the service is not available anymore (checked with nRF Connect).

Here a code to reproduce the issue:

#include <ArduinoBLE.h>

BLEService ledService = BLEService("19B10010-E8F2-537E-4F6C-D104768A1214");

// create switch characteristic and allow remote device to read and write
BLEByteCharacteristic characteristicTest1("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
BLEByteCharacteristic characteristicTest2("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);

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

  if (!BLE.begin()) {
    Serial.println("starting Bluetooth® Low Energy module failed!");

    while (1);
  }

  BLE.setLocalName("TestBLE");
  BLE.setAdvertisedService(ledService);

  ledService.addCharacteristic(characteristicTest1);
  // ledService.addCharacteristic(characteristicTest2);

  // add service
  BLE.addService(ledService);

  BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
  BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);

  characteristicTest1.setEventHandler(BLEWritten, testCharacteristicWritten);
  characteristicTest1.setValue(0);
  // characteristicTest2.setEventHandler(BLEWritten, testCharacteristicWritten);
  // characteristicTest2.setValue(0);

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

void loop() {
  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 testCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) {
  Serial.print("Characteristic event, written: ");
  Serial.println(characteristicTest1.value());
}

As you can see I commented everything related to the second characteristic, only the definition of the variable is not commented. If I comment the line BLEByteCharacteristic characteristicTest2("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); everything starts working again.

Here what I see when the second characteristic is commented:
Screenshot 2023-07-16 at 17 11 52

Just uncommenting the second characteristic this happens:
Screenshot 2023-07-16 at 17 12 29
As you can see the service and the first characteristic is not visible anymore.

I am using the ArduinoBLE version 1.3.5, with this PR to have the support for the Arduino uno r4 wifi.

Any idea of what the issue could be? Sorry in advance if this is a trivial issue given by my code, I am not an expert with C++ and BLE.

@facchinm
Copy link
Contributor

Should be fixed by arduino/ArduinoCore-renesas@96963d8 . @MicheleMas can you retest with latest library + core?

@per1234 per1234 added the status: waiting for information More information must be provided before work can proceed label Sep 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for information More information must be provided before work can proceed type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

3 participants