Skip to main content

Python library for controlling KingSmith WalkingPad treadmills over BLE (FTMS and legacy WiLink protocols)

Project description

walkingpad-controller

Python library for controlling KingSmith WalkingPad treadmills over Bluetooth Low Energy (BLE).

Supports both FTMS (Fitness Machine Service) and legacy WiLink protocols behind a unified API. Protocol is auto-detected based on the BLE device name and advertised services.

Features

  • Unified API — single WalkingPadController class for all device types
  • Auto protocol detection — FTMS for newer KS-HD-* / KS-MC21-* / KS-SMC21C-* / ZP-ZEALR1-* devices, WiLink for older models
  • Real-time status — speed, distance, duration, calories, steps via BLE notifications
  • Cold-start handling — waits for belt to start moving and stabilize before sending speed commands, avoiding BLE disconnects on KingSmith devices
  • Reconnect recovery — pending target speed is automatically re-applied after BLE reconnection
  • KingSmith vendor extensions — step counter (FTMS bit 13), MC-21 vendor pre-amble, supplement service detection
  • Firmware version — exposed via controller.firmware_version (FTMS only)

Installation

pip install walkingpad-controller

For legacy WiLink device support (older WalkingPad models):

pip install walkingpad-controller[wilink]

Quick Start

import asyncio
from bleak import BleakScanner
from walkingpad_controller import WalkingPadController

async def main():
    # Find your treadmill
    device = await BleakScanner.find_device_by_name("KS-HD-Z1D")

    # Create controller (protocol auto-detected from BLE name)
    controller = WalkingPadController(ble_device=device)

    # Connect
    await controller.connect()
    print(f"Protocol: {controller.protocol.value}")
    print(f"Speed range: {controller.min_speed}-{controller.max_speed} km/h")

    # Start the belt (runs at minimum speed)
    await controller.start()

    # Set desired speed
    await controller.set_speed(3.0)

    # Read status
    print(f"Speed: {controller.status.speed} km/h")
    print(f"Steps: {controller.status.steps}")

    # Stop and disconnect
    await controller.stop()
    await controller.disconnect()

asyncio.run(main())

Status Callbacks

Register callbacks to receive real-time status updates:

from walkingpad_controller import WalkingPadController, TreadmillStatus

def on_status(status: TreadmillStatus):
    print(f"Speed: {status.speed} km/h, Distance: {status.distance}m, "
          f"Duration: {status.duration}s, Calories: {status.calories}, "
          f"Steps: {status.steps}")

controller = WalkingPadController(ble_device=device)
controller.register_status_callback(on_status)
controller.register_disconnect_callback(lambda: print("Disconnected!"))
await controller.connect()

API Reference

WalkingPadController

The main entry point. Auto-detects protocol and delegates to the appropriate backend.

Property / Method Description
protocol Detected protocol (ProtocolType.FTMS or ProtocolType.WILINK)
connected Whether the device is currently connected
status Current TreadmillStatus
min_speed / max_speed Speed range in km/h (read from device for FTMS)
speed_increment Speed step size in km/h
firmware_version Firmware version string (FTMS only; empty otherwise)
connect() Connect and auto-detect protocol
disconnect() Disconnect from the device
start() Start the belt (runs at minimum speed)
stop() Stop the belt
set_speed(speed_kmh) Set speed (starts belt if stopped)
switch_mode(mode) Switch operating mode (WiLink: auto/manual/standby)
register_status_callback(cb) Register a TreadmillStatus callback
register_disconnect_callback(cb) Register a disconnect callback
update_ble_device(device) Update BLE device reference after rediscovery
update_state() Poll / refresh current status from the device

TreadmillStatus

Dataclass with real-time treadmill data:

Field Type Description
belt_state int 0=stopped, 1=active, 5=standby, 9=starting
speed float Current speed in km/h
mode int Operating mode (0=auto, 1=manual, 2=standby)
distance int Total distance in meters
duration int Elapsed time in seconds
steps int Step count (FTMS KingSmith extension)
calories int Total energy in kcal
calories_per_hour int Energy rate
heart_rate int Heart rate in bpm (if available)
timestamp float Unix timestamp of last update

Protocol-Specific Controllers

For advanced use, you can use the protocol controllers directly:

  • FTMSController — FTMS protocol (newer KS-HD-* devices)
  • WiLinkController — Legacy WiLink protocol (older WalkingPad models, requires [wilink] extra)

Supported Devices

FTMS Protocol (tested)

  • KingSmith KS-Z1D (BLE name: KS-HD-Z1D) — confirmed working
  • KingSmith MC-21 (BLE names: KS-MC21-*, KS-SMC21C-*, ZP-ZEALR1-*) — confirmed working as of v0.4.1, requires the vendor pre-amble described below
  • Other KingSmith devices with BLE names starting with KS-HD- are expected to work via the same FTMS / supplement-service code path

WiLink Protocol (via ph4-walkingpad)

  • WalkingPad A1, A1 Pro
  • WalkingPad C1, C2
  • Other models supported by ph4-walkingpad

Known Behavior

FTMS Cold Start

KingSmith FTMS devices require a START_OR_RESUME command before the belt will accept speed commands. The library handles this automatically: it sends START, waits for the belt to report speed > 0 via treadmill data notifications, then waits an additional stabilization period before sending SET_TARGET_SPEED. This avoids the BLE disconnects that occur when speed commands are sent too early during motor startup.

BLE Connection Drops

KingSmith FTMS devices may occasionally drop the connection after a cold start. The library stores the pending target speed and re-applies it after reconnection.

Connection Exclusivity

Only one BLE client can connect to the treadmill at a time — KS Fit and any client of this library are mutually exclusive.

MC-21 Vendor Pre-amble

The MC-21 family (KS-MC21-*, KS-SMC21C-*, ZP-ZEALR1-*) requires a vendor pre-amble before each FTMS Control Point command, and acks via Fitness Machine Status events rather than Control Point indications. The library detects this and handles it transparently. See docs/ftms-protocol-reference.md for the protocol details and docs/ks-fit-reverse-engineering.md for the analysis.

Requirements

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

walkingpad_controller-0.4.4.tar.gz (37.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

walkingpad_controller-0.4.4-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

Details for the file walkingpad_controller-0.4.4.tar.gz.

File metadata

  • Download URL: walkingpad_controller-0.4.4.tar.gz
  • Upload date:
  • Size: 37.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for walkingpad_controller-0.4.4.tar.gz
Algorithm Hash digest
SHA256 5721eb9fdaf3dad12c320b2ae4daa5d4107447f406e50f763e0df73b1fc58503
MD5 5db32e8b4931c2b79f48673fe4ca6be6
BLAKE2b-256 2628c0574371fa99f39e4dd90f8265bf0bb56080570888fb0f10600a4414b653

See more details on using hashes here.

Provenance

The following attestation bundles were made for walkingpad_controller-0.4.4.tar.gz:

Publisher: publish.yml on mcdax/walkingpad-controller

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file walkingpad_controller-0.4.4-py3-none-any.whl.

File metadata

File hashes

Hashes for walkingpad_controller-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 48a01e4a6fadd53b0ee721160c717a42ff3ff945bf52fa41093db0cc75a52c9f
MD5 db8aa087596a9c8589fd906fc91456f1
BLAKE2b-256 dc2d3285e479d4c07b5a791ddd1bbc84769243abf1f87873d40762e519017eb6

See more details on using hashes here.

Provenance

The following attestation bundles were made for walkingpad_controller-0.4.4-py3-none-any.whl:

Publisher: publish.yml on mcdax/walkingpad-controller

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page