dawsontoth / zwifit

This NodeJS app joins Zwift with treadmills running iFit® over Wi-Fi.
MIT License
82 stars 43 forks source link

Crash when connecting with Garmin Fenix 5 #23

Open catteneo opened 4 years ago

catteneo commented 4 years ago

Description While trying to connect zwifit (connected with Proform 995i via BLE) with a Garmin Fenix 5 got a crash on the zwifit app. This would be useful to perform a Garmin Coach training plan workout.

Steps To Reproduce

  1. Connect the treadmill with Zwifit via BLE
  2. Activate the Run-Speed-Cadence profile
  3. In the watch add zwifit as a sensor
  4. Start a treadmill activity
  5. Zwifit crash

Expected behavior Should work as with zwift

Logs 0|app | Connected to Zwift (watch MAC address) 0|app | RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 3. Received 4 0|app | at boundsError (internal/buffer.js:77:9) 0|app | at Buffer.readUInt8 (internal/buffer.js:243:5) 0|app | at parseCommandHeader (/home/pi/zwifit/src/ble/ifit/_request.js:707:29) 0|app | at /home/pi/zwifit/src/ble/ifit/_request.js:166:18 0|app | at Characteristic.listener (/home/pi/zwifit/src/ble/ifit/_request.js:657:4) 0|app | at Characteristic.emit (events.js:327:22) 0|app | at Noble.onRead (/home/pi/zwifit/node_modules/noble/lib/noble.js:414:20) 0|app | at NobleBindings.emit (events.js:315:20) 0|app | at NobleBindings.onNotification (/home/pi/zwifit/node_modules/noble/lib/hci-socket/bindings.js:448:8) 0|app | at Gatt.emit (events.js:315:20) { 0|app | code: 'ERR_OUT_OF_RANGE' 0|app | }

Debug Added printing to the buffer: 0|app | writeRequestAndGatherResponse: 4 0|app | writeRequestAndGatherResponse: <Buffer 01 00 00 00>

So tried to discard packets with size <= 4 (is set to <4 only) https://github.com/dawsontoth/zwifit/blob/master/src/ble/ifit/_request.js#L698

But started to get random disconnects from treadmill as soon as the activity on the watch starts

catteneo commented 4 years ago

@RasPelikan can you give this a look?

catteneo commented 4 years ago

@dawsontoth & @RasPelikan anything?