hypermoose / Keiser2Zwift

29 stars 6 forks source link

Keiser2Zwift

Use your Keiser M3 bike with apps like Zwift without buying a converter from Keiser which never really worked for me. This project was built to use make use of a Raspberry pi with 2 bluetooth adapters. Other systems may work but your on your own to get it setup. Two bluetooth adapters are required to make this work. I use the built in one on a Raspberry Pi 3/4 or the Pi Zero W and an additional one plugged into the usb port. The steps to install are below.

USB bluetooth adapters known to work

Any one available from Amazon with linux support should work but I have tried these:

Installation

  1. Setup your Pi with Raspbian or Raspbian Lite. https://www.raspberrypi.org/downloads/
  2. Disable the default bluetooth service. Note that I actually move the file to a backup location to make sure it doesnt come back after a reboot.
    • sudo systemctl stop bluetooth
    • sudo systemctl disable bluetooth
    • sudo mv /usr/lib/bluetoothd bluetoothd.bak
  3. Install the development requirements
    • sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev
  4. Install NVVM to manager Node.js versions (Make sure to close and reopen your shell after this step)
    • curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
  5. Install the latest binary build of Node.js to support Pis (anything newer and your need to spend a lot time with building it)
    • nvm install 10.22.0
  6. Download this repo or clone it locally. I put it in a directory off the home folder for pi called /home/pi/code/keiser
  7. Go to that directory and run
    • npm install
  8. Make sure both bluetooth adapters are connected and issues the following two commands
    • sudo hciconfig hci0 up
    • sudo hciconfig hci1 up
  9. Verify that you see two devices when you run:
    • hcitool dev
  10. Start this project manually as root. You should see log messages that indicate its looking for an M3i.
    • sudo npm start
  11. Wake up your bike and do a few revolutions of the pedals. You should see log messages indicating that its connected to that bike
  12. Launch Zwift and connect to the Power meter whose name starts with KeiserM3-. Then connect to the Cadence sensor. Enjoy

Running without root/sudo

Run the following command:

sudo setcap cap_net_raw+eip $(eval readlink -f `which node`)

This grants the node binary cap_net_raw privileges, so it can start/stop BLE advertising.

Note: The above command requires setcap to be installed, it can be installed using the following:

Setting up to always run

You can setup the program to run at Pi boot time by doing the following steps:

  1. Edit the keiser.service file in the root of this project to change the path if you didnt take my suggestion.
  2. Copy the service definition into the correct location
    • sudo cp keiser.service /etc/systemd/system
  3. Enable the service
    • sudo systemctl enable keiser
  4. Start the service (Make sure you aren't still manually running the project using npm)
    • sudo systemctl start keiser
  5. Verify it started
    • systemctl status keiser
  6. Reboot the system and verify that the service started automatically using step 5

Issues with USB adapters at system boot

Several people have reported issues at system boot with both adapters being recognized. A known work around by @djwasser is described in issue: https://github.com/hypermoose/Keiser2Zwift/issues/2

Thanks

I leveraged several other great projects to build this. They are: