Skip to content

Commit

Permalink
Merge pull request #557 from doudar/wahoo-fix
Browse files Browse the repository at this point in the history
Wahoo fix
  • Loading branch information
doudar authored Jul 9, 2024
2 parents 6b518dd + 220123b commit 8e8a235
Show file tree
Hide file tree
Showing 26 changed files with 804 additions and 825 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added more robust activity monitoring and reboot every 30 minutes if there is no activity.
- Updated all references of SmartSkin2K to SmartSpin2k for consistency.
- Fixed bug where BT scanner "Loading" wouldn't disappear if "NONE" and "NONE" were selected.
- Fixed Bug where ERG setpoint state wasn't going to the positive control loop correctly.
- Fixed Bug where ERG setpoint state wasn't going to the positive control loop correctly.
- Refactored BLE_Server into separate files for each BLE Service.
- Fixed bug in CPS service for Wahoo app (and probably others).
- Depreciated the SPIFFS->LittleFS upgrader.

### Hardware
- added Yesoul S3.
Expand Down
6 changes: 0 additions & 6 deletions data/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,6 @@ <h2>
class="slider"></span></label>
</td>
</tr>
<tr>
<td>
<p class="tooltip">Enable BLE RX Logging<span class="tooltiptext">Enable logging BLE RX messages.
Uses lots of bandwidth.</span></p>
</td>
</tr>
</tbody>
</table>
<input type="submit" value="Save Settings" />
Expand Down
37 changes: 10 additions & 27 deletions include/BLE_Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <memory>
#include <NimBLEDevice.h>
#include <Arduino.h>
#include <queue>
#include <deque>
#include "Main.h"
#include "BLE_Definitions.h"

Expand Down Expand Up @@ -50,25 +52,11 @@ class MyCallbacks : public NimBLECharacteristicCallbacks {
void onSubscribe(NimBLECharacteristic *pCharacteristic, ble_gap_conn_desc *desc, uint16_t subValue);
};

class ss2kCustomCharacteristicCallbacks : public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *);
void onSubscribe(NimBLECharacteristic *pCharacteristic, ble_gap_conn_desc *desc, uint16_t subValue);
};

class ss2kCustomCharacteristic {
public:
// Used internally for notify and onWrite Callback.
static void process(std::string rxValue);
// Custom Characteristic value that needs to be notified
static void notify(char _item);
// Notify any changed value in userConfig
static void parseNemit();
};

extern std::string FTMSWrite;

