Open Fitness Protocol

Add OFP to your app

One library reads every device in the registry: heart rate straps, power meters, FTMS bikes, rowers and treadmills, and the devices the community adds. You wire four hooks to your app's own Bluetooth once. New devices come with a version bump.

npm install @openfitnessprotocol/ofp

No dependencies · Apache-2.0 · reading only, never control · npm · GitHub

The four hooks

Start OFP
with the services your app already reads. OFP leaves those to you.
Every advertisement in
from your scanner, before your own filtering.
Devices and values out
into your device list and your screens, by field name.
The rider's choice
use(id) and release(id).

Electron or Node

// main process (Node). npm install @openfitnessprotocol/ofp @abandonware/noble
import { readFileSync } from 'node:fs'
import { createRequire } from 'node:module'
import noble from '@abandonware/noble'
import { Ofp, wasmEngine } from '@openfitnessprotocol/ofp'
import { advertisementFrom } from '@openfitnessprotocol/ofp/adapters/noble'

const require = createRequire(import.meta.url)
const file = (p) => readFileSync(require.resolve('@openfitnessprotocol/ofp/' + p))

const ofp = new Ofp({
  engine: wasmEngine(file('core/ofp_core.wasm')),
  bundle: file('registry.bundle.json').toString(),
  iRead: ['180d', '1818', '1816', '1826'],   // the services your app reads itself: OFP leaves them to you
  on: {
    device: (d) => addToDeviceList(d),       // a device OFP recognised: { id, name, fields }
    values: (v) => show(v.basic, v.fields),  // basic = { power, cadence, speed, heartRate }
    inUse: (id) => markConnected(id),
    lost: (id) => markDisconnected(id),
  },
})

noble.on('discover', (p) => {               // every advertisement, before your own filtering
  const a = advertisementFrom(p)
  if (a) ofp.advertisement(a)
})

// the rider picks a device: ofp.use(id) · lets it go: ofp.release(id)

React Native

// React Native. npm install @openfitnessprotocol/ofp react-native-ble-manager
import { Platform } from 'react-native'
import BleManager from 'react-native-ble-manager'
import { Ofp, moduleEngine, companyIdsOf } from '@openfitnessprotocol/ofp'
import * as core from '@openfitnessprotocol/ofp/core/js'   // Hermes has no WebAssembly
import bundle from '@openfitnessprotocol/ofp/registry'
import { advertisementsFrom, scanOptionsFor } from '@openfitnessprotocol/ofp/adapters/react-native-ble-manager'

const companyIds = companyIdsOf(bundle)
const ofp = new Ofp({
  engine: moduleEngine(core),
  bundle,
  iRead: ['180d', '1818', '1816', '1826'],
  on: { device: addToDeviceList, values: (v) => show(v.basic, v.fields), inUse: markConnected, lost: markDisconnected },
})

BleManager.onDiscoverPeripheral((p) => {
  for (const a of advertisementsFrom(p, companyIds)) ofp.advertisement(a)
})

// scan with OFP's extra options so broadcast-only devices get through your service filter:
BleManager.scan({ serviceUUIDs: myServices, seconds: 30, ...scanOptionsFor({ companyIds }, ofp.scanNeed(), undefined, Platform.OS) })

Broadcast-only devices (like the Keiser M3i) send their data in the advertisement, so keep the scan running while one is in use: ofp.scanNeed() says when.

Let an AI assistant wire it

The integration guide has the four hooks in detail, two complete reference integrations (Electron with noble, React Native with react-native-ble-manager), and a prompt to give your assistant. Most apps need one new file.

What you get

Values by name

v.basic has power, cadence, speed and heart rate for every app. v.fields has everything else a device sends (gear, temperature, breathing, RR intervals), each described once with its unit and range, so you can show a field you have never heard of.

New devices without code

A device is a small data file, checked against a real recording before it ships. A new one reaches your app when you update the package.

Your app stays in charge

OFP has no Bluetooth of its own and never writes to a trainer. It reads what your scanner hears, and leaves every service you read yourself to you.