MetaTracker wouldn't connect unless reset
Using a MetaHub (raspberry pi 3) running node I discover and connect :
MetaWear.discover(function (device) {
device.connectAndSetUp(function (error) {
...
})
})
This works fine for the first time. Once the pi is restarted, the discover callback is called, then the disconnect event is fired, and the connectAndSetUp callback is never called. I get another discover callback, but that's because I call discover when disconnected, but that's it. The way to make it work again is by opening the Metabase mobile app, choose Diagnostics, connect to the device (connect, it will fail and ask if it should connect again, then it succeeds) and choose Reset from the options to reset the Tracker. After the reset, the sensor can connect again.
Update: I can't reproduce this all the time, but it happens often, like 80% of the time.
Please list out the steps to reproduce this issue and post the code you are running.
Okay I solved the issue by following few practices:
- calling
stopDiscoverbefore AND after callingdiscover - restarting discovery when disconnect is fired as well
- have a timeout for
connectAndSetUp(10 seconds worked) and try again on timeout - exiting and restarting in case of a connection error (using
forever)
With this approach, sometimes it connects from first try, other times it takes an additional 1 or 2 tries, but it connects eventually.
I'll close this for now, as it "sort of" solves the problem, and I don't need the MetaBase app to reset the MetaTracker.