Creating logger timed out

Hi everyone

I have a small project where I want to try out the logging system of the MetaWear-sensor. For this I'm using the .NETStandard implementation extended by @FrozenKiwi (see post: https://mbientlab.com/community/discussion/2266/xamarin-forms-support#latest).

While adding a new routing to the gyro (IGyroBmi160) which dictates to log data I'm getting an exception saying "Creating logger timed out". My code looks like this:
var logging = _board.GetModule<ILogging>();

var gyro = _board.GetModule<IGyroBmi160>();
if (gyro == null)
return;

gyro.Configure(OutputDataRate._50Hz, DataRange._1000dps);

await gyro.AngularVelocity.AddRouteAsync(source =>
{
source.Log(data =>
{
var angularVelocity = data.Value<AngularVelocity>();
OnStatusChanged?.Invoke(this, new StatusChangedEventArgs(angularVelocity.ToString()));
});
});

logging.Start(true);

gyro.AngularVelocity.Start();
gyro.Start();

await Task.Delay(TimeSpan.FromSeconds(8));

logging.Stop();

await logging.DownloadAsync(100, (nEntries, totalEntries) =>
{
OnStatusChanged?.Invoke(this, new StatusChangedEventArgs($"Progress update = {nEntries}/{totalEntries}"));
});

logging.ClearEntries();

What am I doing wrong?

Comments

  • edited November 2017
    Make sure the board is in a clean state before creating loggers.  Reset the board and try again when AddRouteAsync throws this exception.
  • @Eric "Reset the board"; by this you mean calling TearDown, disconnect from the sensor and reconfiguring it?
  • Just call TearDown, then attempt to setup the logger again.
  • I had a bit of trouble on the UWP platform with various operations timing out (from memory the characteristic search on UWP was so slow that sometimes an operation would timeout before we'd even starting sending to the board).  

    I increased the timeouts for debugging by 10x just to make sure any issues were genuine issues, rather than my PC being super-slow.  It may be worth trying that.  Search for the error message you get, and somewhere just above that will be the code that starts the timer.  I think I replaced all the time out intervals with a #define for ease-of-replacing, try upping that value just to ensure that the timeout is valid.  All the await's everywhere make it hard to verify that the function being called has been exited before the timeout triggers, but thats a good indication that the communication -should- be working.
  • Both didn't give me a solution; I've tried connecting to the device, initializing the board and next called "TearDown". I've increased the timeout by factor 10 (x10) and added routing to the gyro-module to log its data. However the timeout is still thrown...

    Code that is taking too long:
    MbientLab.MetaWear.Impl.Logging.cs
    private void createLogger()
    ...
    bridge.sendCommand(command);
    ...
  • Is this behavior happening on both Android and iOS devices?  

    It seems like your device is perhaps losing connection when attempting to add the loggers.  You should check that the commands are in fact being sent to the board and that the connection is still active during logger creation.
  • The logger is working perfectly on iOS, but not on Android. I don't think it's related to losing connection, since the connection is established moments before creating the logger.
    Streaming data works great on both platforms.
  • FYI on iOS sometimes the time out also happens; by simply calling "TearDown" the logger can be started. This doesn't help on Android.
  • Try logging data with the MetaBase app on your Android device:
  • Logging with the MetaBase app works, but not with above SDK. So what I need to know: how can this be fixed?
  • Well, we don't know why only the Android platform is experiencing timeouts nor why it only occurs with logging.  You will need to take this up with @FrozenKiwi to figure out the appropriate fix as Xamarin support is based on his fork.

    Some general debugging tips though:
    1. Run your gyro logging code on other Android devices and OS versions.
    2. Log other sensors, like accelerometer or magnetometer
    3. Check that the MetaWear is indeed receiving the create logger commands
      • This one will require directly accessing the GATT characteristics to check their states
  • Can you share your code with me Stefaan?

    I haven't done any logging, so I might need to do some tweaking.

    I've got a new version with android-specific fixes waiting - I just need to push some fixes upstream to the bluetooth library
  • I've created a sample and published it to git: https://github.com/StefaanAvonds/MetaWearLoggingSample
    This code works for iOS (logging is done), but creates a time out on Android.

    Looking forward to your changes!
  • Hey Stefaan,

    Short update, I've been tracking some odd activity through Android for a while, and finally traced it to some issues with use of async in the API.

    I've rebuilt the API around 0.3.  It's not quite ready for consumption (I also had to make some fixes to the bluetooth library) but if you don't mind getting your hands dirty it's all been pushed to github.

    If your a bit more patient, I'll have the cleanup finished and everything re-tested by the NY.
  • Thanks! I've got some other stuff on my working list at the moment, but I could have a look at it in January.
This discussion has been closed.