Skip to content

Commit b0a366a

Browse files
committed
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.
1 parent 2ccef69 commit b0a366a

Some content is hidden

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

41 files changed

+1564
-912
lines changed

libraries/CurieBLE/examples/BatteryMonitor/BatteryMonitor.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ BLEPeripheral blePeripheral; // BLE Peripheral Device (the board you're pr
1515
BLEService batteryService("180F"); // BLE Battery Service
1616

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

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

libraries/CurieBLE/examples/ButtonLED/ButtonLED.ino

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ const int ledPin = 13; // set ledPin to on-board LED
99
const int buttonPin = 4; // set buttonPin to digital pin 4
1010

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

1415

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

2022
void setup() {
2123
Serial.begin(9600);
@@ -32,6 +34,7 @@ void setup() {
3234
blePeripheral.addAttribute(ledCharacteristic);
3335
blePeripheral.addAttribute(buttonCharacteristic);
3436

37+
// set initial values for led and button characteristic
3538
ledCharacteristic.setValue(0);
3639
buttonCharacteristic.setValue(0);
3740

@@ -59,10 +62,13 @@ void loop() {
5962

6063
if (ledCharacteristic.written() || buttonChanged) {
6164
// update LED, either central has written to characteristic or button state has changed
65+
// if you are using a phone or a BLE central device that is aware of this characteristic, writing a value of 0x40 for example
66+
// Will be interpreted as written
6267
if (ledCharacteristic.value()) {
6368
Serial.println("LED on");
6469
digitalWrite(ledPin, HIGH);
6570
} else {
71+
// If central writes a 0 value then it is interpreted as no value and turns off the LED
6672
Serial.println("LED off");
6773
digitalWrite(ledPin, LOW);
6874
}

libraries/CurieBLE/examples/CallbackLED/CallbackLED.ino

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
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+
//
8+
// This example demonstartes the use of Callback or event Handlers responding to events
9+
// BLECoonected, BLEDisconnected and BLEWritten are events.
10+
// To Test use a Phone app lie 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 suck 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
1019

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

1323
// create switch characteristic and allow remote device to read and write
1424
BLECharCharacteristic switchChar("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
@@ -45,6 +55,9 @@ void loop() {
4555
blePeripheral.poll();
4656
}
4757

58+
// The function parameter (BLEHelper& central) is for peripheral devices
59+
// This enable us to have access to the central's data like its bluetooth address
60+
4861
void blePeripheralConnectHandler(BLEHelper& central) {
4962
// central connected event handler
5063
Serial.print("Connected event, central: ");
@@ -57,6 +70,8 @@ void blePeripheralDisconnectHandler(BLEHelper& central) {
5770
Serial.println(central.address());
5871
}
5972

73+
// In addtion to the BLECentral& central parameter, we also have to have to BLECharacteristic& characteristic parameter
74+
6075
void switchCharacteristicWritten(BLEHelper& central, BLECharacteristic& characteristic) {
6176
// central wrote new value to characteristic, update LED
6277
Serial.print("Characteristic event, written: ");
Lines changed: 70 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
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 serail monitor
2412
*/
2513

2614
#define MAX_IMU_RECORD 1
2715

28-
struct bt_le_conn_param conn_param = {0x18, 0x28, 0, 400};
16+
ble_conn_param_t conn_param = {30.0, // minimum interval in ms 7.5 - 4000
17+
50.0, // maximum interval in ms 7.5 -
18+
0, // latency
19+
4000 // timeout in ms 100 - 32000ms
20+
};
21+
// define a structure that will serve as buffer for holding IMU data
22+
2923
typedef struct {
3024
int index;
3125
unsigned int slot[3];
@@ -38,17 +32,54 @@ BLEService bleImuService("F7580001-153E-D4F6-F26D-43D8D98EEB13");
3832
BLECharacteristic bleImuChar("F7580003-153E-D4F6-F26D-43D8D98EEB13", // standard 128-bit characteristic UUID
3933
BLERead | BLENotify, sizeof(imuBuf)); // remote clients will be able to
4034
// get notifications if this characteristic changes
35+
// function prototype for function that determines if the advertising data is found
36+
bool adv_found(uint8_t type,
37+
const uint8_t *data,
38+
uint8_t data_len,
39+
void *user_data);
40+
41+
void setup()
42+
{
43+
// This is set to higher baud rate because accelrometer data changes very quickly
44+
Serial.begin(115200); // initialize serial communication
45+
pinMode(13, OUTPUT); // initialize the LED on pin 13 to indicate when a central is connected
46+
// set the event handeler function for the bleImuChar characteristic
47+
bleImuChar.setEventHandler(BLEWritten, bleImuCharacteristicWritten);
48+
49+
bleCentral.addAttribute(bleImuService); // Add the BLE IMU service
50+
bleCentral.addAttribute(bleImuChar); // Add the BLE IMU characteristic
51+
52+
// Setup callback whenever a Peripheral advertising data is found)
53+
bleCentral.setAdvertiseHandler(adv_found);
54+
bleCentral.setEventHandler(BLEConnected, ble_connected);
55+
56+
/* Now activate the BLE device. It will start continuously transmitting BLE
57+
advertising packets and will be visible to remote BLE central devices
58+
until it receives a new connection */
59+
bleCentral.begin();
60+
}
61+
62+
63+
void loop()
64+
{
65+
// we put a 2 second delay
66+
// Even though this looks empty, since we setup 2 callbacks by setting the advertising handler adv_found
67+
// and event handler for BLEConnected, we basically are lsitening for advertising data and connected event.
68+
69+
delay(2000);
70+
}
4171

4272
void ble_connected(BLEHelper &role)
4373
{
74+
// since we are a central device we create a BLEPeripheralHelper peripheral
4475
BLEPeripheralHelper&peripheral = *(BLEPeripheralHelper*)(&role);
4576
Serial.println("Connected");
4677

4778
// Start discovery the profiles in peripheral device
4879
peripheral.discover();
4980
}
5081

51-
void bleImuCharacteristicWritten(BLEHelper& central, BLECharacteristic& characteristic)
82+
void bleImuCharacteristicWritten(BLEHelper& peripheral, BLECharacteristic& characteristic)
5283
{
5384
// Peripheral wrote new value to characteristic by Notification/Indication
5485
const unsigned char *cvalue = characteristic.value();
@@ -75,7 +106,9 @@ bool adv_found(uint8_t type,
75106
Serial.print(type);
76107
Serial.print(" data_len ");
77108
Serial.println(data_len);
78-
109+
// Please see https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
110+
// To decode the data the central device cares.
111+
// This example use UUID as identity.
79112
switch (type)
80113
{
81114
case BT_DATA_UUID128_SOME:
@@ -86,10 +119,10 @@ bool adv_found(uint8_t type,
86119
Serial.println("AD malformed");
87120
return true;
88121
}
89-
struct bt_uuid * serviceuuid = bleImuService.uuid();
122+
bt_uuid_t* serviceuuid = bleImuService.uuid();
90123
for (i = 0; i < data_len; i += MAX_UUID_SIZE)
91124
{
92-
if (memcmp (((struct bt_uuid_128*)serviceuuid)->val, &data[i], MAX_UUID_SIZE) != 0)
125+
if (memcmp (((bt_uuid_128_t*)serviceuuid)->val, &data[i], MAX_UUID_SIZE) != 0)
93126
{
94127
continue;
95128
}
@@ -111,33 +144,20 @@ bool adv_found(uint8_t type,
111144
return true;
112145
}
113146

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-
}
147+
/*
148+
Copyright (c) 2016 Intel Corporation. All rights reserved.
137149
150+
This library is free software; you can redistribute it and/or
151+
modify it under the terms of the GNU Lesser General Public
152+
License as published by the Free Software Foundation; either
153+
version 2.1 of the License, or (at your option) any later version.
138154
139-
void loop()
140-
{
141-
delay(2000);
142-
}
155+
This library is distributed in the hope that it will be useful,
156+
but WITHOUT ANY WARRANTY; without even the implied warranty of
157+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
158+
Lesser General Public License for more details.
143159
160+
You should have received a copy of the GNU Lesser General Public
161+
License along with this library; if not, write to the Free Software
162+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
163+
*/

0 commit comments

Comments
 (0)