// TODO add the rest of the server to this class
class SpinBLEServer {
private:
void updateWheelAndCrankRev();

public:
struct {
bool Heartrate : 1;
Expand All @@ -79,25 +67,20 @@ class SpinBLEServer {
NimBLEServer *pServer = nullptr;
void setClientSubscribed(NimBLEUUID pUUID, bool subscribe);
void notifyShift();

double calculateSpeed();
void update();
// Queue to store writes to any of the callbacks to the server
std::queue<std::string> writeCache;
SpinBLEServer() { memset(&clientSubscribed, 0, sizeof(clientSubscribed)); }
};

extern SpinBLEServer spinBLEServer;

void startBLEServer();
bool spinDown();
void logCharacteristic(char *buffer, const size_t bufferCapacity, const byte *data, const size_t dataLength, const NimBLEUUID serviceUUID, const NimBLEUUID charUUID,
const char *format, ...);
void updateWheelAndCrankRev();
void updateIndoorBikeDataChar();
void updateCyclingPowerMeasurementChar();
void updateCyclingSpeedCadenceChar();
void calculateInstPwrFromHR();
void updateHeartRateMeasurementChar();
int connectedClientCount();
void controlPointIndicate();
void processFTMSWrite();

// BLE FIRMWARE UPDATER
void BLEFirmwareSetup();
Expand Down Expand Up @@ -128,7 +111,7 @@ class SpinBLEAdvertisedDevice {

public: // eventually these should be made private
// // TODO: Do we dispose of this object? Is so, we need to de-allocate the queue.
// // This distructor was called too early and the queue was deleted out from
// // This destructor was called too early and the queue was deleted out from
// // under us.
// ~SpinBLEAdvertisedDevice() {
// if (dataBuffer != nullptr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

#pragma once

#include <NimBLEDevice.h>
#include "BLE_Common.h"

// Codes
const uint8_t cc_read = 0x01; // value to request read operation
const uint8_t cc_write = 0x02; // Value to request write operation
Expand Down Expand Up @@ -51,3 +54,25 @@ const uint8_t BLE_maxBrakeWatts = 0x22; // "" Maximum watts for the oth
const uint8_t BLE_restartBLE = 0x23; // Closes all connections to the BLE client - used to connect new BLE devices the user selects.
const uint8_t BLE_scanBLE = 0x24; // Scan for new BLE devices
const uint8_t BLE_firmwareVer = 0x25; // String of the current firmware version

class BLE_ss2kCustomCharacteristic {
public:
void setupService(NimBLEServer *pServer);
void update();
// Used internally for notify and onWrite Callback.
static void process(std::string rxValue);
// Custom Characteristic value that needs to be notified
static void notify(char _item);
// Notify any changed value in userConfig
static void parseNemit();

private:
BLEService *pSmartSpin2kService;
BLECharacteristic *smartSpin2kCharacteristic;
uint8_t ss2kCustomCharacteristicValue[3] = {0x00, 0x00, 0x00};
};

class ss2kCustomCharacteristicCallbacks : public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *);
void onSubscribe(NimBLECharacteristic *pCharacteristic, ble_gap_conn_desc *desc, uint16_t subValue);
};
24 changes: 24 additions & 0 deletions include/BLE_Cycling_Power_Service.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2020 Anthony Doud & Joel Baranick
* All rights reserved
*
* SPDX-License-Identifier: GPL-2.0-only
*/

#pragma once

#include <NimBLEDevice.h>
#include "BLE_Common.h"

class BLE_Cycling_Power_Service {
public:
BLE_Cycling_Power_Service();
void setupService(NimBLEServer *pServer, MyCallbacks *chrCallbacks);
void update();

private:
BLEService *pPowerMonitor;
BLECharacteristic *cyclingPowerMeasurementCharacteristic;
BLECharacteristic *cyclingPowerFeatureCharacteristic;
BLECharacteristic *sensorLocationCharacteristic;
};
24 changes: 24 additions & 0 deletions include/BLE_Cycling_Speed_Cadence.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2020 Anthony Doud & Joel Baranick
* All rights reserved
*
* SPDX-License-Identifier: GPL-2.0-only
*/

#pragma once

#include <NimBLEDevice.h>
#include "BLE_Common.h"

class BLE_Cycling_Speed_Cadence {
public:
BLE_Cycling_Speed_Cadence();
void setupService(NimBLEServer *pServer, MyCallbacks *chrCallbacks);
void update();

private:
BLEService *pCyclingSpeedCadenceService;
BLECharacteristic *cscMeasurement;
BLECharacteristic *cscFeature;
BLECharacteristic *cscControlPoint;
};
18 changes: 9 additions & 9 deletions include/BLE_Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,6 @@ class CyclingPowerMeasurement {
data.push_back(static_cast<uint8_t>(instantaneousPower & 0xFF));
data.push_back(static_cast<uint8_t>((instantaneousPower >> 8) & 0xFF));

// Conditional fields based on flags
if (flags.crankRevolutionDataPresent) {
// Add crank revolution data if present
data.push_back(static_cast<uint8_t>(cumulativeCrankRevolutions & 0xFF));
data.push_back(static_cast<uint8_t>((cumulativeCrankRevolutions >> 8) & 0xFF));

data.push_back(static_cast<uint8_t>(lastCrankEventTime & 0xFF));
data.push_back(static_cast<uint8_t>((lastCrankEventTime >> 8) & 0xFF));
}
// Conditional fields based on flags
if (flags.wheelRevolutionDataPresent) {
// Add wheel revolution data if present
Expand All @@ -251,6 +242,15 @@ class CyclingPowerMeasurement {
data.push_back(static_cast<uint8_t>(lastWheelEventTime & 0xFF));
data.push_back(static_cast<uint8_t>((lastWheelEventTime >> 8) & 0xFF));
}
// Conditional fields based on flags
if (flags.crankRevolutionDataPresent) {
// Add crank revolution data if present
data.push_back(static_cast<uint8_t>(cumulativeCrankRevolutions & 0xFF));
data.push_back(static_cast<uint8_t>((cumulativeCrankRevolutions >> 8) & 0xFF));

data.push_back(static_cast<uint8_t>(lastCrankEventTime & 0xFF));
data.push_back(static_cast<uint8_t>((lastCrankEventTime >> 8) & 0xFF));
}

return data;
}
Expand Down
32 changes: 32 additions & 0 deletions include/BLE_Fitness_Machine_Service.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2020 Anthony Doud & Joel Baranick
* All rights reserved
*
* SPDX-License-Identifier: GPL-2.0-only
*/

#pragma once

#include <NimBLEDevice.h>
#include "BLE_Common.h"

class BLE_Fitness_Machine_Service {
public:
BLE_Fitness_Machine_Service();
void setupService(NimBLEServer *pServer, MyCallbacks *chrCallbacks);
void update();

private:
BLEService *pFitnessMachineService;
BLECharacteristic *fitnessMachineFeature;
BLECharacteristic *fitnessMachineIndoorBikeData;
BLECharacteristic *fitnessMachineStatusCharacteristic;
BLECharacteristic *fitnessMachineControlPoint;
BLECharacteristic *fitnessMachineResistanceLevelRange;
BLECharacteristic *fitnessMachinePowerRange;
BLECharacteristic *fitnessMachineInclinationRange;
BLECharacteristic *fitnessMachineTrainingStatus;
uint8_t ftmsIndoorBikeData[11] = {0};
bool spinDown();
void processFTMSWrite();
};
22 changes: 22 additions & 0 deletions include/BLE_Heart_Service.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2020 Anthony Doud & Joel Baranick
* All rights reserved
*
* SPDX-License-Identifier: GPL-2.0-only
*/

#pragma once

#include <NimBLEDevice.h>
#include "BLE_Common.h"

class BLE_Heart_Service {
public:
BLE_Heart_Service();
void setupService(NimBLEServer *pServer, MyCallbacks *chrCallbacks);
void update();

private:
BLEService *pHeartService;
BLECharacteristic *heartRateMeasurementCharacteristic;
};
25 changes: 0 additions & 25 deletions include/LittleFS_Upgrade.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "HTTP_Server_Basic.h"
#include "SmartSpin_parameters.h"
#include "BLE_Common.h"
#include "LittleFS_Upgrade.h"
//#include "LittleFS_Upgrade.h"
#include "boards.h"
#include "SensorCollector.h"
#include "SS2KLog.h"
Expand Down
66 changes: 32 additions & 34 deletions include/cert.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,43 @@
* SPDX-License-Identifier: GPL-2.0-only
*/

/*
/*
* To update, search for ROOT CA Certificate used by raw.githubusercontent.com (Digicert)
* Sourced from: https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt
* Worth pointing out that this is likely better to source direct from the source:
* Worth pointing out that this is likely better to source direct from the source:
* https://curl.se/docs/caextract.html - needs conversion to .crt to be text editor readable.
*/


#pragma once

// certificate for https://raw.githubusercontent.com
// DigiCert Global Root G2, valid until Sat Mar 29 2031, size: 1720 bytes
const char* rootCACertificate = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIEyDCCA7CgAwIBAgIQDPW9BitWAvR6uFAsI8zwZjANBgkqhkiG9w0BAQsFADBh\n" \
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" \
"d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBH\n" \
"MjAeFw0yMTAzMzAwMDAwMDBaFw0zMTAzMjkyMzU5NTlaMFkxCzAJBgNVBAYTAlVT\n" \
"MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxMzAxBgNVBAMTKkRpZ2lDZXJ0IEdsb2Jh\n" \
"bCBHMiBUTFMgUlNBIFNIQTI1NiAyMDIwIENBMTCCASIwDQYJKoZIhvcNAQEBBQAD\n" \
"ggEPADCCAQoCggEBAMz3EGJPprtjb+2QUlbFbSd7ehJWivH0+dbn4Y+9lavyYEEV\n" \
"cNsSAPonCrVXOFt9slGTcZUOakGUWzUb+nv6u8W+JDD+Vu/E832X4xT1FE3LpxDy\n" \
"FuqrIvAxIhFhaZAmunjZlx/jfWardUSVc8is/+9dCopZQ+GssjoP80j812s3wWPc\n" \
"3kbW20X+fSP9kOhRBx5Ro1/tSUZUfyyIxfQTnJcVPAPooTncaQwywa8WV0yUR0J8\n" \
"osicfebUTVSvQpmowQTCd5zWSOTOEeAqgJnwQ3DPP3Zr0UxJqyRewg2C/Uaoq2yT\n" \
"zGJSQnWS+Jr6Xl6ysGHlHx+5fwmY6D36g39HaaECAwEAAaOCAYIwggF+MBIGA1Ud\n" \
"EwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFHSFgMBmx9833s+9KTeqAx2+7c0XMB8G\n" \
"A1UdIwQYMBaAFE4iVCAYlebjbuYP+vq5Eu0GF485MA4GA1UdDwEB/wQEAwIBhjAd\n" \
"BgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwdgYIKwYBBQUHAQEEajBoMCQG\n" \
"CCsGAQUFBzABhhhodHRwOi8vb2NzcC5kaWdpY2VydC5jb20wQAYIKwYBBQUHMAKG\n" \
"NGh0dHA6Ly9jYWNlcnRzLmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEdsb2JhbFJvb3RH\n" \
"Mi5jcnQwQgYDVR0fBDswOTA3oDWgM4YxaHR0cDovL2NybDMuZGlnaWNlcnQuY29t\n" \
"L0RpZ2lDZXJ0R2xvYmFsUm9vdEcyLmNybDA9BgNVHSAENjA0MAsGCWCGSAGG/WwC\n" \
"ATAHBgVngQwBATAIBgZngQwBAgEwCAYGZ4EMAQICMAgGBmeBDAECAzANBgkqhkiG\n" \
"9w0BAQsFAAOCAQEAkPFwyyiXaZd8dP3A+iZ7U6utzWX9upwGnIrXWkOH7U1MVl+t\n" \
"wcW1BSAuWdH/SvWgKtiwla3JLko716f2b4gp/DA/JIS7w7d7kwcsr4drdjPtAFVS\n" \
"slme5LnQ89/nD/7d+MS5EHKBCQRfz5eeLjJ1js+aWNJXMX43AYGyZm0pGrFmCW3R\n" \
"bpD0ufovARTFXFZkAdl9h6g4U5+LXUZtXMYnhIHUfoyMo5tS58aI7Dd8KvvwVVo4\n" \
"chDYABPPTHPbqjc1qCmBaZx2vN4Ye5DUys/vZwP9BFohFrH/6j/f3IL16/RZkiMN\n" \
"JCqVJUzKoZHm1Lesh3Sz8W2jmdv51b2EQJ8HmA==\n" \
"-----END CERTIFICATE-----\n" \
"";
// DigiCert Global Root G2, valid until Sat Mar 29 2031, size: 1720 bytes
const char* rootCACertificate =
"-----BEGIN CERTIFICATE-----\n"
"MIIEyDCCA7CgAwIBAgIQDPW9BitWAvR6uFAsI8zwZjANBgkqhkiG9w0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