Skip to content

Commit a03fa3c

Browse files
sandeepmistrysys_maker
authored and
sys_maker
committed
Fix and simplify SensorTag button example
1 parent f4a1880 commit a03fa3c

File tree

1 file changed

+10
-49
lines changed

1 file changed

+10
-49
lines changed

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

+10-49
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,6 @@
1515

1616
#include <CurieBLE.h>
1717

18-
const int NUM_OF_SERVICE = 10;
19-
20-
char *serviceUUIDArray[NUM_OF_SERVICE] =
21-
22-
// These are the various services that are included in the CC2650 Sensor Tag
23-
// If you uncomment them you can see the various services
24-
{ //"f000aa00-0451-4000-b000-000000000000",
25-
// "f000aa20-0451-4000-b000-000000000000",
26-
// "f000aa40-0451-4000-b000-000000000000",
27-
// "f000aa70-0451-4000-b000-000000000000",
28-
// "f000aa80-0451-4000-b000-000000000000",
29-
// "f000aa64-0451-4000-b000-000000000000",
30-
// "f000ac00-0451-4000-b000-000000000000",
31-
// "f000ccc0-0451-4000-b000-000000000000",
32-
// "f000ffc0-0451-4000-b000-000000000000",
33-
"0000ffe0-0000-1000-8000-00805f9b34fb"
34-
};
35-
3618
void setup() {
3719
Serial.begin(9600);
3820
while (!Serial);
@@ -77,10 +59,7 @@ void loop() {
7759
* Use a central app that can display the BT MAC address
7860
* ******************************************************
7961
*/
80-
81-
if (peripheral.address() == "24:71:89:07:27:80")
82-
83-
{
62+
if (peripheral.address() == "68:C9:0B:06:BC:81") {
8463
// stop scanning
8564
BLE.stopScan();
8665

@@ -94,9 +73,6 @@ void loop() {
9473

9574
void monitorSensorTagButtons(BLEDevice peripheral)
9675
{
97-
static bool getAllServices = true;
98-
static int serviceIndx = 0;
99-
10076
// connect to the peripheral
10177
Serial.println("Connecting ...");
10278
if (peripheral.connect()) {
@@ -106,34 +82,18 @@ void monitorSensorTagButtons(BLEDevice peripheral)
10682
return;
10783
}
10884

109-
if (getAllServices) {
110-
// discover peripheral attributes
111-
Serial.println("Discovering attributes ...");
112-
if (peripheral.discoverAttributes()) {
113-
Serial.println("Attributes discovered");
114-
} else {
115-
getAllServices = false;
116-
Serial.println("Attribute discovery failed.");
117-
peripheral.disconnect();
118-
return;
119-
}
85+
// discover peripheral attributes
86+
Serial.println("Discovering attributes of service 0xffe0 ...");
87+
if (peripheral.discoverAttributesByService("ffe0")) {
88+
Serial.println("Attributes discovered");
12089
} else {
121-
int tmp = serviceIndx;
122-
Serial.print("Discovering Service: ");
123-
Serial.println(serviceUUIDArray[tmp]);
124-
if (++serviceIndx >= NUM_OF_SERVICE)
125-
serviceIndx = 0;
126-
if (peripheral.discoverAttributesByService(serviceUUIDArray[tmp]) == false) {
127-
Serial.println("Can't find the Service.");
128-
peripheral.disconnect();
129-
return;
130-
} else {
131-
Serial.println("Service discovered.");
132-
}
90+
Serial.println("Attribute discovery failed.");
91+
peripheral.disconnect();
92+
return;
13393
}
13494

13595
// retrieve the simple key characteristic
136-
BLECharacteristic simpleKeyCharacteristic = peripheral.characteristic("0000ffe1-0000-1000-8000-00805f9b34fb");
96+
BLECharacteristic simpleKeyCharacteristic = peripheral.characteristic("ffe1");
13797

13898
// subscribe to the simple key characteristic
13999
Serial.println("Subscribing to simple key characteristic ...");
@@ -174,6 +134,7 @@ void monitorSensorTagButtons(BLEDevice peripheral)
174134
}
175135
}
176136

137+
Serial.println("SensorTag disconnected!");
177138
}
178139

179140

0 commit comments

Comments
 (0)