Instructions below and current code do not result in working system. No timetable for a fix.
This repo is my attempt to set up a headless PI Zero W with no additional dongles that can continuously scan the proprietary M3i broadcasts and implement the BLE services for:
I blatantly appropriated some of the work other folks are doing (see hypermoose/Keiser2Zwift and ptx2/gymnasticon) and was able to implement all of the BLE services using only the single on-board PIZeroW bluetooth adapter.
What is currently working:
Note that for the Cycling Power Service and for the Cycling Speed and Cadence service, the cadence information (crank count and timestamp) is calculated from the instantaneous rpms reported by the Keiser M3i.
A side benefit of using only the on-board bluetooth adaptor is that the PiZeroW without the dongle runs fine on the power from the USB port on the back of my HDTV. So I just have the PIZeroW velcroed to the back of the TV and powered by a short USB power cable which gives me nice clean "invisible" install.
I also created a Fitness Machine Service that is currently disabled (via commments in code) because it appears that most Apps do not need it. Prior to disabling, it was verfied that for power, instantaneous cadence, and heart rate:
These installation steps are based on starting with a Raspberry PI Zero W, a blank miniSD card, and a laptop running Windows 10.
Pre-setup for headless operation and to enable SSH connection:
To configure for headless WiFi connection, create a text file named wpa_supplicant.conf and place it in the root directory of the miniSD card. Add the following text to the file:
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
scan_ssid=1
ssid="your_wifi_ssid"
psk="your_wifi_password"
}
pi@raspberrypi:~ $ sudo apt-get update
pi@raspberrypi:~ $ sudo apt-get upgrade
sudo systemctl stop bluetooth
sudo systemctl disable bluetooth
sudo mv /usr/lib/bluetooth/bluetoothd bluetoothd.bak
sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
sudo shutdown -r now
nvm install 10.22.0
sudo cp -r /home/pi/.nvm/versions/node/v10.22.0/* /usr/local/
sudo apt update
sudo apt install git
mkdir /home/pi/code
cd /home/pi/code
git clone https://github.com/djwasser/M3iPiZeroW.git
cd M3iPiZeroW
npm install
sudo hciconfig hci0 up
hcitool dev
sudo npm start
At this point, if everything is working, you can set things up to run without sudo and also install the app as a service that runs whenever the Rapsberry Pi starts up. Enter Control-C to stop the running app and execute the following commands:
sudo apt-get install libcap2-bin
sudo setcap cap_net_raw+eip $(eval readlink -f `which node`)
This enables running without sudo. To set up as a service to always run, execute the following commands:
sudo cp M3iPiZeroW.service /etc/systemd/system
sudo systemctl enable M3iPiZeroW
sudo systemctl start M3iPiZeroW
Verify the the service started:
systemctl status M3iPiZeroW
Now reboot the Raspberry Pi, connect to the console using SSH and confirm the service is running:
systemctl status M3iPiZeroW
Now pedal the Keiser and confirm you can connect to power and cadence from Zwift