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

Jira 714 CurieBLE: Adding more than 6 characteristics to a service causes device to crash when attempting to advertise #446

Open
kgillespieatmosphere opened this issue Feb 18, 2017 · 12 comments

Comments

@kgillespieatmosphere
Copy link

It appears there is an issue when you add more than 6 characteristics to a single service in the CurieBLE driver with version 2.0.0 RC4.

The device never begins to advertise and appears to hang when calling BLE.advertise();

Removing the 7th characteristic from service will allow the device to continue to work.

Using Arduino101 board and version 2.0.0 RC4 of the Intel Curie Arduino SDK libs.

@kgillespieatmosphere
Copy link
Author

charTest.ino.zip

In this example I have commented out the line

PrimaryService.addCharacteristic(Function6Characteristic);

If you uncomment it then this project will no longer run, and the Arduino101 won't advertise.

@SidLeung
Copy link
Contributor

Please note that the current memory arrangement can only provided 8 KB of HEAP for the entire system. In addition, the malloc() does not maximize the usage of the HEAP. This issue is under investigation and proposed solutions are under testing. At the mean time, the number of Characteristic is limited.

@kgillespieatmosphere
Copy link
Author

Is there anyway to configure the heap to have more than 8KB allocated for a project?

@SidLeung
Copy link
Contributor

The allocation of ARC memory is controlled by the firmware running on the x86 core. To re-arrange the allocation needs an upgrade to the firmware.

@sandeepmistry
Copy link
Contributor

The device never begins to advertise and appears to hang when calling BLE.advertise();

@SidLeung is there are way to prevent the hanging?

@kitsunami
Copy link

There is no solution to prevent the hanging at this time, but can be considered for future investigation/improvements.

@kitsunami kitsunami added this to the Elnath milestone Feb 27, 2017
@agdl
Copy link
Member

agdl commented Mar 29, 2017

I have a sketch arranged like this:

#include <CurieBLE.h>

BLEPeripheral blePeripheral;

BLEService service1("1E600000-B5F3-F393-E0AA-E50E24DCCA9E");
BLEUnsignedIntCharacteristic char11("1E600001-B5F3-F393-E0AA-E50E24DCCA9E", BLERead | BLEWrite | BLENotify);
BLEUnsignedCharCharacteristic char12("1E600002-B5F3-F393-E0AA-E50E24DCCA9E", BLERead | BLEWrite);
BLECharacteristic char13("1E600003-B5F3-F393-E0AA-E50E24DCCA9E", BLERead | BLEWrite | BLENotify, 20);
BLECharacteristic char14("1E600004-B5F3-F393-E0AA-E50E24DCCA9E", BLERead | BLEWrite | BLENotify, 20);

BLEService service2("2E600000-B5A3-F393-E0AA-E50E24DCCA9E");
BLEUnsignedIntCharacteristic char21("2E600001-B5F3-F393-E0AA-E50E24DCCA9E", BLERead | BLEWrite | BLENotify);
BLEUnsignedIntCharacteristic char22("2E600002-B5F3-F393-E0AA-E50E24DCCA9E", BLERead | BLEWrite | BLENotify);
BLEUnsignedIntCharacteristic char23("2E600003-B5F3-F393-E0AA-E50E24DCCA9E", BLERead | BLEWrite | BLENotify);
BLEUnsignedIntCharacteristic char24("2E600004-B5F3-F393-E0AA-E50E24DCCA9E", BLERead | BLEWrite | BLENotify);

BLEService service3("3E600000-B5F3-F393-E0A9-E50E24DCCA9E");
BLEUnsignedCharCharacteristic char31("3E600001-B5F3-F393-E0AA-E50E24DCCA9E", BLERead | BLEWrite);
BLEUnsignedCharCharacteristic char32("3E600002-B5F3-F393-E0AA-E50E24DCCA9E", BLERead | BLEWrite);
BLEUnsignedIntCharacteristic char33("3E600003-B5F3-F393-E0AA-E50E24DCCA9E", BLERead | BLEWrite);

void setup() {
  Serial.begin(115200);
  while (!Serial);
  Serial.println("Serial started");
  // put your setup code here, to run once:
  blePeripheral.setLocalName("myTest");
  blePeripheral.setAdvertisedServiceUuid(service1.uuid());
  blePeripheral.addAttribute(service1);
  blePeripheral.addAttribute(char11);
  blePeripheral.addAttribute(char12);
  blePeripheral.addAttribute(char13);
  blePeripheral.addAttribute(char14);
  blePeripheral.addAttribute(service2);
  blePeripheral.addAttribute(char21);
  blePeripheral.addAttribute(char22);
  blePeripheral.addAttribute(char23);
  blePeripheral.addAttribute(char24);
  blePeripheral.addAttribute(service3);
  blePeripheral.addAttribute(char31);
  blePeripheral.addAttribute(char32);
  blePeripheral.addAttribute(char33);
  blePeripheral.begin();
}

void loop() {
  // put your main code here, to run repeatedly:
  BLECentral central = blePeripheral.central();

  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());

    // while the central is still connected to peripheral:
    while (central.connected()) {
    }

    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
  }
}

That was working on 1.0.7

Now I can see only the services 0x1800 and 0x1801 and not mine.

Tested on 2.0.1

@solidcloudio
Copy link

solidcloudio commented Apr 15, 2017

Seeing this same problem.. Sample script that fails:

#include <CurieBLE.h>

#define DEVICE_NAME "TestDevice"

