Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b3eb626

Browse files
sgbihuSidLeung
authored andcommittedFeb 10, 2017
BLE Peripheral cannot discover Central attributes
1. Add test sketches discoveratperipheral.ino and profileatcentral.ino 2. Modify BLEDeviceManager.cpp to add central to profile buffer in peripheral role.
1 parent 29daefb commit b3eb626

File tree

15 files changed

+749
-167
lines changed

15 files changed

+749
-167
lines changed
 

‎libraries/CurieBLE/examples/central/BatteryMonitor_Central/BatteryMonitor_Central.ino

+44-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1-
#include <CurieBLE.h>
1+
/*
2+
* Copyright (c) 2016 Intel Corporation. All rights reserved.
3+
* See the bottom of this file for the license terms.
4+
*/
25

36
/*
4-
This sketch example works with BatteryMonitor_Notification.ino
7+
* Sketch: BatteryMonitor_Central.ino
8+
*
9+
* Description:
10+
* This sketch will receive the notifications and output the received
11+
* data in the serial monitor. It also illustrates using a non-typed
12+
* characteristic.
13+
*
14+
* Notes:
15+
*
16+
* - Set the baud rate to 115200 on the serial monitor to accomodate
17+
* the speed of constant data updates
18+
* - Expected Peripheral name: BatteryMonitorSketch
19+
* - Expected Peripheral Characteristic: 2A19
20+
* - Expected Peripheral sketch: BatteryMonitor_Notification.ino
21+
*
22+
*/
523

6-
BatteryMonitor_Notification will send notification to this central sketch.
7-
This sketch will receive the notifications and output the received data in the serial monitor.
8-
It also illustrates using a non-typed characteristic.
9-
Set the baud rate to 115200 on the serial monitor to accomodate the speed of constant data updates
10-
*/
24+
#include <CurieBLE.h>
1125

1226
#define LED_PIN 13
1327

@@ -123,3 +137,26 @@ void printData(const unsigned char data[], int length) {
123137
Serial.print(b);
124138
}
125139
}
140+
141+
/*
142+
Copyright (c) 2016 Intel Corporation. All rights reserved.
143+
144+
This library is free software; you can redistribute it and/or
145+
modify it under the terms of the GNU Lesser General Public
146+
License as published by the Free Software Foundation; either
147+
version 2.1 of the License, or (at your option) any later version.
148+
149+
This library is distributed in the hope that it will be useful,
150+
but WITHOUT ANY WARRANTY; without even the implied warranty of
151+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
152+
Lesser General Public License for more details.
153+
154+
You should have received a copy of the GNU Lesser General Public
155+
License along with this library; if not, write to the Free Software
156+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
157+
*/
158+
159+
160+
161+
162+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* Copyright (c) 2016 Intel Corporation. All rights reserved.
3+
* See the bottom of this file for the license terms.
4+
*/
5+
6+
/*
7+
* Sketch: CentralDouble.ino.
8+
*
9+
* Description: This is a simple BLE sketch that initiates the
10+
* Arduino platform as a Central. It reads a double value from
11+
* a connected Peripheral. The sketch exercises: Scanning for
12+
* a specific Peripheral, connecting to it, discover its Attributes,
13+
* and exercise a specific Characteristic to read a double value
14+
* from the Peripheral.
15+
*
16+
* Notes: Expected Peripheral name: DataTest
17+
* Expected Peripheral Characteristic: 19b20001e8f2537e4f6cd104768a1214
18+
* Expected Characteristic read value: double.
19+
*/
20+
21+
#include "CurieBLE.h"
22+
23+
24+
// LED pin
25+
#define LED_PIN 13
26+
27+
void setup() {
28+
Serial.begin(9600);
29+
30+
// set LED pin to output mode
31+
pinMode(LED_PIN, OUTPUT);
32+
33+
// begin initialization
34+
BLE.begin();
35+
Serial.println(BLE.address());
36+
37+
BLE.scanForName("DataTest");
38+
}
39+
40+
void loop() {
41+
BLEDevice peripheral = BLE.available();
42+
if (peripheral)
43+
{
44+
Serial.println(peripheral.address());
45+
BLE.stopScan();
46+
// central connected to peripheral
47+
controlLogic(peripheral);
48+
BLE.scanForName("DataTest");
49+
}
50+
}
51+
52+
53+
void controlLogic(BLEDevice &peripheral)
54+
{
55+
// connect to the peripheral
56+
Serial.print("Connecting ... ");
57+
Serial.println(peripheral.address());
58+
59+
if (peripheral.connect())
60+
{
61+
Serial.print("Connected: ");
62+
Serial.println(peripheral.address());
63+
}
64+
else
65+
{
66+
Serial.println("Failed to connect!");
67+
return;
68+
}
69+
70+
if (peripheral.discoverAttributes() == false)
71+
{
72+
Serial.println("Discover failed, Disconnecting...");
73+
peripheral.disconnect();
74+
return;
75+
}
76+
77+
BLECharacteristic doubleCharacteristic = peripheral.characteristic("19b20001e8f2537e4f6cd104768a1214");
78+
79+
if (!doubleCharacteristic)
80+
{
81+
peripheral.disconnect();
82+
Serial.println("Peripheral does not have test double characteristic!");
83+
delay(5000);
84+
return;
85+
}
86+
doubleCharacteristic.subscribe();
87+
88+
while (peripheral.connected())
89+
{
90+
doubleCharacteristic.read();
91+
delay(1000);
92+
if (doubleCharacteristic.valueUpdated())
93+
{
94+
Serial.print("Double characteristic value: ");
95+
Serial.println(doubleCharacteristic.doubleValue());
96+
}
97+
delay(1000);
98+
}
99+
Serial.print("Disconnected");
100+
Serial.println(peripheral.address());
101+
}
102+
103+
104+
105+
/*
106+
Arduino BLE Peripheral Double read/write test example
107+
Copyright (c) 2016 Arduino LLC. All right reserved.
108+
109+
This library is free software; you can redistribute it and/or
110+
modify it under the terms of the GNU Lesser General Public
111+
License as published by the Free Software Foundation; either
112+
version 2.1 of the License, or (at your option) any later version.
113+
114+
This library is distributed in the hope that it will be useful,
115+
but WITHOUT ANY WARRANTY; without even the implied warranty of
116+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
117+
Lesser General Public License for more details.
118+
119+
You should have received a copy of the GNU Lesser General Public
120+
License along with this library; if not, write to the Free Software
121+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
122+
*/
123+
124+

‎libraries/CurieBLE/examples/central/IMUBleCentral/IMUBleCentral.ino

+38-23
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
11
/*
2-
Copyright (c) 2016 Arduino LLC. All right 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 St, Fifth Floor, Boston, MA 02110-1301 USA
17-
*/
18-
#include <CurieBLE.h>
2+
* Copyright (c) 2016 Intel Corporation. All rights reserved.
3+
* See the bottom of this file for the license terms.
4+
*/
195

206
/*
21-
This sketch example works with IMUBleNotification.ino
7+
* Sketch: IMUBleCentral.ino
8+
*
9+
* Description:
10+
* This sketch will receive the notifications and output the
11+
* received data in the serial monitor. It also illustrates
12+
* using a non-typed characteristic.
13+
*
14+
* Notes:
15+
*
16+
* - Expected Peripheral name: Imu
17+
* - Expected Peripheral Characteristic: F7580003-153E-D4F6-F26D-43D8D98EEB13
18+
* - Expected Peripheral sketch: IMUBleNotification.ino
19+
*/
2220

23-
IMUBleNotification.ino will send notification to this central sketch.
24-
This sketch will receive the notifications and output the received data in the serial monitor.
25-
It also illustrates using a non-typed characteristic.
26-
Set the baud rate to 115200 on the serial monitor to accomodate the speed of constant data updates from IMU subsystem.
27-
*/
21+
#include <CurieBLE.h>
2822

2923
#define LED_PIN 13
3024
#define MAX_IMU_RECORD 1
@@ -123,3 +117,24 @@ void controlImu(BLEDevice peripheral)
123117
Serial.print("Disconnected");
124118
Serial.println(peripheral.address());
125119
}
120+
121+
122+
/*
123+
Copyright (c) 2016 Arduino LLC. All right reserved.
124+
125+
This library is free software; you can redistribute it and/or
126+
modify it under the terms of the GNU Lesser General Public
127+
License as published by the Free Software Foundation; either
128+
version 2.1 of the License, or (at your option) any later version.
129+
130+
This library is distributed in the hope that it will be useful,
131+
but WITHOUT ANY WARRANTY; without even the implied warranty of
132+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
133+
Lesser General Public License for more details.
134+
135+
You should have received a copy of the GNU Lesser General Public
136+
License along with this library; if not, write to the Free Software
137+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
138+
*/
139+
140+

‎libraries/CurieBLE/examples/central/led_control/led_control.ino

+41-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
/*
2-
Arduino BLE Central LED Control example
3-
Copyright (c) 2016 Arduino LLC. All right reserved.
4-
5-
This library is free software; you can redistribute it and/or
6-
modify it under the terms of the GNU Lesser General Public
7-
License as published by the Free Software Foundation; either
8-
version 2.1 of the License, or (at your option) any later version.
9-
10-
This library is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13-
Lesser General Public License for more details.
14-
15-
You should have received a copy of the GNU Lesser General Public
16-
License along with this library; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18-
*/
2+
* Copyright (c) 2016 Intel Corporation. All rights reserved.
3+
* See the bottom of this file for the license terms.
4+
*/
195

6+
/*
7+
* Sketch: led_control.ino
8+
*
9+
* Description:
10+
* This is a Central sketch that looks for a particular Sevice with a
11+
* certain Characteristic from a Peripheral. Upon succesful discovery,
12+
* it reads the state of a button and write that value to the
13+
* Peripheral Characteristic.
14+
*
15+
* Notes:
16+
*
17+
* - Expected Peripheral Service: 19b10000-e8f2-537e-4f6c-d104768a1214
18+
* - Expected Peripheral Characteristic: 19b10001-e8f2-537e-4f6c-d104768a1214
19+
* - Expected Peripheral sketch:
20+
*
21+
*/
2022

2123
#include <CurieBLE.h>
2224

@@ -125,3 +127,25 @@ void controlLed(BLEDevice peripheral) {
125127
}
126128
}
127129
}
130+
131+
/*
132+
Arduino BLE Central LED Control example
133+
Copyright (c) 2016 Arduino LLC. All right reserved.
134+
135+
This library is free software; you can redistribute it and/or
136+
modify it under the terms of the GNU Lesser General Public
137+
License as published by the Free Software Foundation; either
138+
version 2.1 of the License, or (at your option) any later version.
139+
140+
This library is distributed in the hope that it will be useful,
141+
but WITHOUT ANY WARRANTY; without even the implied warranty of
142+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
143+
Lesser General Public License for more details.
144+
145+
You should have received a copy of the GNU Lesser General Public
146+
License along with this library; if not, write to the Free Software
147+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
148+
*/
149+
150+
151+

‎libraries/CurieBLE/examples/central/peripheral_explorer/peripheral_explorer.ino

+37-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/*
2-
Arduino BLE Central peripheral explorer example
3-
Copyright (c) 2016 Arduino LLC. All right reserved.
4-
5-
This library is free software; you can redistribute it and/or
6-
modify it under the terms of the GNU Lesser General Public
7-
License as published by the Free Software Foundation; either
8-
version 2.1 of the License, or (at your option) any later version.
2+
* Copyright (c) 2016 Intel Corporation. All rights reserved.
3+
* See the bottom of this file for the license terms.
4+
*/
95

10-
This library is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13-
Lesser General Public License for more details.
14-
15-
You should have received a copy of the GNU Lesser General Public
16-
License along with this library; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18-
*/
6+
/*
7+
* Sketch: BatteryMonitor_Central.ino
8+
*
9+
* Description:
10+
* This is a Central sketch demonstrating the discovery process
11+
* of a Peripheral. The discovered Attributes are being
12+
* display onto the serial output.
13+
*
14+
* Notes:
15+
*
16+
* - Expected Peripheral name: LED
17+
*
18+
*/
1919

2020
#include <CurieBLE.h>
2121

@@ -150,3 +150,24 @@ void printData(const unsigned char data[], int length) {
150150
}
151151
}
152152

153+
154+
/*
155+
Arduino BLE Central peripheral explorer example
156+
Copyright (c) 2016 Arduino LLC. All right reserved.
157+
158+
This library is free software; you can redistribute it and/or
159+
modify it under the terms of the GNU Lesser General Public
160+
License as published by the Free Software Foundation; either
161+
version 2.1 of the License, or (at your option) any later version.
162+
163+
This library is distributed in the hope that it will be useful,
164+
but WITHOUT ANY WARRANTY; without even the implied warranty of
165+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
166+
Lesser General Public License for more details.
167+
168+
You should have received a copy of the GNU Lesser General Public
169+
License along with this library; if not, write to the Free Software
170+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
171+
*/
172+
173+

‎libraries/CurieBLE/examples/central/scan/scan.ino

+34-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
/*
2-
Arduino BLE Central scan example
3-
Copyright (c) 2016 Arduino LLC. All right reserved.
4-
5-
This library is free software; you can redistribute it and/or
6-
modify it under the terms of the GNU Lesser General Public
7-
License as published by the Free Software Foundation; either
8-
version 2.1 of the License, or (at your option) any later version.
2+
* Copyright (c) 2016 Intel Corporation. All rights reserved.
3+
* See the bottom of this file for the license terms.
4+
*/
95

10-
This library is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13-
Lesser General Public License for more details.
14-
15-
You should have received a copy of the GNU Lesser General Public
16-
License along with this library; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18-
*/
6+
/*
7+
* Sketch: scan.ino
8+
*
9+
* Description:
10+
* This is a Central sketch that performs scanning of Peripherals
11+
* only. It does not perform connection. The Advertized info
12+
* of a Peripheral are display.
13+
*
14+
* Notes:
15+
*
16+
*/
1917

2018
#include <CurieBLE.h>
2119

@@ -68,3 +66,23 @@ void loop() {
6866
}
6967
}
7068

69+
70+
/*
71+
Arduino BLE Central scan example
72+
Copyright (c) 2016 Arduino LLC. All right reserved.
73+
74+
This library is free software; you can redistribute it and/or
75+
modify it under the terms of the GNU Lesser General Public
76+
License as published by the Free Software Foundation; either
77+
version 2.1 of the License, or (at your option) any later version.
78+
79+
This library is distributed in the hope that it will be useful,
80+
but WITHOUT ANY WARRANTY; without even the implied warranty of
81+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
82+
Lesser General Public License for more details.
83+
84+
You should have received a copy of the GNU Lesser General Public
85+
License along with this library; if not, write to the Free Software
86+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
87+
*/
88+

‎libraries/CurieBLE/examples/central/scan_callback/scan_callback.ino

+47-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
/*
2-
Arduino BLE Central scan callback example
3-
Copyright (c) 2016 Arduino LLC. All right reserved.
4-
5-
This library is free software; you can redistribute it and/or
6-
modify it under the terms of the GNU Lesser General Public
7-
License as published by the Free Software Foundation; either
8-
version 2.1 of the License, or (at your option) any later version.
9-
10-
This library is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13-
Lesser General Public License for more details.
2+
* Copyright (c) 2016 Intel Corporation. All rights reserved.
3+
* See the bottom of this file for the license terms.
4+
*/
145

15-
You should have received a copy of the GNU Lesser General Public
16-
License along with this library; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18-
*/
6+
/*
7+
* Sketch: scan_callback.ino
8+
*
9+
* Description:
10+
* This is a Central Sketch that scan for Peripherals without
11+
* performing connection. It displays the Adv info for each
12+
* Peripheral scanned. Notice that this sketch makes use of
13+
* the Event Handler, a call back routine, to display the
14+
* info onto the serial output.
15+
*
16+
* Notes:
17+
*
18+
* - It is highly recommended not to use the Event Handler to
19+
* dump information to the serial monitor. Please note
20+
* that Event Handler executes in interrupt context and it
21+
* is expected to perform short execution task. It is due
22+
* to the fact that the entire system timing is impact by the
23+
* execution time of the Event Handler. Accessing the serial
24+
* monitor is relatively time consuming, it is highly desirable
25+
* to perform that in the background.
26+
*
27+
*/
1928

2029
#include <CurieBLE.h>
2130

@@ -70,3 +79,25 @@ void bleCentralDiscoverHandler(BLEDevice peripheral) {
7079

7180
Serial.println();
7281
}
82+
83+
84+
85+
/*
86+
Arduino BLE Central scan callback example
87+
Copyright (c) 2016 Arduino LLC. All right reserved.
88+
89+
This library is free software; you can redistribute it and/or
90+
modify it under the terms of the GNU Lesser General Public
91+
License as published by the Free Software Foundation; either
92+
version 2.1 of the License, or (at your option) any later version.
93+
94+
This library is distributed in the hope that it will be useful,
95+
but WITHOUT ANY WARRANTY; without even the implied warranty of
96+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
97+
Lesser General Public License for more details.
98+
99+
You should have received a copy of the GNU Lesser General Public
100+
License along with this library; if not, write to the Free Software
101+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
102+
*/
103+

‎libraries/CurieBLE/examples/central/sensortag_button/sensortag_button.ino

+35-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
/*
2-
Arduino BLE Central SensorTag button example
3-
Copyright (c) 2016 Arduino LLC. All right reserved.
4-
5-
This library is free software; you can redistribute it and/or
6-
modify it under the terms of the GNU Lesser General Public
7-
License as published by the Free Software Foundation; either
8-
version 2.1 of the License, or (at your option) any later version.
9-
10-
This library is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13-
Lesser General Public License for more details.
2+
* Copyright (c) 2016 Intel Corporation. All rights reserved.
3+
* See the bottom of this file for the license terms.
4+
*/
145

15-
You should have received a copy of the GNU Lesser General Public
16-
License along with this library; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18-
*/
6+
/*
7+
* Sketch: BatteryMonitor_Central.ino
8+
*
9+
* Description:
10+
* This Central sketch scan for a Peripheral called the SensorTag.
11+
* It looks for particular Service, discovers all its attributes,
12+
* and them on the serial monitor.
13+
*
14+
*/
1915

2016
#include <CurieBLE.h>
2117

@@ -179,3 +175,26 @@ void monitorSensorTagButtons(BLEDevice peripheral)
179175
}
180176

181177
}
178+
179+
180+
181+
/*
182+
Arduino BLE Central SensorTag button example
183+
Copyright (c) 2016 Arduino LLC. All right reserved.
184+
185+
This library is free software; you can redistribute it and/or
186+
modify it under the terms of the GNU Lesser General Public
187+
License as published by the Free Software Foundation; either
188+
version 2.1 of the License, or (at your option) any later version.
189+
190+
This library is distributed in the hope that it will be useful,
191+
but WITHOUT ANY WARRANTY; without even the implied warranty of
192+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
193+
Lesser General Public License for more details.
194+
195+
You should have received a copy of the GNU Lesser General Public
196+
License along with this library; if not, write to the Free Software
197+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
198+
*/
199+
200+

‎libraries/CurieBLE/examples/peripheral/IMUBleNotification/IMUBleNotification.ino

+34-21
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
11
/*
2-
Copyright (c) 2016 Arduino LLC. All right 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.
2+
* Copyright (c) 2016 Intel Corporation. All rights reserved.
3+
* See the bottom of this file for the license terms.
4+
*/
85

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.
6+
/*
7+
* Sketch: IMUBleNotification.ino
8+
*
9+
* Description:
10+
* This is a Peripheral sketch that reads IMU data from sensor and sends
11+
* via notifications to a connected Central.
12+
*
13+
* Notes:
14+
*
15+
* - This sketch is inteneded to pair up with IMUBleCentral.ino.
16+
*
17+
*/
1318

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 St, Fifth Floor, Boston, MA 02110-1301 USA
17-
*/
1819
#include <CurieBLE.h>
1920
#include <CurieIMU.h>
2021

21-
/*
22-
This sketch example works with IMUBleCentral.ino.
23-
24-
This sketch will read IMU data from sensor and send notifications to IMUBleCentral.ino.
25-
IMUBleCentral.ino will receive the notifications and output the received data.
26-
*/
27-
2822
#define MAX_IMU_RECORD 1
2923

3024
typedef struct {
@@ -125,3 +119,22 @@ void recordImuData(int index)
125119
imuBuf[index].slot[2] = (unsigned int)((gy << 16) | (gz & 0x0FFFF));
126120
}
127121

122+
123+
/*
124+
Copyright (c) 2016 Arduino LLC. All right reserved.
125+
126+
This library is free software; you can redistribute it and/or
127+
modify it under the terms of the GNU Lesser General Public
128+
License as published by the Free Software Foundation; either
129+
version 2.1 of the License, or (at your option) any later version.
130+
131+
This library is distributed in the hope that it will be useful,
132+
but WITHOUT ANY WARRANTY; without even the implied warranty of
133+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
134+
Lesser General Public License for more details.
135+
136+
You should have received a copy of the GNU Lesser General Public
137+
License along with this library; if not, write to the Free Software
138+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
139+
*/
140+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright (c) 2016 Intel Corporation. All rights reserved.
3+
* See the bottom of this file for the license terms.
4+
*/
5+
6+
/*
7+
* Sketch: PeripheralDouble.ino
8+
*
9+
* Description:
10+
* This is a Peripheral sketch that has a Characteristic of double.
11+
* It demonstrates the usage of double in a BLE exchange.
12+
*
13+
* Notes:
14+
*
15+
* - Peripheral Characteristic: 19b20001e8f2537e4f6cd104768a1214
16+
*/
17+
18+
#include <CurieBLE.h>
19+
20+
// LED pin
21+
#define LED_PIN 13
22+
23+
// create service
24+
BLEService dataService("19b20000e8f2537e4f6cd104768a1214");
25+
26+
// create data characteristic
27+
BLEDoubleCharacteristic doubleCharacteristic("19b20001e8f2537e4f6cd104768a1214", BLERead | BLEWrite);
28+
29+
void setup() {
30+
Serial.begin(9600);
31+
32+
// set LED pin to output mode
33+
pinMode(LED_PIN, OUTPUT);
34+
35+
// begin initialization
36+
BLE.begin();
37+
Serial.println(BLE.address());
38+
39+
// set advertised local name and service UUID
40+
BLE.setLocalName("DataTest");
41+
42+
dataService.addCharacteristic(doubleCharacteristic);
43+
44+
// add service and characteristic
45+
BLE.addService(dataService);
46+
47+
BLE.advertise();
48+
49+
Serial.println(F("BLE Test Double Peripheral"));
50+
}
51+
52+
void loop() {
53+
BLEDevice central = BLE.central();
54+
double test_value = 0.1;
55+
56+
if (central) {
57+
// central connected to peripheral
58+
Serial.print(F("Connected to central: "));
59+
Serial.println(central.address());
60+
61+
while (central.connected())
62+
{
63+
// central still connected to peripheral
64+
doubleCharacteristic.writeDouble(test_value);
65+
test_value += 0.3;
66+
delay(2000);
67+
}
68+
69+
// central disconnected
70+
Serial.print(F("Disconnected from central: "));
71+
Serial.println(central.address());
72+
}
73+
}
74+
75+
76+
/*
77+
Arduino BLE Peripheral Double read/write test example
78+
Copyright (c) 2016 Arduino LLC. All right reserved.
79+
80+
This library is free software; you can redistribute it and/or
81+
modify it under the terms of the GNU Lesser General Public
82+
License as published by the Free Software Foundation; either
83+
version 2.1 of the License, or (at your option) any later version.
84+
85+
This library is distributed in the hope that it will be useful,
86+
but WITHOUT ANY WARRANTY; without even the implied warranty of
87+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
88+
Lesser General Public License for more details.
89+
90+
You should have received a copy of the GNU Lesser General Public
91+
License along with this library; if not, write to the Free Software
92+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
93+
*/
94+
95+

‎libraries/CurieBLE/examples/peripheral/led/led.ino

+33-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
/*
2-
Arduino BLE Peripheral LED example
3-
Copyright (c) 2016 Arduino LLC. All right reserved.
4-
5-
This library is free software; you can redistribute it and/or
6-
modify it under the terms of the GNU Lesser General Public
7-
License as published by the Free Software Foundation; either
8-
version 2.1 of the License, or (at your option) any later version.
9-
10-
This library is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13-
Lesser General Public License for more details.
2+
* Copyright (c) 2016 Intel Corporation. All rights reserved.
3+
* See the bottom of this file for the license terms.
4+
*/
145

15-
You should have received a copy of the GNU Lesser General Public
16-
License along with this library; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18-
*/
6+
/*
7+
* Sketch: BatteryMonitor_Central.ino
8+
*
9+
* Description:
10+
* This is a Peripheral sketch that works with a connected Central.
11+
* It allows the Central to write a value and set/reset the led
12+
* accordingly.
13+
*/
1914

2015
#include <CurieBLE.h>
2116

@@ -82,3 +77,25 @@ void loop() {
8277
Serial.println(central.address());
8378
}
8479
}
80+
81+
82+
/*
83+
Arduino BLE Peripheral LED example
84+
Copyright (c) 2016 Arduino LLC. All right reserved.
85+
86+
This library is free software; you can redistribute it and/or
87+
modify it under the terms of the GNU Lesser General Public
88+
License as published by the Free Software Foundation; either
89+
version 2.1 of the License, or (at your option) any later version.
90+
91+
This library is distributed in the hope that it will be useful,
92+
but WITHOUT ANY WARRANTY; without even the implied warranty of
93+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
94+
Lesser General Public License for more details.
95+
96+
You should have received a copy of the GNU Lesser General Public
97+
License along with this library; if not, write to the Free Software
98+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
99+
*/
100+
101+

‎libraries/CurieBLE/examples/peripheral/led_callback/led_callback.ino

+26-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
/*
2-
Arduino BLE Peripheral LED callback example
3-
Copyright (c) 2016 Arduino LLC. All right reserved.
4-
5-
This library is free software; you can redistribute it and/or
6-
modify it under the terms of the GNU Lesser General Public
7-
License as published by the Free Software Foundation; either
8-
version 2.1 of the License, or (at your option) any later version.
9-
10-
This library is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13-
Lesser General Public License for more details.
14-
15-
You should have received a copy of the GNU Lesser General Public
16-
License along with this library; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18-
*/
2+
* Copyright (c) 2016 Intel Corporation. All rights reserved.
3+
* See the bottom of this file for the license terms.
4+
*/
195

