keeping states in sync

I have an impression, that with 1.2.3 FW my RG boards tend to reboot from time to time. What would be the best way to recognize the reset of the board from the App (I can see it nicely from LED blinking on startup) and how can I update the state of the modules? I have several routes and some of them are modifying the gates, counters on the others, so when device reboots it all collapses. Can I recognize if the route with specific name still exists on the board?
Thank you in advance


  • edited September 2016
    An unexpected disconnected will trigger the failure function from the ConnectionStateHandler function however it can take up to 20 seconds for Android to realize the btle connection was lost.  

    There is no method to check if a route is still valid.  If you detect a reset occurred, you can call tearDown to remove reset the API and then setup your routes / configure the sensors again.
  • The problem is that the failure is also caused by a trivial connection loss. If I reconnect to the board I have no clue if the board has been reset or simply lost connection for some time.
    One solution might be to pull up the GPIO and check the status after reconnect or read out the step counter if it has been reset to zero. But those are not too elegant for my taste.
  • That is true.  Well, we should first get to why your board is resetting as the firmware shouldn't be behaving like this.  How are you configuring your MetaWear?
  • edited September 2016
    For now, I've implemented the method, when I pulling up one pin and readout it status as digital input after reconnection, when drops down - means device has been rebooted.

    As for configuration, I have an external I2C sensors which I'm polling together with accelerometer and gyroscope with 5 Hz frequency and stream data. In my application connection might interrupt (due to physical distance/obstacles) and I should be able to warn user of the event (LED and buzzer). After reconnection I should be able to continue measurements without any interaction with user. In order to orchestrate this I have plenty of counters and filters which are modifying each other and I believe I'm running on the limit of allowed capacity, since if I'm adding a bit more functionality, I'm getting "route timeout failure".

    With this reset detection method I have been able to run the measurements for 10+ hours, while device has been rebooting and app has been tearing down and resetting the routes. With this procedure route ids were continiously incrementing. At some point further rerouting fails and it only can be solved by restarting the app, when route ids are reset to 0.
    Here is my question, would it work if on the clean start, I would make all the routing and store serialized state. Then, after detecting device reset after reconnect I would program the routes again in order to initialize onboard logic and then I simply reload the stored state. In this case I would assume to have real clean restart on the Android app side as well.

    Thank you in advance
  • That should work.  Alternatively, you can try using the macro to have the board automatically rebuild the entire data route.
  • @Eric
    Have implemented this method, works well for detection of reboot. I also set the class to the initial state by deserializing from stored state and then resetting all the routes (I have something like 9 routes). However, sometimes there is a failure of route setup (timeout). In this case, I just issue a reset command to the board and try again. If fails again - reset again, etc. Most of the time it finally succeeds. 
    My question is, how can I make the route setup more robust? Should I introduce delays? I'm already setting up the most critical routes sequentially (proceed to the next only when the previous one has already been setup).

  • Can you post your code?
  • It is a relatively large and elaborated module. I will try to extract the essence of MW communication. I will send it to hello @ mbientlab.

    In a meantime, I'm trying to make route initialization in sequence. Is it possible with AsyncOperation / onComplete to wait until completion of one route setup before initiating next one.
    This is also and issue for me for I2C communication, where my dialog with HW depends on the result of i2c read, which is only available in async. Is there a solution?
  • Do not send code to hello at mbientlab; post your code to pastbin or github and link it in this thread.

    Routes internally are initialized in sequence with a queue.
  • ok, with routes it is first called - first initialized.
    Can I orchestrate I2C - write, read and respond with write according to read results without having incapsulated completion handlers?
This discussion has been closed.