#define SERVICE_UUID          ("f513d9a0-6cd5-4ed6-b98c-b67ce98f0cz4")

#define CHAR_UUID_1                 ("f513d9a1-6cd5-4ed6-b98c-b67ce98f0cz4")
#define CHAR_UUID_2                 ("f513d9a2-6cd5-4ed6-b98c-b67ce98f0cz4")
#define CHAR_UUID_3                 ("f513d9a3-6cd5-4ed6-b98c-b67ce98f0cz4")
#define CHAR_UUID_4                 ("f513d9a4-6cd5-4ed6-b98c-b67ce98f0cz4")
#define CHAR_UUID_5                 ("f513d9a5-6cd5-4ed6-b98c-b67ce98f0cz4")
#define CHAR_UUID_6                 ("f513d9a6-6cd5-4ed6-b98c-b67ce98f0cz4")
#define CHAR_UUID_7                 ("f513d9a7-6cd5-4ed6-b98c-b67ce98f0cz4")
#define CHAR_UUID_8                 ("f513d9a8-6cd5-4ed6-b98c-b67ce98f0cz4")
#define CHAR_UUID_9                 ("f513d9a9-6cd5-4ed6-b98c-b67ce98f0cz4")

bool connectedBle = false;       // Are we connected to a BLE device?

/* BLE Service */
BLEService pbService(SERVICE_UUID);

BLEUnsignedIntCharacteristic LvlChar1(CHAR_UUID_1, BLERead | BLENotify | BLEWrite);     
BLEUnsignedIntCharacteristic LvlChar2(CHAR_UUID_2, BLERead | BLENotify | BLEWrite);     
BLEUnsignedIntCharacteristic LvlChar3(CHAR_UUID_3, BLERead | BLENotify | BLEWrite);     
BLEUnsignedIntCharacteristic LvlChar4(CHAR_UUID_4, BLERead | BLENotify | BLEWrite);     
BLEUnsignedIntCharacteristic LvlChar5(CHAR_UUID_5, BLERead | BLENotify | BLEWrite);     
BLEUnsignedIntCharacteristic LvlChar6(CHAR_UUID_6, BLERead | BLENotify | BLEWrite);     
BLEUnsignedIntCharacteristic LvlChar7(CHAR_UUID_7, BLERead | BLENotify | BLEWrite);     

BLECharacteristic imuAccCharacteristic(CHAR_UUID_8, BLERead | BLENotify, 12);
BLECharacteristic imuGyroCharacteristic(CHAR_UUID_9, BLERead | BLENotify, 12);


void bleDeviceConnectHandler(BLEDevice central) {
    // central connected event handler
  Serial.print(F("Connected event, central: "));
  Serial.println(central.address());
  connectedBle = true;
}

void bleDeviceDisconnectHandler(BLEDevice central) {
    // central disconnected event handler
  Serial.print(F("Disconnected event, central: "));
  Serial.println(central.address());
  connectedBle = false;
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while (!Serial);    // wait for the serial port to open IF DEBUGGING!!
  
  Serial.println("Initializing BLE device...");

  /* Initialize BLE */
  BLE.begin();
  BLE.setLocalName("TestService");
  BLE.setAdvertisedService(pbService);

  // Add the characteristics
  pbService.addCharacteristic(LvlChar1);  
  pbService.addCharacteristic(LvlChar2);
  pbService.addCharacteristic(LvlChar3);
  pbService.addCharacteristic(LvlChar4);
  pbService.addCharacteristic(LvlChar5);
  pbService.addCharacteristic(LvlChar6);
  pbService.addCharacteristic(LvlChar7);
  
  // Add the characteristics
  int ret1 = pbService.addCharacteristic(imuAccCharacteristic);
  int ret2 = pbService.addCharacteristic(imuGyroCharacteristic);

  Serial.println(ret1);
  Serial.println(ret2);

  BLE.setEventHandler(BLEConnected, bleDeviceConnectHandler);
  BLE.setEventHandler(BLEDisconnected, bleDeviceDisconnectHandler);

  Serial.println("Events wired...");

  BLE.addService(pbService);              // Add the Imu service
  Serial.println("Service Added...");

  BLE.setTxPower(4);
  Serial.println("Power Set...");

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

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

Removing one of the attributes, it works, but with the script as above advertise hangs... Serial log shows:
Initializing BLE device...
0
0
Events wired...
Service Added...
Power Set...

//BLE advertise hangs, never gets to log message...

int bleStatus = BLE.advertise();
Serial.println(bleStatus);
Serial.println("Bluetooth device active, waiting for connections...");

This was working in 1.0.7..

@solidcloudio
Copy link

I wouldn't say this is an "Enhancement" but rather a bug..

@novashah novashah changed the title CurieBLE: Adding more than 6 characteristics to a service causes device to crash when attempting to advertise Jira 714 CurieBLE: Adding more than 6 characteristics to a service causes device to crash when attempting to advertise Apr 25, 2017
@russmcinnis
Copy link
Contributor

We are going to investigate the limits of characteristics when we have V4.2 stabilized.

@solidcloudio
Copy link

solidcloudio commented May 2, 2017 via email

@b100bf
Copy link

b100bf commented Jul 3, 2017

I cannot advertise more than 7 characteristics even in separate services. I think there is a memory limitation.
If i'll use 16bit UUIDs instead of 128bit, will it allow more characteristics, or does it only a short representation?

@kitsunami kitsunami removed this from the Elnath milestone Aug 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants