diff --git a/libraries/CurieBLE/examples/central/BatteryMonitor_Central/BatteryMonitor_Central.ino b/libraries/CurieBLE/examples/central/BatteryMonitor_Central/BatteryMonitor_Central.ino index 89469631..90a39dfb 100644 --- a/libraries/CurieBLE/examples/central/BatteryMonitor_Central/BatteryMonitor_Central.ino +++ b/libraries/CurieBLE/examples/central/BatteryMonitor_Central/BatteryMonitor_Central.ino @@ -1,13 +1,27 @@ -#include +/* + * Copyright (c) 2016 Intel Corporation. All rights reserved. + * See the bottom of this file for the license terms. + */ /* - This sketch example works with BatteryMonitor_Notification.ino + * Sketch: BatteryMonitor_Central.ino + * + * Description: + * This sketch will receive the notifications and output the received + * data in the serial monitor. It also illustrates using a non-typed + * characteristic. + * + * Notes: + * + * - Set the baud rate to 115200 on the serial monitor to accomodate + * the speed of constant data updates + * - Expected Peripheral name: BatteryMonitorSketch + * - Expected Peripheral Characteristic: 2A19 + * - Expected Peripheral sketch: BatteryMonitor_Notification.ino + * + */ - BatteryMonitor_Notification will send notification to this central sketch. - This sketch will receive the notifications and output the received data in the serial monitor. - It also illustrates using a non-typed characteristic. - Set the baud rate to 115200 on the serial monitor to accomodate the speed of constant data updates -*/ +#include #define LED_PIN 13 @@ -123,3 +137,26 @@ void printData(const unsigned char data[], int length) { Serial.print(b); } } + +/* + Copyright (c) 2016 Intel Corporation. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + + + + diff --git a/libraries/CurieBLE/examples/central/CentralDouble/CentralDouble.ino b/libraries/CurieBLE/examples/central/CentralDouble/CentralDouble.ino new file mode 100644 index 00000000..45089df4 --- /dev/null +++ b/libraries/CurieBLE/examples/central/CentralDouble/CentralDouble.ino @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2016 Intel Corporation. All rights reserved. + * See the bottom of this file for the license terms. + */ + +/* + * Sketch: CentralDouble.ino. + * + * Description: + * This is a simple BLE sketch that initiates the + * Arduino platform as a Central. It reads a double value from + * a connected Peripheral. The sketch exercises: Scanning for + * a specific Peripheral, connecting to it, discover its Attributes, + * and exercise a specific Characteristic to read a double value + * from the Peripheral. + * + * Notes: + * Expected Peripheral name: DataTest + * Expected Peripheral Characteristic: 19b20001e8f2537e4f6cd104768a1214 + * Expected Characteristic read value: double. + */ + +#include "CurieBLE.h" + + +// LED pin +#define LED_PIN 13 + +void setup() { + Serial.begin(9600); + + // set LED pin to output mode + pinMode(LED_PIN, OUTPUT); + + // begin initialization + BLE.begin(); + Serial.println(BLE.address()); + + BLE.scanForName("DataTest"); +} + +void loop() { + BLEDevice peripheral = BLE.available(); + if (peripheral) + { + Serial.println(peripheral.address()); + BLE.stopScan(); + // central connected to peripheral + controlLogic(peripheral); + BLE.scanForName("DataTest"); + } +} + + +void controlLogic(BLEDevice &peripheral) +{ + // connect to the peripheral + Serial.print("Connecting ... "); + Serial.println(peripheral.address()); + + if (peripheral.connect()) + { + Serial.print("Connected: "); + Serial.println(peripheral.address()); + } + else + { + Serial.println("Failed to connect!"); + return; + } + + if (peripheral.discoverAttributes() == false) + { + Serial.println("Discover failed, Disconnecting..."); + peripheral.disconnect(); + return; + } + + BLECharacteristic doubleCharacteristic = peripheral.characteristic("19b20001e8f2537e4f6cd104768a1214"); + + if (!doubleCharacteristic) + { + peripheral.disconnect(); + Serial.println("Peripheral does not have test double characteristic!"); + delay(5000); + return; + } + doubleCharacteristic.subscribe(); + + while (peripheral.connected()) + { + doubleCharacteristic.read(); + delay(1000); + if (doubleCharacteristic.valueUpdated()) + { + Serial.print("Double characteristic value: "); + Serial.println(doubleCharacteristic.doubleValue()); + } + delay(1000); + } + Serial.print("Disconnected"); + Serial.println(peripheral.address()); +} + + + +/* + Arduino BLE Peripheral Double read/write test example + Copyright (c) 2016 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + diff --git a/libraries/CurieBLE/examples/central/IMUBleCentral/IMUBleCentral.ino b/libraries/CurieBLE/examples/central/IMUBleCentral/IMUBleCentral.ino index 60748578..739a8b05 100644 --- a/libraries/CurieBLE/examples/central/IMUBleCentral/IMUBleCentral.ino +++ b/libraries/CurieBLE/examples/central/IMUBleCentral/IMUBleCentral.ino @@ -1,30 +1,24 @@ /* - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#include + * Copyright (c) 2016 Intel Corporation. All rights reserved. + * See the bottom of this file for the license terms. + */ /* - This sketch example works with IMUBleNotification.ino + * Sketch: IMUBleCentral.ino + * + * Description: + * This sketch will receive the notifications and output the + * received data in the serial monitor. It also illustrates + * using a non-typed characteristic. + * + * Notes: + * + * - Expected Peripheral name: Imu + * - Expected Peripheral Characteristic: F7580003-153E-D4F6-F26D-43D8D98EEB13 + * - Expected Peripheral sketch: IMUBleNotification.ino + */ - IMUBleNotification.ino will send notification to this central sketch. - This sketch will receive the notifications and output the received data in the serial monitor. - It also illustrates using a non-typed characteristic. - Set the baud rate to 115200 on the serial monitor to accomodate the speed of constant data updates from IMU subsystem. -*/ +#include #define LED_PIN 13 #define MAX_IMU_RECORD 1 @@ -123,3 +117,24 @@ void controlImu(BLEDevice peripheral) Serial.print("Disconnected"); Serial.println(peripheral.address()); } + + +/* + Copyright (c) 2016 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + diff --git a/libraries/CurieBLE/examples/central/led_control/led_control.ino b/libraries/CurieBLE/examples/central/led_control/led_control.ino index 8983a2ef..fd8ce3c2 100644 --- a/libraries/CurieBLE/examples/central/led_control/led_control.ino +++ b/libraries/CurieBLE/examples/central/led_control/led_control.ino @@ -1,22 +1,24 @@ /* - Arduino BLE Central LED Control example - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + * Copyright (c) 2016 Intel Corporation. All rights reserved. + * See the bottom of this file for the license terms. + */ +/* + * Sketch: led_control.ino + * + * Description: + * This is a Central sketch that looks for a particular Sevice with a + * certain Characteristic from a Peripheral. Upon succesful discovery, + * it reads the state of a button and write that value to the + * Peripheral Characteristic. + * + * Notes: + * + * - Expected Peripheral Service: 19b10000-e8f2-537e-4f6c-d104768a1214 + * - Expected Peripheral Characteristic: 19b10001-e8f2-537e-4f6c-d104768a1214 + * - Expected Peripheral sketch: + * + */ #include @@ -125,3 +127,25 @@ void controlLed(BLEDevice peripheral) { } } } + +/* + Arduino BLE Central LED Control example + Copyright (c) 2016 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + + diff --git a/libraries/CurieBLE/examples/central/peripheral_explorer/peripheral_explorer.ino b/libraries/CurieBLE/examples/central/peripheral_explorer/peripheral_explorer.ino index 5014b7ee..45429655 100644 --- a/libraries/CurieBLE/examples/central/peripheral_explorer/peripheral_explorer.ino +++ b/libraries/CurieBLE/examples/central/peripheral_explorer/peripheral_explorer.ino @@ -1,21 +1,21 @@ /* - Arduino BLE Central peripheral explorer example - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + * Copyright (c) 2016 Intel Corporation. All rights reserved. + * See the bottom of this file for the license terms. + */ - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ +/* + * Sketch: peripheral_explorer.ino + * + * Description: + * This is a Central sketch demonstrating the discovery process + * of a Peripheral. The discovered Attributes are being + * display onto the serial output. + * + * Notes: + * + * - Expected Peripheral name: LED + * + */ #include @@ -150,3 +150,24 @@ void printData(const unsigned char data[], int length) { } } + +/* + Arduino BLE Central peripheral explorer example + Copyright (c) 2016 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + diff --git a/libraries/CurieBLE/examples/central/scan/scan.ino b/libraries/CurieBLE/examples/central/scan/scan.ino index 32c77c97..d191d033 100644 --- a/libraries/CurieBLE/examples/central/scan/scan.ino +++ b/libraries/CurieBLE/examples/central/scan/scan.ino @@ -1,21 +1,19 @@ /* - Arduino BLE Central scan example - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + * Copyright (c) 2016 Intel Corporation. All rights reserved. + * See the bottom of this file for the license terms. + */ - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ +/* + * Sketch: scan.ino + * + * Description: + * This is a Central sketch that performs scanning of Peripherals + * only. It does not perform connection. The Advertized info + * of a Peripheral are display. + * + * Notes: + * + */ #include @@ -68,3 +66,23 @@ void loop() { } } + +/* + Arduino BLE Central scan example + Copyright (c) 2016 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + diff --git a/libraries/CurieBLE/examples/central/scan_callback/scan_callback.ino b/libraries/CurieBLE/examples/central/scan_callback/scan_callback.ino index ddb8b14c..fe853cd6 100644 --- a/libraries/CurieBLE/examples/central/scan_callback/scan_callback.ino +++ b/libraries/CurieBLE/examples/central/scan_callback/scan_callback.ino @@ -1,21 +1,30 @@ /* - Arduino BLE Central scan callback example - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. + * Copyright (c) 2016 Intel Corporation. All rights reserved. + * See the bottom of this file for the license terms. + */ - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ +/* + * Sketch: scan_callback.ino + * + * Description: + * This is a Central Sketch that scan for Peripherals without + * performing connection. It displays the Adv info for each + * Peripheral scanned. Notice that this sketch makes use of + * the Event Handler, a call back routine, to display the + * info onto the serial output. + * + * Notes: + * + * - It is highly recommended not to use the Event Handler to + * dump information to the serial monitor. Please note + * that Event Handler executes in interrupt context and it + * is expected to perform short execution task. It is due + * to the fact that the entire system timing is impact by the + * execution time of the Event Handler. Accessing the serial + * monitor is relatively time consuming, it is highly desirable + * to perform that in the background. + * + */ #include @@ -70,3 +79,25 @@ void bleCentralDiscoverHandler(BLEDevice peripheral) { Serial.println(); } + + + +/* + Arduino BLE Central scan callback example + Copyright (c) 2016 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + diff --git a/libraries/CurieBLE/examples/central/sensortag_button/sensortag_button.ino b/libraries/CurieBLE/examples/central/sensortag_button/sensortag_button.ino index 7f3f1aa2..786ff051 100644 --- a/libraries/CurieBLE/examples/central/sensortag_button/sensortag_button.ino +++ b/libraries/CurieBLE/examples/central/sensortag_button/sensortag_button.ino @@ -1,21 +1,17 @@ /* - Arduino BLE Central SensorTag button example - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. + * Copyright (c) 2016 Intel Corporation. All rights reserved. + * See the bottom of this file for the license terms. + */ - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ +/* + * Sketch: sensortag_button.ino + * + * Description: + * This Central sketch scan for a Peripheral called the SensorTag. + * It looks for particular Service, discovers all its attributes, + * and them on the serial monitor. + * + */ #include @@ -179,3 +175,26 @@ void monitorSensorTagButtons(BLEDevice peripheral) } } + + + +/* + Arduino BLE Central SensorTag button example + Copyright (c) 2016 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + diff --git a/libraries/CurieBLE/examples/peripheral/BatteryMonitor_Notification/BatteryMonitor_Notification.ino b/libraries/CurieBLE/examples/peripheral/BatteryMonitor_Notification/BatteryMonitor_Notification.ino index 2325f351..a44cd6b6 100644 --- a/libraries/CurieBLE/examples/peripheral/BatteryMonitor_Notification/BatteryMonitor_Notification.ino +++ b/libraries/CurieBLE/examples/peripheral/BatteryMonitor_Notification/BatteryMonitor_Notification.ino @@ -3,18 +3,24 @@ See the bottom of this file for the license terms. */ -#include - /* - This sketch can work with BatteryMonitor_Central. - - You can also use an android or IOS app that supports notifications. - This sketch example partially implements the standard Bluetooth Low-Energy Battery service - and connection interval paramater update. - For more information: https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx -*/ - + * Sketch: BatteryMonitor_Notification.ino + * + * Description: + * This sketch example partially implements the standard Bluetooth + * Low-Energy Battery service and connection interval paramater update. + * + * For more information: + * https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx + * + * Notes: + * + * - Expected to work with BatteryMonitor_Central sketch. + * You can also use an android or IOS app that supports notifications. + * + */ +#include BLEService batteryService("180F"); // BLE Battery Service diff --git a/libraries/CurieBLE/examples/peripheral/IMUBleNotification/IMUBleNotification.ino b/libraries/CurieBLE/examples/peripheral/IMUBleNotification/IMUBleNotification.ino index c3ac0ff0..e8ad758b 100644 --- a/libraries/CurieBLE/examples/peripheral/IMUBleNotification/IMUBleNotification.ino +++ b/libraries/CurieBLE/examples/peripheral/IMUBleNotification/IMUBleNotification.ino @@ -1,30 +1,24 @@ /* - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + * Copyright (c) 2016 Intel Corporation. All rights reserved. + * See the bottom of this file for the license terms. + */ - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. +/* + * Sketch: IMUBleNotification.ino + * + * Description: + * This is a Peripheral sketch that reads IMU data from sensor and sends + * via notifications to a connected Central. + * + * Notes: + * + * - This sketch is inteneded to pair up with IMUBleCentral.ino. + * + */ - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ #include #include -/* - This sketch example works with IMUBleCentral.ino. - - This sketch will read IMU data from sensor and send notifications to IMUBleCentral.ino. - IMUBleCentral.ino will receive the notifications and output the received data. -*/ - #define MAX_IMU_RECORD 1 typedef struct { @@ -125,3 +119,22 @@ void recordImuData(int index) imuBuf[index].slot[2] = (unsigned int)((gy << 16) | (gz & 0x0FFFF)); } + +/* + Copyright (c) 2016 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + diff --git a/libraries/CurieBLE/examples/peripheral/PeripheralDouble/PeripheralDouble.ino b/libraries/CurieBLE/examples/peripheral/PeripheralDouble/PeripheralDouble.ino new file mode 100644 index 00000000..658822e2 --- /dev/null +++ b/libraries/CurieBLE/examples/peripheral/PeripheralDouble/PeripheralDouble.ino @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2016 Intel Corporation. All rights reserved. + * See the bottom of this file for the license terms. + */ + +/* + * Sketch: PeripheralDouble.ino + * + * Description: + * This is a Peripheral sketch that has a Characteristic of double. + * It demonstrates the usage of double in a BLE exchange. + * + * Notes: + * + * - Peripheral Characteristic: 19b20001e8f2537e4f6cd104768a1214 + */ + +#include + +// LED pin +#define LED_PIN 13 + +// create service +BLEService dataService("19b20000e8f2537e4f6cd104768a1214"); + +// create data characteristic +BLEDoubleCharacteristic doubleCharacteristic("19b20001e8f2537e4f6cd104768a1214", BLERead | BLEWrite); + +void setup() { + Serial.begin(9600); + + // set LED pin to output mode + pinMode(LED_PIN, OUTPUT); + + // begin initialization + BLE.begin(); + Serial.println(BLE.address()); + + // set advertised local name and service UUID + BLE.setLocalName("DataTest"); + + dataService.addCharacteristic(doubleCharacteristic); + + // add service and characteristic + BLE.addService(dataService); + + BLE.advertise(); + + Serial.println(F("BLE Test Double Peripheral")); +} + +void loop() { + BLEDevice central = BLE.central(); + double test_value = 0.1; + + if (central) { + // central connected to peripheral + Serial.print(F("Connected to central: ")); + Serial.println(central.address()); + + while (central.connected()) + { + // central still connected to peripheral + doubleCharacteristic.writeDouble(test_value); + test_value += 0.3; + delay(2000); + } + + // central disconnected + Serial.print(F("Disconnected from central: ")); + Serial.println(central.address()); + } +} + + +/* + Arduino BLE Peripheral Double read/write test example + Copyright (c) 2016 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + diff --git a/libraries/CurieBLE/examples/peripheral/led/led.ino b/libraries/CurieBLE/examples/peripheral/led/led.ino index 55948fd1..4cbb25dd 100644 --- a/libraries/CurieBLE/examples/peripheral/led/led.ino +++ b/libraries/CurieBLE/examples/peripheral/led/led.ino @@ -1,21 +1,16 @@ /* - Arduino BLE Peripheral LED example - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. + * Copyright (c) 2016 Intel Corporation. All rights reserved. + * See the bottom of this file for the license terms. + */ - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ +/* + * Sketch: led.ino + * + * Description: + * This is a Peripheral sketch that works with a connected Central. + * It allows the Central to write a value and set/reset the led + * accordingly. + */ #include @@ -82,3 +77,25 @@ void loop() { Serial.println(central.address()); } } + + +/* + Arduino BLE Peripheral LED example + Copyright (c) 2016 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + diff --git a/libraries/CurieBLE/examples/peripheral/led_callback/led_callback.ino b/libraries/CurieBLE/examples/peripheral/led_callback/led_callback.ino index e00bf419..54a5c659 100644 --- a/libraries/CurieBLE/examples/peripheral/led_callback/led_callback.ino +++ b/libraries/CurieBLE/examples/peripheral/led_callback/led_callback.ino @@ -1,21 +1,7 @@ /* - Arduino BLE Peripheral LED callback example - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + * Copyright (c) 2016 Intel Corporation. All rights reserved. + * See the bottom of this file for the license terms. + */ // Import libraries #include @@ -88,3 +74,26 @@ void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteri digitalWrite(LED_PIN, LOW); } } + + + +/* + Arduino BLE Peripheral LED callback example + Copyright (c) 2016 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + diff --git a/libraries/CurieBLE/examples/test/CommunitySketches/AccelerometerBLE/AccelerometerBLE.ino b/libraries/CurieBLE/examples/test/CommunitySketches/AccelerometerBLE/AccelerometerBLE.ino deleted file mode 100644 index 0e660cb6..00000000 --- a/libraries/CurieBLE/examples/test/CommunitySketches/AccelerometerBLE/AccelerometerBLE.ino +++ /dev/null @@ -1,94 +0,0 @@ -#include -#include "CurieIMU.h" - - -BLEPeripheral blePeripheral; // BLE Peripheral Device (the board you're programming) -BLEService accelService("19B10010-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service - -// BLE accelerometer Characteristic - custom 128-bit UUID, read by central -BLEFloatCharacteristic accelX("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); -BLEFloatCharacteristic accelY("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); -BLEFloatCharacteristic accelZ("19B10013-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); - -long lastUpdate = 0; - -void setup() { - Serial.begin(9600); - - // set advertised local name and service UUID: - blePeripheral.setLocalName("tigoeAcc"); - blePeripheral.setAdvertisedServiceUuid(accelService.uuid()); - - // add service and characteristic: - blePeripheral.addAttribute(accelService); - blePeripheral.addAttribute(accelX); - blePeripheral.addAttribute(accelY); - blePeripheral.addAttribute(accelZ); - - CurieIMU.begin(); - - // Set the accelerometer range to 2G - CurieIMU.setAccelerometerRange(2); - // set the initial value for the characeristic: - accelX.setValue(0); - accelY.setValue(0); - accelZ.setValue(0); - - // begin advertising BLE service: - blePeripheral.begin(); - pinMode(13, OUTPUT); - Serial.println("Starting"); -} - -void loop() { - // listen for BLE peripherals to connect: - BLECentral central = blePeripheral.central(); - - // if a central is connected to peripheral: - if (central) { - digitalWrite(13, HIGH); - 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()) { - long now = millis(); - if (now - lastUpdate > 1000) { - updateAccelerometer(); - lastUpdate = now; - } - } - // when the central disconnects, print it out: - Serial.print("Disconnected from central: "); - Serial.println(central.address()); - digitalWrite(13, LOW); - - } -} - -void updateAccelerometer() { - int axRaw, ayRaw, azRaw; // raw accelerometer values - float ax, ay, az; - - // read raw accelerometer measurements from device - CurieIMU.readAccelerometer(axRaw, ayRaw, azRaw); - - // convert the raw accelerometer data to G's - ax = convertRawAcceleration(axRaw); - ay = convertRawAcceleration(ayRaw); - az = convertRawAcceleration(azRaw); - - accelX.setValue(ax); - accelY.setValue(ay); - accelZ.setValue(az); -} - -float convertRawAcceleration(int aRaw) { - // since we are using 2G range - // -2g maps to a raw value of -32768 - // +2g maps to a raw value of 32767 - - float a = (aRaw * 2.0) / 32768.0; - return a; -} diff --git a/libraries/CurieBLE/examples/test/CommunitySketches/Genuino101CurieBLEHeartRateMonitor/Genuino101CurieBLEHeartRateMonitor.ino b/libraries/CurieBLE/examples/test/CommunitySketches/Genuino101CurieBLEHeartRateMonitor/Genuino101CurieBLEHeartRateMonitor.ino index b7062f34..5428572f 100644 --- a/libraries/CurieBLE/examples/test/CommunitySketches/Genuino101CurieBLEHeartRateMonitor/Genuino101CurieBLEHeartRateMonitor.ino +++ b/libraries/CurieBLE/examples/test/CommunitySketches/Genuino101CurieBLEHeartRateMonitor/Genuino101CurieBLEHeartRateMonitor.ino @@ -1,25 +1,17 @@ /* - Copyright (c) 2015 Intel Corporation. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + * Copyright (c) 2016 Intel Corporation. All rights reserved. + * See the bottom of this file for the license terms. + */ /* - This sketch example partially implements the standard Bluetooth Low-Energy Heart Rate service. - For more information: https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx -*/ + * Sketch: Genuino101CurieBLEHeartRateMonitor.ino. + * + * Description: + * This sketch example partially implements the standard Bluetooth Low-Energy + * Heart Rate service. For more information: + * https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx + * + */ #include @@ -97,4 +89,24 @@ void updateHeartRate() { heartRateChar.setValue(heartRateCharArray, 2); // and update the heart rate measurement characteristic oldHeartRate = heartRate; // save the level for next comparison } -} +} + +/* + Copyright (c) 2015 Intel Corporation. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + diff --git a/libraries/CurieBLE/examples/test/CommunitySketches/StandardFirmataBLE/StandardFirmataBLE.ino b/libraries/CurieBLE/examples/test/CommunitySketches/StandardFirmataBLE/StandardFirmataBLE.ino index cf1e3a74..398993f9 100644 --- a/libraries/CurieBLE/examples/test/CommunitySketches/StandardFirmataBLE/StandardFirmataBLE.ino +++ b/libraries/CurieBLE/examples/test/CommunitySketches/StandardFirmataBLE/StandardFirmataBLE.ino @@ -1,21 +1,20 @@ /* - Firmata is a generic protocol for communicating with microcontrollers - from software on a host computer. It is intended to work with - any host computer software package. - To download a host software package, please click on the following link - to open the list of Firmata client libraries in your default browser. - https://github.com/firmata/arduino#firmata-client-libraries - Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved. - Copyright (C) 2010-2011 Paul Stoffregen. All rights reserved. - Copyright (C) 2009 Shigeru Kobayashi. All rights reserved. - Copyright (C) 2009-2016 Jeff Hoefs. All rights reserved. - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - See file LICENSE.txt for further informations on licensing terms. - Last updated October 16th, 2016 -*/ + * Copyright (c) 2016 Intel Corporation. All rights reserved. + * See the bottom of this file for the license terms. + */ + +/* + * Sketch: StandardFirmataBLE.ino. + * + * Description: + * Firmata is a generic protocol for communicating with microcontrollers + * from software on a host computer. It is intended to work with + * any host computer software package. + * + * Notes: + * - Please use the link stated at the end of this file to + * download a host s/w package. + */ #include #include @@ -830,4 +829,25 @@ void loop() #ifdef FIRMATA_SERIAL_FEATURE serialFeature.update(); #endif -} +} + +/* + Firmata is a generic protocol for communicating with microcontrollers + from software on a host computer. It is intended to work with + any host computer software package. + To download a host software package, please click on the following link + to open the list of Firmata client libraries in your default browser. + https://github.com/firmata/arduino#firmata-client-libraries + Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved. + Copyright (C) 2010-2011 Paul Stoffregen. All rights reserved. + Copyright (C) 2009 Shigeru Kobayashi. All rights reserved. + Copyright (C) 2009-2016 Jeff Hoefs. All rights reserved. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + See file LICENSE.txt for further informations on licensing terms. + Last updated October 16th, 2016 +*/ + + diff --git a/libraries/CurieBLE/examples/test/CommunitySketches/StarterKit101_BLE/StarterKit101_BLE.ino b/libraries/CurieBLE/examples/test/CommunitySketches/StarterKit101_BLE/StarterKit101_BLE.ino deleted file mode 100644 index 641af931..00000000 --- a/libraries/CurieBLE/examples/test/CommunitySketches/StarterKit101_BLE/StarterKit101_BLE.ino +++ /dev/null @@ -1,37 +0,0 @@ -#include -// change the next line based on what your smartphone is configured to advertise -const String deviceName = "Nexus 5X"; -const int rssiTrigger = -50; -const int ledPin = 13; - -void setup() { - Serial.begin(9600); - BLE.begin(); - pinMode(ledPin, OUTPUT); - BLE.setEventHandler(BLEDiscovered, bleCentralDiscoverHandler); - while (!Serial) ; - Serial.println("Bluetooth device active, start scanning..."); - BLE.scan(true); -} - -void loop() { - BLE.poll(); -} - -void bleCentralDiscoverHandler(BLEDevice peripheral) { - if (peripheral.hasLocalName()) { - Serial.println(peripheral.localName()); - if (peripheral.localName().indexOf(deviceName) != -1) { - Serial.println(" found"); - Serial.print("Rssi: "); - Serial.println(peripheral.rssi()); - if (peripheral.rssi() > rssiTrigger) { - Serial.println("LED ON"); - digitalWrite(ledPin, HIGH); - } else { - Serial.println("LED OFF"); - digitalWrite(ledPin, LOW); - } - } - } -} diff --git a/libraries/CurieBLE/examples/test/central/central.ino b/libraries/CurieBLE/examples/test/central/central.ino deleted file mode 100644 index 5bc13524..00000000 --- a/libraries/CurieBLE/examples/test/central/central.ino +++ /dev/null @@ -1,86 +0,0 @@ - -#include "CurieBLE.h" - -// LED pin -#define LED_PIN 13 - -void setup() { - Serial.begin(9600); - Serial.println("test---"); - - // set LED pin to output mode - pinMode(LED_PIN, OUTPUT); - - // begin initialization - BLE.begin(); - Serial.println(BLE.address()); - - BLE.scanForName("LED"); -} - -void controlLed(BLEDevice &peripheral) -{ - static bool discovered = false; - // connect to the peripheral - Serial.print("Connecting ... "); - Serial.println(peripheral.address()); - - if (peripheral.connect()) - { - Serial.print("Connected: "); - Serial.println(peripheral.address()); - } - else - { - Serial.println("Failed to connect!"); - return; - } - - peripheral.discoverAttributes(); - - BLECharacteristic ledCharacteristic = peripheral.characteristic("19b10101-e8f2-537e-4f6c-d104768a1214"); - - if (!ledCharacteristic) - { - peripheral.disconnect(); - Serial.println("Peripheral does not have LED characteristic!"); - delay(5000); - return; - } - - - unsigned char ledstate = 0; - - discovered = false; - while (peripheral.connected()) - { - if (ledstate == 1) - { - ledstate = 0; - } - else - { - ledstate = 1; - } - ledCharacteristic.write(&ledstate, sizeof(ledstate)); - delay(5000); - } - Serial.print("Disconnected"); - Serial.println(peripheral.address()); -} - -void loop() { - BLEDevice peripheral = BLE.available(); - if (peripheral) - { - Serial.println(peripheral.address()); - BLE.stopScan(); - delay (1000); - // central connected to peripheral - controlLed(peripheral); - delay (4000); - BLE.scanForName("LED"); - } -} - - diff --git a/libraries/CurieBLE/examples/test/discoveratperipheral/discoveratperipheral.ino b/libraries/CurieBLE/examples/test/discoveratperipheral/discoveratperipheral.ino new file mode 100644 index 00000000..8de71767 --- /dev/null +++ b/libraries/CurieBLE/examples/test/discoveratperipheral/discoveratperipheral.ino @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2016 Intel Corporation. All rights reserved. + * See the bottom of this file for the license terms. + */ + +/* + * Sketch: discoveratperipheral.ino. + * + * Description: + * This is a BLE Central sketch that looks for a particular + * Characteristic in a connected Peripheral to write to. The + * Peripheral with the special Characteristic will blink its + * LED. + * + * Notes: + * - This sketch is Arduino BLE Peripheral LED example. + * Please see licensing at the bottom of this file. + * - Expected Peripheral Characteristic: 19b10000e8f2537e4f6cd104768a1214 + */ + +#include + +// LED pin +#define LED_PIN 13 + +// create service +BLEService ledService("19b10000e8f2537e4f6cd104768a1214"); + +void setup() { + Serial.begin(9600); + + // set LED pin to output mode + pinMode(LED_PIN, OUTPUT); + + // begin initialization + BLE.begin(); + Serial.println(BLE.address()); + + // set advertised local name and service UUID + BLE.setLocalName("LED"); + + BLE.advertise(); + + Serial.println(F("BLE LED Peripheral")); +} + +void loop() { + BLEDevice central = BLE.central(); + + if (central) { + // central connected to peripheral + Serial.print(F("Connected to central: ")); + Serial.println(central.address()); + + controlLed(central); + // central disconnected + Serial.print(F("Disconnected from central: ")); + Serial.println(central.address()); + } +} + +void controlLed(BLEDevice ¢ral) +{ + if (central.discoverAttributes() == false) + { + Serial.println("Discover failed, Disconnecting..."); + central.disconnect(); + return; + } + + BLECharacteristic ledCharacteristic = central.characteristic("19b10101-e8f2-537e-4f6c-d104768a1214"); + + if (!ledCharacteristic) + { + central.disconnect(); + //while(1) + { + Serial.println("Central does not have LED characteristic!"); + delay(5000); + } + return; + } + + ledCharacteristic.subscribe(); + + unsigned char ledstate = 0; + + while (central.connected()) + { + if (ledstate == 1) + { + ledstate = 0; + } + else + { + ledstate = 1; + } + ledCharacteristic.write(&ledstate, sizeof(ledstate)); + delay(5000); + } + Serial.print("Disconnected"); + Serial.println(central.address()); +} + + +/* + Arduino BLE Peripheral LED example + Copyright (c) 2016 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + diff --git a/libraries/CurieBLE/examples/test/notification/notification.ino b/libraries/CurieBLE/examples/test/notification/notification.ino deleted file mode 100644 index 542102bb..00000000 --- a/libraries/CurieBLE/examples/test/notification/notification.ino +++ /dev/null @@ -1,78 +0,0 @@ - -#include "CurieBLE.h" - -// LED pin -#define LED_PIN 13 - -// create service -BLEService ledService("19b10100e8f2537e4f6cd104768a1214"); - -BLECharacteristic switchCharacteristic("19b10101e8f2537e4f6cd104768a1214", BLERead | BLEWrite | BLENotify, 1); - -BLEDescriptor switchDescriptor("2901", "switch"); - -void setup() { - Serial.begin(9600); - Serial.println("test---"); - - // set LED pin to output mode - pinMode(LED_PIN, OUTPUT); - - // begin initialization - BLE.begin(); - Serial.println(BLE.address()); - - // set advertised local name and service UUID - BLE.setLocalName("LED"); - BLE.setAdvertisedServiceUuid(ledService.uuid()); - - // add service and characteristic - BLE.addService(ledService); - ledService.addCharacteristic(switchCharacteristic); - switchCharacteristic.addDescriptor(switchDescriptor); - unsigned char test = 1; - switchCharacteristic.writeValue(&test,1); - BLE.advertise(); -} - -void loop() { - static int i = 0; - BLEDevice central = BLE.central(); - bool temp = central; -i++; - if (temp) { - // central connected to peripheral - Serial.print(i); - Serial.print(F("Connected to central: ")); - Serial.println(central.address()); - - Serial.print(temp); - - unsigned char ledstate = 0; - - while (central.connected()) { - // central still connected to peripheral - if (switchCharacteristic.canNotify()) - { - - if (ledstate == 1) - { - ledstate = 0; - digitalWrite(LED_PIN, LOW); - } - else - { - ledstate = 1; - digitalWrite(LED_PIN, HIGH); - } - switchCharacteristic.writeValue(&ledstate, sizeof(ledstate)); - delay(5000); - } - } - - // central disconnected - Serial.print(F("Disconnected from central: ")); - Serial.println(central.address()); - } - //delay (1000); -} diff --git a/libraries/CurieBLE/examples/test/notifycentral/notifycentral.ino b/libraries/CurieBLE/examples/test/notifycentral/notifycentral.ino deleted file mode 100644 index 47086b18..00000000 --- a/libraries/CurieBLE/examples/test/notifycentral/notifycentral.ino +++ /dev/null @@ -1,89 +0,0 @@ - -#include "CurieBLE.h" - -// LED pin -#define LED_PIN 13 - -void setup() { - Serial.begin(9600); - Serial.println("test---"); - - // set LED pin to output mode - pinMode(LED_PIN, OUTPUT); - - // begin initialization - BLE.begin(); - Serial.println(BLE.address()); - - BLE.scanForName("LED"); -} - -void controlLed(BLEDevice &peripheral) -{ - static bool discovered = false; - // connect to the peripheral - Serial.print("Connecting ... "); - Serial.println(peripheral.address()); - - if (peripheral.connect()) - { - Serial.print("Connected: "); - Serial.println(peripheral.address()); - } - else - { - Serial.println("Failed to connect!"); - return; - } - - peripheral.discoverAttributes(); - - BLECharacteristic ledCharacteristic = peripheral.characteristic("19b10101-e8f2-537e-4f6c-d104768a1214"); - - if (!ledCharacteristic) - { - peripheral.disconnect(); - Serial.println("Peripheral does not have LED characteristic!"); - delay(5000); - return; - } - ledCharacteristic.subscribe(); - - - discovered = false; - while (peripheral.connected()) - { - if (ledCharacteristic.valueUpdated()) - { - char ledValue = *ledCharacteristic.value(); - - if (ledValue) { - Serial.println(F("LED on")); - digitalWrite(LED_PIN, HIGH); - } else { - Serial.println(F("LED off")); - digitalWrite(LED_PIN, LOW); - } - } - } - Serial.print("Disconnected"); - Serial.println(peripheral.address()); -} - -void loop() { - //pr_debug(LOG_MODULE_BLE, "%s-%d",__FUNCTION__, __LINE__); - BLEDevice peripheral = BLE.available(); - //pr_debug(LOG_MODULE_BLE, "%s-%d",__FUNCTION__, __LINE__); - if (peripheral) - { - Serial.println(peripheral.address()); - BLE.stopScan(); - delay (1000); - // central connected to peripheral - controlLed(peripheral); - delay (4000); - BLE.scanForName("LED"); - } -} - - diff --git a/libraries/CurieBLE/examples/test/profileatcentral/profileatcentral.ino b/libraries/CurieBLE/examples/test/profileatcentral/profileatcentral.ino new file mode 100644 index 00000000..2fe20520 --- /dev/null +++ b/libraries/CurieBLE/examples/test/profileatcentral/profileatcentral.ino @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2017 Intel Corporation. All rights reserved. + * See the bottom of this file for the license terms. + */ + +/* + * Sketch: profileatcentral.ino + * + * Description: + * This is a BLE Central sketch that demostrates the setting of the + * BLE descriptor. + * + * Notes: + * - This sketch is based on the Arduino BLE Peripheral LED example. + * Please refer to licensing agreement at the bottom of this file. + */ + +#include "CurieBLE.h" +#include +// LED pin +#define LED_PIN 13 +BLEService ledService("19b10100e8f2537e4f6cd104768a1214"); + +BLECharacteristic switchCharacteristic("19b10101e8f2537e4f6cd104768a1214", BLERead | BLEWrite | BLENotify, 1); + +BLEDescriptor switchDescriptor("2901", "switch"); + +void setup() { + Serial.begin(115200); + + // set LED pin to output mode + pinMode(LED_PIN, OUTPUT); + + // begin initialization + BLE.begin(); + Serial.println(BLE.address()); + ledService.addCharacteristic(switchCharacteristic); + switchCharacteristic.addDescriptor(switchDescriptor); + BLE.addService(ledService); + + BLE.scanForName("LED"); +} + + +void loop() { + BLEDevice peripheral = BLE.available(); + if (peripheral) + { + Serial.println(peripheral.address()); + + BLE.stopScan(); + + if (peripheral.connect()) + { + Serial.print("Connected: "); + Serial.println(peripheral.address()); + while (peripheral.connected()) + { + delay (1000); + } + } + else + { + Serial.println("Failed to connect!"); + } + delay (4000); + BLE.scanForName("LED"); + } +} + + +/* + Arduino BLE Peripheral LED example + Copyright (c) 2016 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + diff --git a/libraries/CurieBLE/examples/test/test/test.ino b/libraries/CurieBLE/examples/test/test/test.ino deleted file mode 100644 index bd4da60c..00000000 --- a/libraries/CurieBLE/examples/test/test/test.ino +++ /dev/null @@ -1,71 +0,0 @@ - -#include "CurieBLE.h" - -// LED pin -#define LED_PIN 13 - -// create service -BLEService ledService("19b10100e8f2537e4f6cd104768a1214"); - -BLECharacteristic switchCharacteristic("19b10101e8f2537e4f6cd104768a1214", BLERead | BLEWrite | BLENotify, 1); - -BLEDescriptor switchDescriptor("2901", "switch"); - -void setup() { - Serial.begin(9600); - Serial.println("test---"); - - // set LED pin to output mode - pinMode(LED_PIN, OUTPUT); - - // begin initialization - BLE.begin(); - Serial.println(BLE.address()); - - // set advertised local name and service UUID - BLE.setLocalName("LED"); - BLE.setAdvertisedServiceUuid(ledService.uuid()); - - // add service and characteristic - BLE.addService(ledService); - ledService.addCharacteristic(switchCharacteristic); - switchCharacteristic.addDescriptor(switchDescriptor); - unsigned char test = 1; - switchCharacteristic.writeValue(&test,1); - BLE.advertise(); -} - -void loop() { - static int i = 0; - BLEDevice central = BLE.central(); - bool temp = central; -i++; - if (temp) { - // central connected to peripheral - Serial.print(i); - Serial.print(F("Connected to central: ")); - Serial.println(central.address()); - - Serial.print(temp); - - while (central.connected()) { - // central still connected to peripheral - if (switchCharacteristic.written()) { - char ledValue = *switchCharacteristic.value(); - // central wrote new value to characteristic, update LED - if (ledValue) { - Serial.println(F("LED on")); - digitalWrite(LED_PIN, HIGH); - } else { - Serial.println(F("LED off")); - digitalWrite(LED_PIN, LOW); - } - } - } - - // central disconnected - Serial.print(F("Disconnected from central: ")); - Serial.println(central.address()); - } - //delay (1000); -} diff --git a/libraries/CurieBLE/src/internal/BLEDeviceManager.cpp b/libraries/CurieBLE/src/internal/BLEDeviceManager.cpp index e21c40f5..5162f593 100644 --- a/libraries/CurieBLE/src/internal/BLEDeviceManager.cpp +++ b/libraries/CurieBLE/src/internal/BLEDeviceManager.cpp @@ -1062,11 +1062,12 @@ void BLEDeviceManager::handleConnectEvent(bt_conn_t *conn, uint8_t err) } else { + // Peripheral has established the connection with this Central device memset(&_wait_for_connect_peripheral, 0, sizeof(_wait_for_connect_peripheral)); _connecting = false; - // Peripheral has established the connection with this Central device - BLEProfileManager::instance()->handleConnectedEvent(bt_conn_get_dst(conn)); } + // The peripheral and central can work as GATT server. Reserve one buffer for peer device + BLEProfileManager::instance()->handleConnectedEvent(bt_conn_get_dst(conn)); if (NULL != _device_events[BLEConnected]) {