hypermoose / Keiser2Zwift

29 stars 6 forks source link

The console is stuck at "npm start" #1

Closed kals81 closed 3 years ago

kals81 commented 4 years ago

Hi, I have been trying to implement you solution using a raspberry pi and tried to use the on-board bluetooth as well as a second standalone bluetooth adapter.

I detect the devices , but on "npm start" , I can't seem to connect to the keiser bike. To make sure there is no interference , I have unplugged the m series converter also. Would greatly appreciate your help in resolving this issue.

Thank you, Kals pi@raspberrypi:~/code/keiser $ hcitool dev Devices: hci1 00:1A:7D:DA:71:13 hci0 00:1A:7D:DA:71:13 pi@raspberrypi:~/code/keiser $ npm start

keiser2zwift@1.0.0 start /home/pi/code/keiser node index.js

Starting [KeiserM3 starting] (node:2818) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

hypermoose commented 4 years ago

Hi there,

I would love to help. First off its very odd that both your devices have the same id. Did you make sure to stop the bluetoothd service and did you install the bluez dependencies using apt-get?

kals81 commented 4 years ago

Hi , thanks for getting back. I tried the on board bluetooth . It got stuck at npm start. Therefore, I ordered one more of the zemxte adpater in order to bypass the onboard bluetooth. So now both zemxte adapters have the same ID.

I installed the bluetooth dependencies. Will try once more.

Edit: I tried a complete flash of the OS and re-tried all the steps. Still stuck at "npm start" Would appreciate your help.

Thank you Kals

kals81 commented 4 years ago

I made some progress. After following these steps, i can now detect the bike using noble https://github.com/noble/noble#running-without-rootsudo

Still unable to broadcast the data on to other apps.

hypermoose commented 4 years ago

Thanks I will add that to the instructions. However I’m concerned that the bleno side isn’t working. Can you send me the full output of the window after npm start?

And have you tried going back to the built in Bluetooth + only one USB dongle?

kals81 commented 4 years ago

HI Gary,

Thanks for getting back I started with a fresh Raspbian install.

Here are the things I changed 1) Plug in USB bluetooth dongle after step 5. I noticed sometimes when USB was plugged in hciconfig didn't detect the on-board bluetooth. Other comment I noticed on bleno git was that bluetooth 4.1 is needed, so I think we need to use on-board bluetooth. 2) Have to do "npm install @abandonware/noble" after "npm install" in Step 7. 3) Then folllow these steps https://github.com/noble/noble#running-without-rootsudo

With above changes "npm start" works and I can connect to "kinomap" app on IPad.

