-
-
Notifications
You must be signed in to change notification settings - Fork 284
Jira #788: BLE Peripheral cannot discover Central attributes, Git #382. #410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
libraries/CurieBLE/examples/central/CentralDouble/CentralDouble.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong example sketch name here (I think?) |
||
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 | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sketch code looks good, it's pretty readable. However I have no idea what this sketch is doing, there are not really any comments to explain it.
Can you please follow the style of our other example sketches (here is a good example: https://github.com/01org/corelibs-arduino101/blob/master/libraries/CurieIMU/examples/Accelerometer/Accelerometer.ino)
Specifically, 1) put the main part of the license at the bottom of the file, with a short 1-line reference at the top. Just copy the style of existing sketches, here. And 2), add a short comment at the top, explaining what the sketch does. Again, just copy the style of existing examples.