@@ -122,6 +122,12 @@ bool SpinBLEClient::connectToServer()
122
122
charUUID = FITNESSMACHINEINDOORBIKEDATA_UUID;
123
123
debugDirector (" trying to connect to Fitness machine service" );
124
124
}
125
+ else if (myDevice->isAdvertisingService (ECHELON_DEVICE_UUID))
126
+ {
127
+ serviceUUID = ECHELON_SERVICE_UUID;
128
+ charUUID = ECHELON_DATA_UUID;
129
+ debugDirector (" Trying to connect to Echelon Bike" );
130
+ }
125
131
else if (myDevice->isAdvertisingService (HEARTSERVICE_UUID))
126
132
{
127
133
serviceUUID = HEARTSERVICE_UUID;
@@ -200,7 +206,7 @@ bool SpinBLEClient::connectToServer()
200
206
}
201
207
202
208
if (pRemoteCharacteristic->canNotify ())
203
- {
209
+ {
204
210
debugDirector (" Found " + String (pRemoteCharacteristic->getUUID ().toString ().c_str ()) + " on reconnect." );
205
211
reconnectTries = MAX_RECONNECT_TRIES;
206
212
// VV Is this really needed? Shouldn't it just carry over from the previous connection? VV
@@ -242,7 +248,6 @@ bool SpinBLEClient::connectToServer()
242
248
pClient->connect (myDevice->getAddress ()); // if you pass BLEAdvertisedDevice instead of address, it will be recognized type of peer device address (public or private)
243
249
debugDirector (" - Connected to server" , true );
244
250
debugDirector (" - RSSI " + pClient->getRssi (), true );
245
-
246
251
// Obtain a reference to the service we are after in the remote BLE server.
247
252
BLERemoteService *pRemoteService = pClient->getService (serviceUUID);
248
253
if (pRemoteService == nullptr )
@@ -313,7 +318,7 @@ bool SpinBLEClient::connectToServer()
313
318
314
319
void SpinBLEClient::MyClientCallback::onConnect (NimBLEClient *pClient)
315
320
{
316
- // debugDirector("Connect Called"); This callback happens so early for us it's nearly useless.
321
+ // debugDirector("Connect Called"); This callback happens so early for us it's nearly useless.
317
322
}
318
323
319
324
void SpinBLEClient::MyClientCallback::onDisconnect (NimBLEClient *pclient)
@@ -340,7 +345,7 @@ void SpinBLEClient::MyClientCallback::onDisconnect(NimBLEClient *pclient)
340
345
// spinBLEClient.myBLEDevices[i].connectedClientID = BLE_HS_CONN_HANDLE_NONE;
341
346
debugDirector (" Detected " + String (spinBLEClient.myBLEDevices [i].serviceUUID .toString ().c_str ()) + " Disconnect" );
342
347
spinBLEClient.myBLEDevices [i].doConnect = true ;
343
- if ((spinBLEClient.myBLEDevices [i].charUUID == CYCLINGPOWERMEASUREMENT_UUID) || (spinBLEClient.myBLEDevices [i].charUUID == FITNESSMACHINEINDOORBIKEDATA_UUID) || (spinBLEClient.myBLEDevices [i].charUUID == FLYWHEEL_UART_RX_UUID))
348
+ if ((spinBLEClient.myBLEDevices [i].charUUID == CYCLINGPOWERMEASUREMENT_UUID) || (spinBLEClient.myBLEDevices [i].charUUID == FITNESSMACHINEINDOORBIKEDATA_UUID) || (spinBLEClient.myBLEDevices [i].charUUID == FLYWHEEL_UART_RX_UUID) || (spinBLEClient. myBLEDevices [i]. charUUID == ECHELON_SERVICE_UUID) )
344
349
{
345
350
346
351
debugDirector (" Deregistered PM on Disconnect" );
@@ -394,7 +399,7 @@ void SpinBLEClient::MyAdvertisedDeviceCallback::onResult(BLEAdvertisedDevice *ad
394
399
{
395
400
aDevName = " " ;
396
401
}
397
- if ((advertisedDevice->haveServiceUUID ()) && (advertisedDevice->isAdvertisingService (CYCLINGPOWERSERVICE_UUID) || advertisedDevice->isAdvertisingService (FLYWHEEL_UART_SERVICE_UUID) || advertisedDevice->isAdvertisingService (FITNESSMACHINESERVICE_UUID) || advertisedDevice->isAdvertisingService (HEARTSERVICE_UUID)))
402
+ if ((advertisedDevice->haveServiceUUID ()) && (advertisedDevice->isAdvertisingService (CYCLINGPOWERSERVICE_UUID) || advertisedDevice->isAdvertisingService (FLYWHEEL_UART_SERVICE_UUID) || advertisedDevice->isAdvertisingService (FITNESSMACHINESERVICE_UUID) || advertisedDevice->isAdvertisingService (HEARTSERVICE_UUID) || advertisedDevice-> isAdvertisingService (ECHELON_DEVICE_UUID) ))
398
403
{
399
404
// if ((aDevName == c_PM) || (advertisedDevice->getAddress().toString().c_str() == c_PM) || (aDevName == c_HR) || (advertisedDevice->getAddress().toString().c_str() == c_HR) || (String(c_PM) == ("any")) || (String(c_HR) == ("any")))
400
405
// { //notice the subtle difference vv getServiceUUID(int) returns the index of the service in the list or the 0 slot if not specified.
@@ -410,7 +415,8 @@ void SpinBLEClient::MyAdvertisedDeviceCallback::onResult(BLEAdvertisedDevice *ad
410
415
{
411
416
debugDirector (" Skipping non-selected HRM |" + aDevName + " |" + String (userConfig.getconnectedHeartMonitor ()));
412
417
return ;
413
- }else if (aDevName == String (userConfig.getconnectedHeartMonitor ()))
418
+ }
419
+ else if (aDevName == String (userConfig.getconnectedHeartMonitor ()))
414
420
{
415
421
debugDirector (" HR String Matched " + aDevName);
416
422
}
@@ -426,7 +432,8 @@ void SpinBLEClient::MyAdvertisedDeviceCallback::onResult(BLEAdvertisedDevice *ad
426
432
{
427
433
debugDirector (" Skipping non-selected PM |" + aDevName + " |" + String (userConfig.getconnectedPowerMeter ()));
428
434
return ;
429
- }else if (aDevName == String (userConfig.getconnectedPowerMeter ()))
435
+ }
436
+ else if (aDevName == String (userConfig.getconnectedPowerMeter ()))
430
437
{
431
438
debugDirector (" PM String Matched " + aDevName);
432
439
}
@@ -456,6 +463,7 @@ void SpinBLEClient::scanProcess()
456
463
pBLEScan->setAdvertisedDeviceCallbacks (new MyAdvertisedDeviceCallback ());
457
464
pBLEScan->setInterval (550 );
458
465
pBLEScan->setWindow (500 );
466
+ pBLEScan->setDuplicateFilter (true );
459
467
pBLEScan->setActiveScan (true );
460
468
BLEScanResults foundDevices = pBLEScan->start (10 , false );
461
469
// Load the scan into a Json String
@@ -468,7 +476,7 @@ void SpinBLEClient::scanProcess()
468
476
for (int i = 0 ; i < count; i++)
469
477
{
470
478
BLEAdvertisedDevice d = foundDevices.getDevice (i);
471
- if (d.isAdvertisingService (CYCLINGPOWERSERVICE_UUID) || d.isAdvertisingService (HEARTSERVICE_UUID) || d.isAdvertisingService (FLYWHEEL_UART_SERVICE_UUID) || d.isAdvertisingService (FITNESSMACHINESERVICE_UUID))
479
+ if (d.isAdvertisingService (CYCLINGPOWERSERVICE_UUID) || d.isAdvertisingService (HEARTSERVICE_UUID) || d.isAdvertisingService (FLYWHEEL_UART_SERVICE_UUID) || d.isAdvertisingService (FITNESSMACHINESERVICE_UUID) || d. isAdvertisingService (ECHELON_DEVICE_UUID) )
472
480
{
473
481
device = " device " + String (i);
474
482
devices[device][" address" ] = d.getAddress ().toString ();
@@ -566,14 +574,29 @@ void SpinBLEClient::resetDevices()
566
574
567
575
void SpinBLEClient::postConnect (NimBLEClient *pClient)
568
576
{
569
- for (size_t i = 0 ; i < NUM_BLE_DEVICES; i++)
577
+ for (size_t i = 0 ; i < NUM_BLE_DEVICES; i++)
570
578
{
571
579
if (pClient->getPeerAddress () == this ->myBLEDevices [i].peerAddress )
572
580
{
573
- if ((this ->myBLEDevices [i].charUUID == CYCLINGPOWERMEASUREMENT_UUID) || (this ->myBLEDevices [i].charUUID == FITNESSMACHINEINDOORBIKEDATA_UUID) || (this ->myBLEDevices [i].charUUID == FLYWHEEL_UART_RX_UUID))
581
+ if ((this ->myBLEDevices [i].charUUID == CYCLINGPOWERMEASUREMENT_UUID) || (this ->myBLEDevices [i].charUUID == FITNESSMACHINEINDOORBIKEDATA_UUID) || (this ->myBLEDevices [i].charUUID == FLYWHEEL_UART_RX_UUID)|| ( this -> myBLEDevices [i]. charUUID == ECHELON_DATA_UUID) )
574
582
{
575
583
this ->connectedPM = true ;
576
584
debugDirector (" Registered PM on Connect" );
585
+ if (this ->myBLEDevices [i].charUUID == ECHELON_DATA_UUID)
586
+ {
587
+ NimBLERemoteCharacteristic *writeCharacteristic = pClient->getService (ECHELON_SERVICE_UUID)->getCharacteristic (ECHELON_WRITE_UUID);
588
+ if (writeCharacteristic == nullptr )
589
+ {
590
+ debugDirector (" Failed to find Echelon write characteristic UUID: " ,false );
591
+ debugDirector (String (ECHELON_WRITE_UUID.toString ().c_str ()));
592
+ pClient->disconnect ();
593
+ return ;
594
+ }
595
+ // Enable device notifications
596
+ byte message[] = {0xF0 , 0xB0 , 0x01 , 0x01 , 0xA2 };
597
+ writeCharacteristic->writeValue (message, 5 );
598
+ debugDirector (" Activated Echelon callbacks." );
599
+ }
577
600
// spinBLEClient.removeDuplicates(pclient);
578
601
return ;
579
602
}
@@ -607,7 +630,3 @@ void SpinBLEAdvertisedDevice::print()
607
630
strcat (logBufP, " |" );
608
631
debugDirector (String (logBuf));
609
632
}
610
-
611
-
612
-
613
-
0 commit comments