17
17
#define BLINKY_MS (2000 )
18
18
19
19
/* HRM Service Definitions
20
- * Heart Rate Monitor Service: 0x180D
21
- * Heart Rate Measurement Char: 0x2A37
22
- * Body Sensor Location Char: 0x2A38
20
+ * Heart Rate Monitor Service: 0x180D
21
+ * Heart Rate Measurement Char: 0x2A37
22
+ * Body Sensor Location Char: 0x2A38
23
23
*/
24
24
BLEService hrms = BLEService(UUID16_SVC_HEART_RATE);
25
25
BLECharacteristic hrmc = BLECharacteristic(UUID16_CHR_HEART_RATE_MEASUREMENT);
@@ -74,7 +74,7 @@ void setup()
74
74
// BLEService and BLECharacteristic classes
75
75
Serial.println (" Configuring the Heart Rate Monitor Service" );
76
76
setupHRM ();
77
-
77
+
78
78
// Setup the advertising packet(s)
79
79
Serial.println (" Setting up the advertising payload(s)" );
80
80
setupAdv ();
@@ -107,12 +107,12 @@ void setupHRM(void)
107
107
// Heart Rate Measurement 0x2137 Mandatory Notify
108
108
// Body Sensor Location 0x2138 Optional Read
109
109
// Heart Rate Control Point 0x2A39 Conditional Write <-- Not used here
110
- hrms.start ();
111
-
110
+ hrms.start ();
111
+
112
112
// Note: You must start the service before calling any characteristics
113
113
// Calling .start() on a BLECharacteristic will cause it to be added to
114
114
// the last BLEService that was 'start()'ed!
115
-
115
+
116
116
// Configure the Heart Rate Measurement characteristic
117
117
// See: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.heart_rate_measurement.xml
118
118
// Permission = Notify
@@ -170,7 +170,13 @@ void loop()
170
170
171
171
// Set the characteristic to use 8-bit values, with the sensor connected and detected
172
172
uint8_t hrmdata[2 ] = { 0b00000110 , bps++ };
173
- hrmc.write (hrmdata, sizeof (hrmdata));
173
+ // Note: We use .notify instead of .write since this characteristic has
174
+ // notify as a property!
175
+ if (hrmc.notifyEnabled ()) {
176
+ hrmc.notify (hrmdata, sizeof (hrmdata));
177
+ } else {
178
+ hrmc.write (hrmdata, sizeof (hrmdata));
179
+ }
174
180
}
175
181
}
176
182
@@ -182,7 +188,7 @@ void connect_callback(void)
182
188
void disconnect_callback (uint8_t reason)
183
189
{
184
190
(void ) reason;
185
-
191
+
186
192
Serial.println (" Disconnected" );
187
- Serial.println (" Bluefruit will auto start advertising (default) " );
193
+ Serial.println (" Advertising! " );
188
194
}
0 commit comments