Skip to content

Commit e7238f0

Browse files
sgbihucalvinatintel
authored andcommitted
Jira Tickets and Bug fix
1. Jira 541 Peripheral Start fails on X Number of Attributes -Change the interface and add return value 2. Fix BLE Peripheral is not advertising -Add a delay after register the profile. 3. Modify some comments based on code review 4. Jira 544 BLE peripheral disconnect and end functions -The state not aligned and make disconnect failed. Update when connect and disconnect event received 5. Delete the duplicated code that base class has implemented 6. Fix Jira 665 BLECentral Preview -- compile issue when instantiating BLE descriptor -Fix the build error. Note: i . The current code only support one descriptor on characteristic. ii . The central discover logic need more twist. iii. Now is so long and can't process CCCD and another characteristic. iv . The library will support one other descriptor except CCCD. 7. Improve the discover logic and support another descriptor i. Improve the discover logic ii. Support another the descriptor and CCCD at same time. 8. Modify the comments and delete the unused API 9. Fix Jira 670 A compile error occurs with two BLE methods with the same name i. Add method uuid_cstr in BLEAttribute class. ii. Remove the duplicate file. 10. Fix Jira 672 BLE documentation in code needs to specify units i. Change the scan and connection interval's unit to ms. ii. Unify the advertising interval unit as millisecond iii. Delete some unused code. 11. Fix Jria 671 Support update connection interval in central/peripheral i. Central can update the connection interval. ii. Unify the interval unit to ms at user API. 12. Adjust the example comments and functions i. Fix Jira 675 - BLE callbacks should use passed arguments instead of global variables ii. Adjust the code struture to align with Arduino's requirement 13. Fix Jira 680 LED and LED Central sketches need some work -Add a delay to make sure profile register process success. -The UART send too fast may makes the profile registration failed. 14. Fix Jira 673 BLE Api should pass arguments that are typedef 15. Fix Jira 671 Support update connection interval in central/peripheral i. Add peripheral update the connection interval feature. ii. Update the library. 16. Fix Jira 687 Edit the keyword.txt of CurieBLE to reflect Library changes 17. Make example function ready. But need to resolve Jira 675 18. Fix Jira 676 Review Edit Update BLE User Manual with China Flex 19. Fix Jira 685 BLE Peripheral sketches shall state which associated Central sketch to use 20. Fix Jira 588 - BLE Corrupted Long Write i. Modify the BLECharacteristic to implement the Long write feature. 21. Fix Jira 683 Typecasting and Pointers should be avoided in sketch i. Add write in Characteristic template ii. Add method in BLE Role class to avoid typecaste iii. Modify the advertise address parameter and related example sketches 22. Fix Jira 704 Type Characteristic should be documented 23. Fix Jira 684 Documentation about the central/peripheral
1 parent ae78b16 commit e7238f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2019
-1047
lines changed

libraries/CurieBLE/examples/BatteryMonitor/BatteryMonitor.ino

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
#include <CurieBLE.h>
77

88
/*
9-
This sketch example partially implements the standard Bluetooth Low-Energy Battery service.
9+
This sketch can work with UpdateConnectionInterval.
10+
You can also use an android or IOS app that supports notifications
11+
This sketch example partially implements the standard Bluetooth Low-Energy Battery service
12+
and connection interval paramater update.
1013
For more information: https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx
1114
*/
1215

@@ -15,9 +18,9 @@ BLEPeripheral blePeripheral; // BLE Peripheral Device (the board you're pr
1518
BLEService batteryService("180F"); // BLE Battery Service
1619

1720
// BLE Battery Level Characteristic"
18-
BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID
21+
BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID defined in the URL above
1922
BLERead | BLENotify); // remote clients will be able to
20-
// get notifications if this characteristic changes
23+
// get notifications if this characteristic changes
2124

2225
int oldBatteryLevel = 0; // last battery level reading from analog input
2326
long previousMillis = 0; // last time the battery level was checked, in ms

libraries/CurieBLE/examples/ButtonLED/ButtonLED.ino

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,28 @@
33
* See the bottom of this file for the license terms.
44
*/
55

6+
/* This examples needs a button connected similarly as described here
7+
https://www.arduino.cc/en/Tutorial/Button
8+
The only difference is that instead of connecting to pin 2 connect to pin 4
9+
After the sketch starts connect to a BLE app on a phone and set notification to the Characteristic and you should see it update
10+
whenever the button is pressed. This sketch is not written to pair with any of the central examples.
11+
*/
12+
613
#include <CurieBLE.h>
714

815
const int ledPin = 13; // set ledPin to on-board LED
916
const int buttonPin = 4; // set buttonPin to digital pin 4
1017

1118
BLEPeripheral blePeripheral; // create peripheral instance
12-
BLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214"); // create service
19+
BLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214"); // create service with a 128-bit UUID (32 characters exclusive of dashes).
20+
// Long UUID denote custom user created UUID
1321

1422

1523
// create switch characteristic and allow remote device to read and write
1624
BLECharCharacteristic ledCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
1725
// create button characteristic and allow remote device to get notifications
1826
BLECharCharacteristic buttonCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); // allows remote device to get notifications
27+
// Note use of Typed Characteristics. These previous 2 characeristics are of the type char
1928

2029
void setup() {
2130
Serial.begin(9600);
@@ -32,6 +41,7 @@ void setup() {
3241
blePeripheral.addAttribute(ledCharacteristic);
3342
blePeripheral.addAttribute(buttonCharacteristic);
3443

44+
// set initial values for led and button characteristic
3545
ledCharacteristic.setValue(0);
3646
buttonCharacteristic.setValue(0);
3747

@@ -59,10 +69,13 @@ void loop() {
5969

6070
if (ledCharacteristic.written() || buttonChanged) {
6171
// update LED, either central has written to characteristic or button state has changed
72+
// if you are using a phone or a BLE central device that is aware of this characteristic, writing a value of 0x40 for example
73+
// Will be interpreted as written
6274
if (ledCharacteristic.value()) {
6375
Serial.println("LED on");
6476
digitalWrite(ledPin, HIGH);
6577
} else {
78+
// If central writes a 0 value then it is interpreted as no value and turns off the LED
6679
Serial.println("LED off");
6780
digitalWrite(ledPin, LOW);
6881
}

libraries/CurieBLE/examples/CallbackLED/CallbackLED.ino

+19-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,24 @@
22
* Copyright (c) 2016 Intel Corporation. All rights reserved.
33
* See the bottom of this file for the license terms.
44
*/
5+
6+
// This example can work with LEDCentral
7+
// You should see the LED blink on and off
8+
// This example demonstrates the use of Callback or event Handlers responding to events
9+
// BLECoonected, BLEDisconnected and BLEWritten are events.
10+
// To test interactively use a Phone app like nrf Controller (Android) or Light Blue (iOS)
11+
// Connect to BLE device named LEDCB and explore characteristic with UUID 19B10001-E8F2-537E-4F6C-D104768A1214
12+
// Writing a byte value such as 0x40 should turn on the LED
13+
// Writng a byte value of 0x00 should turn off the LED
514

615
#include <CurieBLE.h>
716

817
const int ledPin = 13; // set ledPin to use on-board LED
918
BLEPeripheral blePeripheral; // create peripheral instance
19+
BLECentralHelper *bleCentral1 = NULL; // peer central device
1020

11-
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service
21+
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service with a 128-bit UUID (32 characters exclusive of dashes).
22+
// Long UUID denote custom user created UUID
1223

1324
// create switch characteristic and allow remote device to read and write
1425
BLECharCharacteristic switchChar("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
@@ -45,10 +56,14 @@ void loop() {
4556
blePeripheral.poll();
4657
}
4758

59+
// The function parameter (BLEHelper& central) is for peripheral devices
60+
// This enable us to have access to the central's data like its bluetooth address
61+
4862
void blePeripheralConnectHandler(BLEHelper& central) {
4963
// central connected event handler
64+
bleCentral1 = blePeripheral.getPeerCentralBLE(central);
5065
Serial.print("Connected event, central: ");
51-
Serial.println(central.address());
66+
Serial.println(bleCentral1->address());
5267
}
5368

5469
void blePeripheralDisconnectHandler(BLEHelper& central) {
@@ -57,6 +72,8 @@ void blePeripheralDisconnectHandler(BLEHelper& central) {
5772
Serial.println(central.address());
5873
}
5974

75+
// In addtion to the BLECentral& central parameter, we also have to have to BLECharacteristic& characteristic parameter
76+
6077
void switchCharacteristicWritten(BLEHelper& central, BLECharacteristic& characteristic) {
6178
// central wrote new value to characteristic, update LED
6279
Serial.print("Characteristic event, written: ");
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
/*
2-
Copyright (c) 2016 Intel Corporation. All rights reserved.
3-
4-
This library is free software; you can redistribute it and/or
5-
modify it under the terms of the GNU Lesser General Public
6-
License as published by the Free Software Foundation; either
7-
version 2.1 of the License, or (at your option) any later version.
8-
9-
This library is distributed in the hope that it will be useful,
10-
but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12-
Lesser General Public License for more details.
13-
14-
You should have received a copy of the GNU Lesser General Public
15-
License along with this library; if not, write to the Free Software
16-
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17-
*/
2+
* Copyright (c) 2016 Intel Corporation. All rights reserved.
3+
* See the bottom of this file for the license terms.
4+
*/
185

196
#include <CurieBLE.h>
207

218
/*
22-
This sketch example partially implements the standard Bluetooth Low-Energy Battery service.
23-
For more information: https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx
9+
This sketch example works with IMUBleNotification.ino
10+
IMUBleNotification.ino will send notification to this sketch.
11+
This sketch will receive the notifications and out put the received data in the serial monitor
12+
It also illustrates using a non typed characteristic
13+
Set the baud rate to 115200 on the serial monitor to accomodate the speed of constant data updates from IMU subsystem
14+
2415
*/
2516

2617
#define MAX_IMU_RECORD 1
2718

28-
struct bt_le_conn_param conn_param = {0x18, 0x28, 0, 400};
19+
ble_conn_param_t conn_param = {30.0, // minimum interval in ms 7.5 - 4000
20+
50.0, // maximum interval in ms 7.5 -
21+
0, // latency
22+
4000 // timeout in ms 100 - 32000ms
23+
};
24+
// define a structure that will serve as buffer for holding IMU data
25+
2926
typedef struct {
3027
int index;
3128
unsigned int slot[3];
@@ -38,19 +35,64 @@ BLEService bleImuService("F7580001-153E-D4F6-F26D-43D8D98EEB13");
3835
BLECharacteristic bleImuChar("F7580003-153E-D4F6-F26D-43D8D98EEB13", // standard 128-bit characteristic UUID
3936
BLERead | BLENotify, sizeof(imuBuf)); // remote clients will be able to
4037
// get notifications if this characteristic changes
38+
// We have a third parameter which is the size of imyBuffer. This is because it is a non-typed characteristic
39+
// If we are only writing to this characteristic we can set this buffer to 512 bytes
40+
// But because of the limitation of the Nordic FW, please do not set this to more than 128 if you intend to read it.
41+
// MAX_IMU_RECORD value is 1 so we are safe
42+
// function prototype for function that determines if the advertising data is found
43+
bool adv_found(uint8_t type,
44+
const uint8_t *dataPtr,
45+
uint8_t data_len,
46+
const bt_addr_le_t *addrPtr);
47+
48+
void setup()
49+
{
50+
// This is set to higher baud rate because accelerometer data changes very quickly
51+
Serial.begin(115200); // initialize serial communication
52+
pinMode(13, OUTPUT); // initialize the LED on pin 13 to indicate when a central is connected
53+
// set the event handeler function for the bleImuChar characteristic
54+
bleImuChar.setEventHandler(BLEWritten, bleImuCharacteristicWritten);
55+
56+
bleCentral.addAttribute(bleImuService); // Add the BLE IMU service
57+
bleCentral.addAttribute(bleImuChar); // Add the BLE IMU characteristic
58+
59+
// Setup callback whenever a Peripheral advertising data is found)
60+
bleCentral.setAdvertiseHandler(adv_found);
61+
bleCentral.setEventHandler(BLEConnected, ble_connected);
62+
63+
/* Now activate the BLE device. It will start continuously transmitting BLE
64+
advertising packets and will be visible to remote BLE central devices
65+
until it receives a new connection */
66+
bleCentral.begin();
67+
}
68+
69+
70+
void loop()
71+
{
72+
// we put a 2 second delay
73+
// Even though this looks empty, since we setup 2 callbacks by setting the advertising handler adv_found
74+
// and event handler for BLEConnected, we basically are lsitening for advertising data and connected events.
75+
76+
delay(2000);
77+
}
4178

4279
void ble_connected(BLEHelper &role)
4380
{
44-
BLEPeripheralHelper&peripheral = *(BLEPeripheralHelper*)(&role);
81+
// since we are a central device we create a BLEPeripheralHelper peripheral
82+
BLEPeripheralHelper *peripheral = bleCentral.getPeerPeripheralBLE(role);
4583
Serial.println("Connected");
4684

4785
// Start discovery the profiles in peripheral device
48-
peripheral.discover();
86+
peripheral->discover();
4987
}
5088

51-
void bleImuCharacteristicWritten(BLEHelper& central, BLECharacteristic& characteristic)
89+
void bleImuCharacteristicWritten(BLEHelper& peripheral, BLECharacteristic& characteristic)
5290
{
5391
// Peripheral wrote new value to characteristic by Notification/Indication
92+
// We have to use pointers because we are NOT using a type characteristic
93+
// In other examples our charcteristics are typed so we not have to use pointers and can access the value directly
94+
// The parent non typde characteristic class, the value method gives a pointer to the characteristic value
95+
5496
const unsigned char *cvalue = characteristic.value();
5597
const imuFrameType *value = (const imuFrameType *)cvalue;
5698
Serial.print("\r\nCharacteristic event, written: ");
@@ -64,32 +106,32 @@ void bleImuCharacteristicWritten(BLEHelper& central, BLECharacteristic& characte
64106
}
65107

66108
bool adv_found(uint8_t type,
67-
const uint8_t *data,
109+
const uint8_t *dataPtr,
68110
uint8_t data_len,
69-
void *user_data)
111+
const bt_addr_le_t *addrPtr)
70112
{
71-
bt_addr_le_t *addr = (bt_addr_le_t *)user_data;
72113
int i;
73114

74115
Serial.print("[AD]:");
75116
Serial.print(type);
76117
Serial.print(" data_len ");
77118
Serial.println(data_len);
78-
119+
// Please see https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
120+
// To decode the data the central device cares.
121+
// This example use UUID as identity.
79122
switch (type)
80123
{
81124
case BT_DATA_UUID128_SOME:
82125
case BT_DATA_UUID128_ALL:
83126
{
84-
if (data_len % MAX_UUID_SIZE != 0)
127+
if (data_len % UUID_SIZE_128 != 0)
85128
{
86129
Serial.println("AD malformed");
87130
return true;
88131
}
89-
struct bt_uuid * serviceuuid = bleImuService.uuid();
90-
for (i = 0; i < data_len; i += MAX_UUID_SIZE)
132+
for (i = 0; i < data_len; i += UUID_SIZE_128)
91133
{
92-
if (memcmp (((struct bt_uuid_128*)serviceuuid)->val, &data[i], MAX_UUID_SIZE) != 0)
134+
if (bleImuService.uuidCompare(dataPtr + i, UUID_SIZE_128) == false)
93135
{
94136
continue;
95137
}
@@ -102,7 +144,7 @@ bool adv_found(uint8_t type,
102144
}
103145
Serial.println("Connecting");
104146
// Connect to peripheral
105-
bleCentral.connect(addr, &conn_param);
147+
bleCentral.connect(addrPtr, &conn_param);
106148
return false;
107149
}
108150
}
@@ -111,33 +153,20 @@ bool adv_found(uint8_t type,
111153
return true;
112154
}
113155

114-
void setup() {
115-
Serial.begin(115200); // initialize serial communication
116-
pinMode(13, OUTPUT); // initialize the LED on pin 13 to indicate when a central is connected
117-
118-
bleImuChar.setEventHandler(BLEWritten, bleImuCharacteristicWritten);
119-
120-
/* Set a local name for the BLE device
121-
This name will appear in advertising packets
122-
and can be used by remote devices to identify this BLE device
123-
The name can be changed but maybe be truncated based on space
124-
left in advertisement packet */
125-
bleCentral.addAttribute(bleImuService); // Add the BLE IMU service
126-
bleCentral.addAttribute(bleImuChar); // Add the BLE IMU characteristic
127-
128-
/* Setup callback */
129-
bleCentral.setAdvertiseHandler(adv_found);
130-
bleCentral.setEventHandler(BLEConnected, ble_connected);
131-
132-
/* Now activate the BLE device. It will start continuously transmitting BLE
133-
advertising packets and will be visible to remote BLE central devices
134-
until it receives a new connection */
135-
bleCentral.begin();
136-
}
156+
/*
157+
Copyright (c) 2016 Intel Corporation. All rights reserved.
137158
159+
This library is free software; you can redistribute it and/or
160+
modify it under the terms of the GNU Lesser General Public
161+
License as published by the Free Software Foundation; either
162+
version 2.1 of the License, or (at your option) any later version.
138163
139-
void loop()
140-
{
141-
delay(2000);
142-
}
164+
This library is distributed in the hope that it will be useful,
165+
but WITHOUT ANY WARRANTY; without even the implied warranty of
166+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
167+
Lesser General Public License for more details.
143168
169+
You should have received a copy of the GNU Lesser General Public
170+
License along with this library; if not, write to the Free Software
171+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
172+
*/

0 commit comments

Comments
 (0)