Connexion to a Home made bike powermeter

Hi,

Sorry if my question is naive or simple.

I just built a home made bike powermeter using arduino nano sense and 4 strain gauges. It can measure the power and the cadence. Now, I am looking for an application to collect the data via BLE or ANT+ through my phone or my sport watch.

BLE and phone : I used PhyPhox application and it works well. However, the data are not saved automatically and analyzed as I would be with garmin connect.

That's why I would prefer using my Garmin Fenix 6 (and Garmin Connect) to see, analyze and save the data.

This watch can connect to a sensor via BLE or ANT+. It seems to me that BLE connection is simple (maybe I am wrong).

I want to code the arduino so that it can send the data via BLE to the Garmin Fenix 6. 

I used (see arduino code below) powerMeterService ("1818") and powerMeasurementChar ("2A63"). It works weel: the watch can find the BLE radio signal corresponding to a bike powermeter (Cycling Power Service). This is confirmed by "nrf connect" or the "BleScan" application found in Connect IQ.

However, if I try to connect the watch to the sensor (click "connect"), then the connexion is not possible and cannot read the data.

I guess that either I need to include a specific code for final pairing or either I need to format the data the right way so that the watch can read them (power and cadence, or only power). Maybe also the data should be sent with a specific rate like 4 Hz or whatever?

Here is my arduino (c++) code below.

Thanks for any help.

------------------------------------------------------------------------------------

#include <ArduinoBLE.h>
const char* localName = "PowerMeter";
BLEService powerMeterService("1818");
BLECharacteristic powerMeasurementChar("2A63", BLERead | BLENotify, 8); // 8 octets pour la mesure de puissance
void setup() {
  Serial.begin(9600);

  if (!BLE.begin()) {
    Serial.println("Impossible d'initialiser le module BLE !");
    while (1);
  }

  Serial.println("Module BLE initialisé.");
 
  BLE.setLocalName(localName);
  BLE.setAdvertisedService(powerMeterService);
  powerMeterService.addCharacteristic(powerMeasurementChar);
  BLE.addService(powerMeterService);

  uint8_t initialValue[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  powerMeasurementChar.writeValue(initialValue, sizeof(initialValue));

  BLE.advertise();
  Serial.println("Périphérique BLE en diffusion avec le nom : " + String(localName));
}

void loop() {
  BLEDevice central = BLE.central();

  if (central) {
    Serial.print("Appareil connecté : ");
    Serial.println(central.address());

    while (central.connected()) {
      // Simulate power and cadence
      int16_t simulatedPower = random(100, 301);
      int16_t simulatedCadence = random(60, 91);

      // Prepare data with a specific format
      uint8_t powerData[8] = {0x02, 0x00}; // Flags : 0x02 means cadence included
     
      // Power (2 octets)
      powerData[2] = lowByte(simulatedPower); // Power (LSB)
      powerData[3] = highByte(simulatedPower); // Power (MSB)
     
      // Cadence (2 octets)
      powerData[4] = lowByte(simulatedCadence); // Cadence (LSB)
      powerData[5] = highByte(simulatedCadence); // Cadence (MSB)

      // 2 octets fixed to zero
      powerData[6] = 0x00;
      powerData[7] = 0x00;

      powerMeasurementChar.writeValue(powerData, sizeof(powerData));
     
      Serial.print("Puissance simulée envoyée : ");
      Serial.print(simulatedPower);
      Serial.print(" W, Cadence : ");
      Serial.print(simulatedCadence);
      Serial.println(" RPM");

      delay(1000);
    }

    // Si le périphérique se déconnecte
    Serial.print("Appareil déconnecté : ");
    Serial.println(central.address());
  }
}