I tried to then set it up to always run , but see the following errors pi@raspberrypi:~/code/keiser $ systemctl status keiser ��� keiser.service - KeiserM3 Loaded: loaded (/etc/systemd/system/keiser.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Wed 2020-09-23 20:19:07 PDT; 3s ago Process: 7218 ExecStart=/home/pi/code/keiser/run.sh (code=exited, status=127) Main PID: 7218 (code=exited, status=127)

Sep 23 20:19:07 raspberrypi systemd[1]: keiser.service: Service RestartSec=100ms expired, scheduling restart. Sep 23 20:19:07 raspberrypi systemd[1]: keiser.service: Scheduled restart job, restart counter is at 5. Sep 23 20:19:07 raspberrypi systemd[1]: Stopped KeiserM3. Sep 23 20:19:07 raspberrypi systemd[1]: keiser.service: Start request repeated too quickly. Sep 23 20:19:07 raspberrypi systemd[1]: keiser.service: Failed with result 'exit-code'. Sep 23 20:19:07 raspberrypi systemd[1]: Failed to start KeiserM3.

hypermoose commented 3 years ago

Hey @kals81 did you ever get the service working? Sorry I dropped the ball on this one. I need a bit more of the log from systemctl status keiser. Please add the -n50 parameter to show more log lines

djwasser commented 3 years ago

Hey Gary,

I just set up new Pi 4 B+ following directions and incorporating corrections as per laks81. I ended up in exactly the same place he did: I can get everything working as long as I insert the USB BLE dongle after the PI boots up. When I try to set up to always run I get the same output as kals81 -- so the situation is reproducible....

pi@raspberrypi:~/code/keiser $ systemctl status keiser ● keiser.service - KeiserM3 Loaded: loaded (/etc/systemd/system/keiser.service; disabled; vendor preset: enabled) Active: failed (Result: exit-code) since Tue 2021-01-12 19:52:43 EST; 1min 30s ago Process: 1782 ExecStart=/home/pi/code/keiser/run.sh (code=exited, status=127) Main PID: 1782 (code=exited, status=127)

Jan 12 19:52:43 raspberrypi systemd[1]: keiser.service: Service RestartSec=100ms expired, scheduling restart. Jan 12 19:52:43 raspberrypi systemd[1]: keiser.service: Scheduled restart job, restart counter is at 5. Jan 12 19:52:43 raspberrypi systemd[1]: Stopped KeiserM3. Jan 12 19:52:43 raspberrypi systemd[1]: keiser.service: Start request repeated too quickly. Jan 12 19:52:43 raspberrypi systemd[1]: keiser.service: Failed with result 'exit-code'. Jan 12 19:52:43 raspberrypi systemd[1]: Failed to start KeiserM3.

hope this helps. FYI, I added the -n50 parameter and got exactly the same output:

pi@raspberrypi:~/code/keiser $ systemctl status keiser -n50 ● keiser.service - KeiserM3 Loaded: loaded (/etc/systemd/system/keiser.service; disabled; vendor preset: enabled) Active: failed (Result: exit-code) since Tue 2021-01-12 19:52:43 EST; 12min ago Process: 1782 ExecStart=/home/pi/code/keiser/run.sh (code=exited, status=127) Main PID: 1782 (code=exited, status=127)

Jan 12 19:52:43 raspberrypi systemd[1]: keiser.service: Service RestartSec=100ms expired, scheduling restart. Jan 12 19:52:43 raspberrypi systemd[1]: keiser.service: Scheduled restart job, restart counter is at 5. Jan 12 19:52:43 raspberrypi systemd[1]: Stopped KeiserM3. Jan 12 19:52:43 raspberrypi systemd[1]: keiser.service: Start request repeated too quickly. Jan 12 19:52:43 raspberrypi systemd[1]: keiser.service: Failed with result 'exit-code'. Jan 12 19:52:43 raspberrypi systemd[1]: Failed to start KeiserM3.

djwasser commented 3 years ago

Ok, found the issue! Need to modify run.sh to use the correct path for the version of nvm installed in step 5. So /home/pi/.config/nvm/versions/node/v12.16.1/bin/node index.js

should be /home/pi/.config/nvm/versions/node/v10.22.0/bin/node index.js

Once I made that correction I ran the commands to enable and start the service.

pi@raspberrypi:~/code/keiser $ sudo systemctl enable keiser
pi@raspberrypi:~/code/keiser $ systemctl start keiser

I had to to authorize via gui at this point. Running status check looks better:

pi@raspberrypi:~/code/keiser $ systemctl status keiser ● keiser.service - KeiserM3 Loaded: loaded (/etc/systemd/system/keiser.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2021-01-12 20:17:06 EST; 5min ago Main PID: 2089 (run.sh) Tasks: 8 (limit: 2063) CGroup: /system.slice/keiser.service ├─2089 /bin/sh /home/pi/code/keiser/run.sh └─2092 /home/pi/.config/nvm/versions/node/v10.22.0/bin/node index.js

Jan 12 20:17:06 raspberrypi systemd[1]: Started KeiserM3. Jan 12 20:17:07 raspberrypi keiserm3[2089]: Starting Jan 12 20:17:07 raspberrypi keiserm3[2089]: [KeiserM3 starting] Jan 12 20:17:07 raspberrypi keiserm3[2089]: (node:2092) [DEP0005] DeprecationWarning: Buffer() is deprecated due to se Jan 12 20:17:07 raspberrypi keiserm3[2089]: [KeiserM3 stateChange] new state: poweredOn Jan 12 20:17:07 raspberrypi keiserm3[2089]: [Central] State changed to poweredOn Jan 12 20:17:07 raspberrypi keiserm3[2089]: [Central] starting scan

Still have issue on reboot due to the onboard BLE not be recognized when the USB BLE dongle is in place. But getting closer!

hypermoose commented 3 years ago

@djwasser, whoops. I'll checking a fix for that. Silly me.

Can you tell me if you did all of step 2 including moving bluetoothd to a new filename so it wont run?

djwasser commented 3 years ago

Yes, I did step 2. Had to modify mv slightly as path did not match my system. My recollection is that I execute the line below after disabling bluetooth: sudo mv /usr/lib/bluetooth/bluetoothd bluetoothd.bak

djwasser commented 3 years ago

@kals81 - it looks like reboot issue was addressed in issue "Internal BT wont work if USB-dongle is attached at boot" which is now closed. Does that workaround and the corrections detailes above address your issue here?

nealjane commented 3 years ago

@kals81 is it working with Kinomap? Had a mess with it today- it found the bike /pi connection, but all the stats are 0 - no matter how hard I pedal🤣

djwasser commented 3 years ago

@nealjane - I looked the Kinomap compatibilty website and under "Sensors" it looks like it supports both "FTMS" and "Power Sensors" BLE profiles. The Keiser2Zwift application appears to present both profiles for connection. However looking at the code, I do not think any exercise stats are provided for the FTMS profile; they only seem to be provided for the Cyclng Power profile. I would be curious if Kinomap gives you options for which BLE service to connect to. I may download it myself just to see... but that might be a few days from now!

djwasser commented 3 years ago

@nealjane - decided to try Kinomap. I was able to use it fine with Keiser2Zwift on my iPad running iOS 14.3. Both the Interactive FTMS and the Smart Power sensors worked (I was wrong in comment above - Keiser2Zwift does update FTMS exercise data via the Indoor bike data characteristic). So not sure what might have happened to you earlier today...

nealjane commented 3 years ago

@djwasser I was testing Kinomap on android- finds bike (ftms empty stats), but can find one additional sensor - so it’s not useable.

just tried it on iOS and it works just as you stated - add 2 sensors in bike settings (ftms empty). Thanks for quick reply/help- much appreciated. 👍🏻

djwasser commented 3 years ago

Back to the original topic of this issue,,,,

I recently purchased a Rapsberry PI Zero W, a USB OTG cable, one of the recommended USB Bluetooth adapters, and followed the README.md instructions. I encounterd the "console stuck at npm start" as described above. I was able to resolve it and I thought I would put the steps I followed here from start to finish in hopes that it will help others and also that someone who knows more than I might have a better approach to the overall install procedure!

Step 1: I used the 32-bit Raspbian PI Desktop image and put it on the SD card using the Rapsberry Pi Imager v1.5 running on a Windows 10 laptop. I planned to run the PI Zero headless and did not have a console cable or mini HDMI cable. So if followed the technique described here for making a headless WiFi connection using SSH from Windows (I used Windows Power Shell). It basically requires putting a couple of files on the SD card prior to inserting into the Rapsberry PI Zero. Once I had the Pi 0 up and running on my WiFi, I connected via SSH and logged in using the pi account. At that point I executed the following two commands:

pi@raspberrypi:~ $ sudo apt-get update pi@raspberrypi:~ $ sudo apt-get upgrade

and then went to dinner because it takes awhile.

Step 2: I followed this as written with the correction to the mv command that others have pointed out: sudo mv /usr/lib/bluetooth/bluetoothd bluetoothd.bak

Step 3: followed as written Step 4: followed as written; then logged out of SSH session and logged back in. Step 5: followed as written Step 6: followed as written using the suggested folder Step 7: followed as written Step 8: sudo hciconfig hci1 up failed - device not found. This is the issue that has been noted elsewhere where the Pi 0 onboad BLE UART service does not start when a USB Bluetooth dongle is present. I determined the bus and port info for the USB dongle as described at this link (https://karlcode.owtelse.com/blog/2017/01/09/disabling-usb-ports-on-linux/) and executed the following commands to get both bluetooth devices working:

echo '1-1' | sudo tee /sys/bus/usb/drivers/usb/unbind sudo systemctl start hciuart.service echo '1-1' | sudo tee /sys/bus/usb/drivers/usb/bind

and then executed the two hciconfig up commands.

Step 9: followed as written Step 10: executing the command gave the following response: pi@raspberrypi:~ $ sudo npm start sudo: npm: command not found My mistake at this point (though I did not know it at the time) was to simply execute the npm command without sudo pi@raspberrypi:~ $ npm start

The application started but hung as detailed in prior posts to this issue:

Starting
[KeiserM3 starting]
(node:2818) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

As the instructions point out below step 12, running without sudo requires granting node privileges to start/stop BLE advertising. So I executed the following:

sudo apt-get install libcap2-bin
sudo setcap cap_net_raw+eip $(eval readlink -f `which node`)

At this point npm start resulted in the application starting as expected:

pi@raspberrypi:~/code/keiser $ npm start

> keiser2zwift@1.0.0 start /home/pi/code/keiser
> node index.js

Starting
[KeiserM3 starting]
(node:30798) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[KeiserM3 stateChange] new state: poweredOn
[Central] State changed to poweredOn
[Central] starting scan

The next step was to set everything up to always run as a service. I followed steps 1 though 5 in that section and got the following after step 5:

pi@raspberrypi:~/code/keiser $ sudo systemctl start keiser
pi@raspberrypi:~/code/keiser $ systemctl status keiser
● keiser.service - KeiserM3
   Loaded: loaded (/etc/systemd/system/keiser.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2021-02-14 18:38:04 GMT; 3s ago
  Process: 31225 ExecStart=/home/pi/code/keiser/run.sh (code=exited, status=127)
 Main PID: 31225 (code=exited, status=127)

Feb 14 18:38:04 raspberrypi systemd[1]: keiser.service: Service RestartSec=100ms expired, scheduling restart.
Feb 14 18:38:04 raspberrypi systemd[1]: keiser.service: Scheduled restart job, restart counter is at 5.
Feb 14 18:38:04 raspberrypi systemd[1]: Stopped KeiserM3.
Feb 14 18:38:04 raspberrypi systemd[1]: keiser.service: Start request repeated too quickly.
Feb 14 18:38:04 raspberrypi systemd[1]: keiser.service: Failed with result 'exit-code'.
Feb 14 18:38:04 raspberrypi systemd[1]: Failed to start KeiserM3.

After a few hours I finally figured out that the path to the node binary in run.sh was not correct for my installation. The trick is to find out where node is actually installed and put that path in run.sh. The command for determing this is "whereis node":

pi@raspberrypi:~/code/keiser $ whereis node
node: /home/pi/.nvm/versions/node/v10.22.0/bin/node

Once run.sh was modified to use the path I found (node: /home/pi/.nvm/versions/node/v10.22.0/bin/node) the keiser service started fine. The final modifed run.sh that I used is below. It is modified from the one in the git repository to:

#!/bin/sh

echo '1-1' | sudo tee /sys/bus/usb/drivers/usb/unbind
sudo systemctl start hciuart.service
echo '1-1' | sudo tee /sys/bus/usb/drivers/usb/bind

hciconfig hci0 up
hciconfig hci1 up
/home/pi/.nvm/versions/node/v10.22.0/bin/node index.js 

After rebooting the Rapsberry PI Zero W the service started fine and transmitted power and cadence data from my Keiser M3i to Zwift running on a iPad with iOS version 14.4.

kals81 commented 3 years ago

Thanks @djwasser . With the change to node version as well as the modification to rc.local , I can now start up keiser service on a re-boot.

caanbesi commented 3 years ago

I'm a novice to using terminal so apologies if any of the is a little obvious.

I'm having issues setting up my Keiser2Zwift.

My setup: I have a Raspberry Pi Zero W and the following bluetooth adapter https://www.amazon.co.uk/gp/product/B06XHY5VXF/ . I initially setup the device with Raspbian Pi OS (not lite or full) using a spare screen, I'm now using VNC viewer to remote login into the Pi. Just took receipt of a new Keiser M3i bike, I'm keen to get Zwift working on it. Using an iPad with iOS 14.4.

The issue I'm having: I can replicate the steps that @djwasser has followed. I seem to encounter the same errors as @djwasser but the fixes appear to work except for sudo setcap cap_net_raw+eip $(eval readlink -f 'which node') which produces the following response Failed to set capabilities on file '/home/pi/code/keiser/which' (No such file or directory) The value of the capability argument is not permitted for a file. Or the file is not a regular (non-symlink) file I think I need to replace 'which node' with the appropriate location but it's not clear to me. pi@raspberrypi:~/code/keiser $ whereis node returns node: /home/pi/.nvm/versions/node/v10.22.0/bin/node

I've been able to run npm start and produce some metrics from the Keiser bike, but the Zwift app on the iPad doesn't see the bluetooth device.

Any help would be much appreciated! I feel like I'm close to getting this working but need someone to help troubleshoot some of the issues I'm having.

Thanks

p.s. special thanks to @hypermoose for putting this project together

djwasser commented 3 years ago

@caanbesi Possibly the quote marks around which node need to be back ticks:

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

Also, check out https://github.com/ptx2/gymnasticon It might be more straight forward to get up and running... and for a PiZeroW does not require a second bluetooth adaptor :-)

caanbesi commented 3 years ago

Thanks @djwasser for your help and the quick response. You were right, the issue with that line was the lack of back ticks.

I have since implemented your fix (link below) for ensuring both bluetooth devices are recognised at start-up. With this edit my Keiser2Zwift setup is now working!

https://github.com/hypermoose/Keiser2Zwift/issues/2

Thanks again.