@@ -200,11 +200,35 @@ void loop()
200
200
if (blinkyms+BLINKY_MS < millis ()) {
201
201
blinkyms = millis ();
202
202
digitalToggle (STATUS_LED);
203
+ }
203
204
204
- // Set the characteristic to use 8-bit values, with the sensor connected and detected
205
- // Note: We use .notify instead of .write since this characteristic has
206
- // notify as a property!
207
- uint8_t hrmdata[2 ] = { 0b00000110 , bps++ };
208
- hrmc.notify (hrmdata, sizeof (hrmdata));
205
+ // Update the HRM value periodically
206
+ if (blinkyms+BLINKY_MS < millis ()) {
207
+ // Make sure we are connected to a Central device!
208
+ if (Bluefruit.connected ()) {
209
+ // Update the value of the notify characteristic
210
+ uint8_t hrmdata[2 ] = { 0b00000110 , bps++ }; // Connected, increment BPS value
211
+ err_t resp = hrmc.notify (hrmdata, sizeof (hrmdata)); // Note: We use .notify instead of .write!
212
+
213
+ // Check the results of the attempt to update the notify characteristic
214
+ switch (resp) {
215
+ case ERROR_NONE:
216
+ // Value was written correctly!
217
+ Serial.print (" Heart Rate Measurement updated to: " );
218
+ Serial.println (bps);
219
+ break ;
220
+ case NRF_ERROR_INVALID_PARAM:
221
+ // Characteristic property not set to 'Notify'
222
+ Serial.println (" Error: Characteristic 'Property' not set to Notify!" );
223
+ break ;
224
+ case NRF_ERROR_INVALID_STATE:
225
+ // Notify bit not set in the CCCD by the Central device
226
+ Serial.println (" Warning: Notify not enabled in the CCCD!" );
227
+ break ;
228
+ default :
229
+ Serial.print (" Error: Ox" ); Serial.println (resp, HEX);
230
+ break ;
231
+ }
232
+ }
209
233
}
210
234
}
0 commit comments