Pulse: Live Heart Rate Zones for Spin Studios

Résumé

Pixel shares Pulse, a studio template that sends members’ wearable heart rate readings to a trainer’s screen during spin classes. Built with Codename One in Java, it uses HealthKit on iOS and Health Connect on Android, with MIT-0 source studios can customize and own.

DEV Community

Pulse: Heart Rate Zones From the Watch to the Trainer's Screen

A spin class with a screen on the wall showing every rider's heart rate zone is the kind of feature studios pay a lot for. It usually means a vendor's hardware, a vendor's app and a monthly fee per location. Underneath, it's three hard integrations: reading a watch or a chest strap in real time, getting that reading off the phone fast enough to matter, and doing it on iOS and Android, which store health data in two completely different places. What is Codename One? Codename One is an open-source framework for building native iOS, Android, desktop, and web apps from a single Java or Kotlin codebase. Learn more at codenameone.com. Pulse is a studio template where that's already done, in one Java project you own the source of. The member's phone records the class, the trainer's phone shows the room. You can generate it from the Initializr as Fitness studio, under your own name and package, and the source is MIT-0. Download the trainer video. From the wrist to the wall When a member checks into a class, the app asks for permission once, then opens a workout session that collects heart rate. On iOS that's a HealthKit workout, which also brings in a paired Apple Watch; on Android it's Health Connect. It's the same code on both: Health.getInstance().getStore().requestAuthorization(
HealthAccess.write(HealthDataType.WORKOUT),
HealthAccess.read(HealthDataType.HEART_RATE),
HealthAccess.write(HealthDataType.HEART_RATE)).onResult((asked, refused) -> {
WorkoutConfiguration config = new WorkoutConfiguration()
.setActivityType(WorkoutActivityType.CYCLING)
.setTitle("Morning Spin")
.addCollectedType(HealthDataType.HEART_RATE);
Health.getInstance().getWorkouts().startSession(config).onResult((workout, failed) -> {
if (workout != null) {
workout.addListener(workoutListener);
workout.start();
pairStrap(workout);
}
});
});
Chest straps over Bluetooth Plenty of members train with a chest strap instead of a watch, and the strap is more accurate anyway. Every strap on the market speaks the standard Bluetooth Heart Rate profile, so Pulse scans for that profile, connects to the first one it finds and feeds it into the same workout session, which means the strap's beats end up in the member's health history too: HealthSensors sensors = Health.getInstance().getSensors();
sensors.startScan(new SensorScanSettings()
.addProfile(HealthSensorProfile.HEART_RATE)
.setTimeoutMillis(20000), new SensorDiscoveryListener() {
public void sensorDiscovered(HealthSensor sensor) {
SensorSessionOptions options = new SensorSessionOptions()
.setAutoReconnect(true)
.setWorkoutSession(workout);
sensors.connect(sensor, HealthSensorProfile.HEART_RATE, options)
.onResult((strap, failed) -> {
if (strap != null) {
strap.addListener(strapListener);
}
});
}

public void scanFailed(HealthException error) {
}

});
Auto reconnect matters more than it looks. A strap drops off for a second whenever someone wipes their chest, and you don't want the trainer's screen to lose them for the rest of the class. A strap reports every beat. A watch, through the platform, reports running statistics instead, so Pulse reads whichever one it has: public void sensorSample(SensorSession session, HealthSample sample) {
if (sample instanceof QuantitySample
&& HealthDataType.HEART_RATE.equals(sample.getType())) {
beat((int) Math.round(((QuantitySample) sample)
.getValue(HealthUnit.COUNT_PER_MINUTE)));
}
}

public void workoutStatisticsUpdated(WorkoutSession session, HealthDataType type) {
HealthQuantity average = session.getStatistic(HealthDataType.HEART_RATE,
AggregateMetric.AVERAGE);
if (average != null) {
beat((int) Math.round(avera...
Pulse: Live Heart Rate Zones for Spin Studios
Powered by Readybot.io

Les dernières actus de Pixel

Incident Response: Look Beyond the Red Alert

Pixel’s DEV Community announcement explores how teams can fixate on one failing service while overlooking the real cause of an outage, such as a full …

Sach: AI Fact-Checks WhatsApp Forwards in India

Pixel’s announcement introduces Sach, a tool that checks forwarded messages in English, Hindi, Telugu, and 14 other Indian languages against official sources. It gives cited …

Java 25 Removes SecurityManager: What to Fix

Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing …