I'm using Arduino IDE 1.8.2 with the latest corelibs 2.0.2 and tools 1.8.0+1.29
Calling BLE.advertise() works with the code below:
#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);
// (line 68) 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:
}
The code above works, but if I uncomment line 68:
//pbService.addCharacteristic(LvlChar7);
It fails...
Log output with code shown here: (works ok)
Initializing BLE device...
0
0
Events wired...
Service Added...
Power Set...
0
Bluetooth device active, waiting for connections...
If I uncomment line 68 (fails)
Initializing BLE device...
0
0
Events wired...
Service Added...
Power Set...
I got to this by a process of elimination, I un-commented all the characteristics, and added them back one by one until it fails.. I don't see anything unique or different about LvlChar7.
You can see it fails when I call advertise(); but only if LvlChar7 is present.
What am I missing? Is there a limit to the number of characteristics you can add?
It doesnt seem specific to LvlChar7, only having 9 characteristics causes the problem... 8 seems to work fine..