206
// Import libraries
217
#include <CurieBLE.h>
@@ -88,3 +74,26 @@ void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteri
8874
digitalWrite(LED_PIN, LOW);
8975
}
9076
}
77+
78+
79+
80+
/*
81+
Arduino BLE Peripheral LED callback example
82+
Copyright (c) 2016 Arduino LLC. All right reserved.
83+
84+
This library is free software; you can redistribute it and/or
85+
modify it under the terms of the GNU Lesser General Public
86+
License as published by the Free Software Foundation; either
87+
version 2.1 of the License, or (at your option) any later version.
88+
89+
This library is distributed in the hope that it will be useful,
90+
but WITHOUT ANY WARRANTY; without even the implied warranty of
91+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
92+
Lesser General Public License for more details.
93+
94+
You should have received a copy of the GNU Lesser General Public
95+
License along with this library; if not, write to the Free Software
96+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
97+
*/
98+
99+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
Arduino BLE Peripheral LED example
3+
Copyright (c) 2016 Arduino LLC. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#include <CurieBLE.h>
21+
22+
// LED pin
23+
#define LED_PIN 13
24+
25+
// create service
26+
BLEService ledService("19b10000e8f2537e4f6cd104768a1214");
27+
28+
void setup() {
29+
Serial.begin(9600);
30+
31+
// set LED pin to output mode
32+
pinMode(LED_PIN, OUTPUT);
33+
34+
// begin initialization
35+
BLE.begin();
36+
Serial.println(BLE.address());
37+
38+
// set advertised local name and service UUID
39+
BLE.setLocalName("LED");
40+
41+
BLE.advertise();
42+
43+
Serial.println(F("BLE LED Peripheral"));
44+
}
45+
46+
void loop() {
47+
BLEDevice central = BLE.central();
48+
49+
if (central) {
50+
// central connected to peripheral
51+
Serial.print(F("Connected to central: "));
52+
Serial.println(central.address());
53+
54+
controlLed(central);
55+
// central disconnected
56+
Serial.print(F("Disconnected from central: "));
57+
Serial.println(central.address());
58+
}
59+
}
60+
61+
void controlLed(BLEDevice &central)
62+
{
63+
if (central.discoverAttributes() == false)
64+
{
65+
Serial.println("Discover failed, Disconnecting...");
66+
central.disconnect();
67+
return;
68+
}
69+
70+
BLECharacteristic ledCharacteristic = central.characteristic("19b10101-e8f2-537e-4f6c-d104768a1214");
71+
72+
if (!ledCharacteristic)
73+
{
74+
central.disconnect();
75+
//while(1)
76+
{
77+
Serial.println("Central does not have LED characteristic!");
78+
delay(5000);
79+
}
80+
return;
81+
}
82+
83+
ledCharacteristic.subscribe();
84+
85+
unsigned char ledstate = 0;
86+
87+
while (central.connected())
88+
{
89+
if (ledstate == 1)
90+
{
91+
ledstate = 0;
92+
}
93+
else
94+
{
95+
ledstate = 1;
96+
}
97+
ledCharacteristic.write(&ledstate, sizeof(ledstate));
98+
delay(5000);
99+
}
100+
Serial.print("Disconnected");
101+
Serial.println(central.address());
102+
}
103+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
#include "CurieBLE.h"
3+
#include <errno.h>
4+
// LED pin
5+
#define LED_PIN 13
6+
BLEService ledService("19b10100e8f2537e4f6cd104768a1214");
7+
8+
BLECharacteristic switchCharacteristic("19b10101e8f2537e4f6cd104768a1214", BLERead | BLEWrite | BLENotify, 1);
9+
10+
BLEDescriptor switchDescriptor("2901", "switch");
11+
12+
void setup() {
13+
Serial.begin(115200);
14+
15+
// set LED pin to output mode
16+
pinMode(LED_PIN, OUTPUT);
17+
18+
// begin initialization
19+
BLE.begin();
20+
Serial.println(BLE.address());
21+
ledService.addCharacteristic(switchCharacteristic);
22+
switchCharacteristic.addDescriptor(switchDescriptor);
23+
BLE.addService(ledService);
24+
25+
BLE.scanForName("LED");
26+
}
27+
28+
29+
void loop() {
30+
BLEDevice peripheral = BLE.available();
31+
if (peripheral)
32+
{
33+
Serial.println(peripheral.address());
34+
35+
BLE.stopScan();
36+
37+
if (peripheral.connect())
38+
{
39+
Serial.print("Connected: ");
40+
Serial.println(peripheral.address());
41+
while (peripheral.connected())
42+
{
43+
delay (1000);
44+
}
45+
}
46+
else
47+
{
48+
Serial.println("Failed to connect!");
49+
}
50+
delay (4000);
51+
BLE.scanForName("LED");
52+
}
53+
}
54+
55+

‎libraries/CurieBLE/src/internal/BLEDeviceManager.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1051,11 +1051,12 @@ void BLEDeviceManager::handleConnectEvent(bt_conn_t *conn, uint8_t err)
10511051
}
10521052
else
10531053
{
1054+
// Peripheral has established the connection with this Central device
10541055
memset(&_wait_for_connect_peripheral, 0, sizeof(_wait_for_connect_peripheral));
10551056
_connecting = false;
1056-
// Peripheral has established the connection with this Central device
1057-
BLEProfileManager::instance()->handleConnectedEvent(bt_conn_get_dst(conn));
10581057
}
1058+
// The peripheral and central can work as GATT server. Reserve one buffer for peer device
1059+
BLEProfileManager::instance()->handleConnectedEvent(bt_conn_get_dst(conn));
10591060

10601061
if (NULL != _device_events[BLEConnected])
10611062
{

0 commit comments

Comments
 (0)
Please sign in to comment.