ptx2 / gymnasticon

Make obsolete and/or proprietary exercise bikes work with popular cycling training apps like Zwift, TrainerRoad, Rouvy and more.
https://ptx2.net/posts/unbricking-a-bike-with-a-raspberry-pi
MIT License
297 stars 38 forks source link

noble interface should be hardened. #55

Open jeremydk opened 3 years ago

jeremydk commented 3 years ago

I had a client device (ios) disconnect and reconnect while Gymnasticon was actively sending bike data.

Feb 20 02:19:31 gymnasticon gymnasticon[1625]: [2021-02-20T07:19:31.578Z] received stats from bike [power=62W cadence=85rpm]
Feb 20 02:19:31 gymnasticon gymnasticon[1625]: noble warning: unknown handle 64 disconnected!
Feb 20 02:19:31 gymnasticon gymnasticon[1625]: noble: unknown peripheral 742558933534 connected!
Feb 20 02:19:31 gymnasticon gymnasticon[1625]: [2021-02-20T07:19:31.761Z] received stats from bike [power=62W cadence=85rpm]
Feb 20 02:19:31 gymnasticon gymnasticon[1625]: [2021-02-20T07:19:31.861Z] received stats from bike [power=62W cadence=85rpm]
Feb 20 02:19:32 gymnasticon gymnasticon[1625]: /home/pi/workspace/gymnasticon/node_modules/@abandonware/noble/lib/noble.js:564
Feb 20 02:19:32 gymnasticon gymnasticon[1625]:   peripheral.mtu = mtu;
Feb 20 02:19:32 gymnasticon gymnasticon[1625]:                  ^
Feb 20 02:19:32 gymnasticon gymnasticon[1625]: TypeError: Cannot set property 'mtu' of undefined
Feb 20 02:19:32 gymnasticon gymnasticon[1625]:     at Noble.onMtu (/home/pi/workspace/gymnasticon/node_modules/@abandonware/noble/lib/noble.js:564:18)
Feb 20 02:19:32 gymnasticon gymnasticon[1625]:     at NobleBindings.emit (events.js:314:20)
Feb 20 02:19:32 gymnasticon gymnasticon[1625]:     at NobleBindings.onMtu (/home/pi/workspace/gymnasticon/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:277:8)
Feb 20 02:19:32 gymnasticon gymnasticon[1625]:     at Gatt.emit (events.js:314:20)
Feb 20 02:19:32 gymnasticon gymnasticon[1625]:     at Object.callback (/home/pi/workspace/gymnasticon/node_modules/@abandonware/noble/lib/hci-socket/gatt.js:329:10)
Feb 20 02:19:32 gymnasticon gymnasticon[1625]:     at Gatt.onAclStreamData (/home/pi/workspace/gymnasticon/node_modules/@abandonware/noble/lib/hci-socket/gatt.js:133:26)
Feb 20 02:19:32 gymnasticon gymnasticon[1625]:     at AclStream.emit (events.js:326:22)
Feb 20 02:19:32 gymnasticon gymnasticon[1625]:     at AclStream.push (/home/pi/workspace/gymnasticon/node_modules/@abandonware/noble/lib/hci-socket/acl-stream.js:33:10)
Feb 20 02:19:32 gymnasticon gymnasticon[1625]:     at NobleBindings.onAclDataPkt (/home/pi/workspace/gymnasticon/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:288:15)
Feb 20 02:19:32 gymnasticon gymnasticon[1625]:     at Hci.emit (events.js:314:20)

We should considering catching / retrying the bluetooth setup (assuming we have visibility at our scope) to become more durable to this. Systemd did restart the process, so this isn't a terminal case for folks.

ptx2 commented 3 years ago

Interesting! It looks like a race in noble where it tries to operate on a peripheral that is not in its internal list of peripherals. There is an open PR on noble https://github.com/abandonware/noble/pull/165 which looks like it will prevent the TypeError from occurring.

I will keep an eye on that PR and update noble once they merge it.