15
15
16
16
#include < CurieBLE.h>
17
17
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
-
36
18
void setup () {
37
19
Serial.begin (9600 );
38
20
while (!Serial);
@@ -77,10 +59,7 @@ void loop() {
77
59
* Use a central app that can display the BT MAC address
78
60
* ******************************************************
79
61
*/
80
-
81
- if (peripheral.address () == " 24:71:89:07:27:80" )
82
-
83
- {
62
+ if (peripheral.address () == " 68:C9:0B:06:BC:81" ) {
84
63
// stop scanning
85
64
BLE.stopScan ();
86
65
@@ -94,9 +73,6 @@ void loop() {
94
73
95
74
void monitorSensorTagButtons (BLEDevice peripheral)
96
75
{
97
- static bool getAllServices = true ;
98
- static int serviceIndx = 0 ;
99
-
100
76
// connect to the peripheral
101
77
Serial.println (" Connecting ..." );
102
78
if (peripheral.connect ()) {
@@ -106,34 +82,18 @@ void monitorSensorTagButtons(BLEDevice peripheral)
106
82
return ;
107
83
}
108
84
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" );
120
89
} 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 ;
133
93
}
134
94
135
95
// retrieve the simple key characteristic
136
- BLECharacteristic simpleKeyCharacteristic = peripheral.characteristic (" 0000ffe1-0000-1000-8000-00805f9b34fb " );
96
+ BLECharacteristic simpleKeyCharacteristic = peripheral.characteristic (" ffe1 " );
137
97
138
98
// subscribe to the simple key characteristic
139
99
Serial.println (" Subscribing to simple key characteristic ..." );
@@ -174,6 +134,7 @@ void monitorSensorTagButtons(BLEDevice peripheral)
174
134
}
175
135
}
176
136
137
+ Serial.println (" SensorTag disconnected!" );
177
138
}
178
139
179
140
0 commit comments