Timeout error while initialising board

Hello,

I'm getting an unexpected error while trying to initialise the board. My code is available here:

https://github.com/liweiyap/metawear-impl

Trying to gain programmatic access to a stream of quaternions via the C++ API on Linux has been much harder than anticipated. Example code for Linux would be of much help. In the meantime, below is a brief description of the current issue.

Board Information

  • Code tested and produces same results with MMR and MMR+. Both devices have the same:
    • Hardware revision: 0.4
    • Firmware revision: 1.5.0
    • Model number: 5

Host Device Information

Description of Problem

  1. Expected to print the message Board initialised from initBoard(board) with a status of 0 (MBL_MW_STATUS_OK).
  2. Instead, observed the message Error initialising board from initBoard(board) with a status of 16 (MBL_MW_STATUS_ERROR_TIMEOUT).
  3. The steps leading up to this behaviour in main.cpp:
    1. A WarbleGatt object is first created using the device MAC address and the host HCI address.
    2. Connection to the device MAC address via warble_gatt_connect_async is successful.
    3. An MblMwBtleConnection object is created using our own implementations of the GATT operations.
    4. An MblMwMetaWearBoard object is instantiated using mbl_mw_metawearboard_create.
    5. Finally, initBoard(board) calls mbl_mw_metawearboard_initialize, which initialises the internal state of the MblMwMetaWearBoard object. This is where the observed message is printed.

SDK

  • MetaWear C++ SDK, version 0.18.4
  • Ubuntu 16.04
  • Self-contained piece of MetaWear SDK calls that replicates this issue is found in main.cpp. The entire code can be copied/pasted and run, assuming that the following dependencies are also installed:

  • All the output from stdout/stderr (with the message Error initialising board and the status of 16 for MBL_MW_STATUS_ERROR_TIMEOUT all the way at the bottom):

Connecting to F2:DC:73:7D:AA:08
error 1590070706.778786: Error on line: 296 (src/blestatemachine.cc): Operation now in progress
Connected
Services disconvered
Characteristics discovered
Descriptors found
Connected to F2:DC:73:7D:AA:08
Enabling notification of characteristic: {326a9006-85cb-9195-d9dd-464cfbbae75a}
Succeeded in enabling notifications.
Reading characteristic: {00002a26-0000-1000-8000-00805f9b34fb}: 1.5.0
Reading characteristic: {00002a24-0000-1000-8000-00805f9b34fb}: 5
Reading characteristic: {00002a27-0000-1000-8000-00805f9b34fb}: 0.4
Reading characteristic: {00002a29-0000-1000-8000-00805f9b34fb}: MbientLab Inc
Reading characteristic: {00002a25-0000-1000-8000-00805f9b34fb}: 047D22
Writing characteristic: {326a9001-85cb-9195-d9dd-464cfbbae75a}: 1 128 
Writing characteristic: {326a9001-85cb-9195-d9dd-464cfbbae75a}: 2 128 
Writing characteristic: {326a9001-85cb-9195-d9dd-464cfbbae75a}: 3 128 
Writing characteristic: {326a9001-85cb-9195-d9dd-464cfbbae75a}: 4 128 
Writing characteristic: {326a9001-85cb-9195-d9dd-464cfbbae75a}: 5 128 
Writing characteristic: {326a9001-85cb-9195-d9dd-464cfbbae75a}: 6 128 
Writing characteristic: {326a9001-85cb-9195-d9dd-464cfbbae75a}: 7 128 
Writing characteristic: {326a9001-85cb-9195-d9dd-464cfbbae75a}: 8 128 
Writing characteristic: {326a9001-85cb-9195-d9dd-464cfbbae75a}: 9 128 
Writing characteristic: {326a9001-85cb-9195-d9dd-464cfbbae75a}: 10 128 
Writing characteristic: {326a9001-85cb-9195-d9dd-464cfbbae75a}: 11 128 
Writing characteristic: {326a9001-85cb-9195-d9dd-464cfbbae75a}: 12 128 
Writing characteristic: {326a9001-85cb-9195-d9dd-464cfbbae75a}: 13 128 
Writing characteristic: {326a9001-85cb-9195-d9dd-464cfbbae75a}: 15 128 
Error initialising board: 16

Comments

  • It looks like everything is correctly setup since you are receiving notifications. My guess is the response time between your ble adapter is too slow so you can try increasing the time for response with mbl_mw_metawearboard_set_time_for_response.

    Try with 1000ms

  • Hi Eric!

    I'm a colleague of the OP. Thanks a lot for your very kind response; we really appreciate it! Indeed, mbl_mw_metawearboard_set_time_for_response was already one of the first things we tried, but we still got the same timeout error as before. We even increased the time up to the maximum of 4000 ms, but to no avail. Due to the error whilst initialising the board, any further commands like mbl_mw_sensor_fusion_set_mode(board, MBL_MW_SENSOR_FUSION_MODE_IMU_PLUS) will throw a std::out_of_range exception. It seems that our problem is very similar to this one.

    I'm wondering if you happen to have any other suggestions. In the meantime, I have updated the code in the repo to include mbl_mw_metawearboard_set_time_for_response. The entire code can be copied/pasted and run.

    Thanks again and warmest regards
    Li

  • edited May 2020
    1. Did you get further in the initialization process when increasing the timeout?
    2. Use btmon to log the bt adapter activity
    3. Try connecting with the python or C# netstandard SDKs
      • They also use Warble to initialize their internal state
      • Look at the source code and see how they connect Warble to their SDKs (primarily the python one)
    4. Use different BT adapters
  • edited May 2020

    Hi Eric! Thanks a lot for your response; really appreciate your kind assistance!

    1) No, unfortunately, I didn't get any further in the initialisation process when increasing the timeout. Instead, I got exactly the same timeout error; it's just that I had to wait longer before the error message was printed.

    2) I have updated the bottom of my README document to show the output from btmon. As I'm not an expert with BTLE, I'm wondering if you could tell me, following a quick glance, whether you happen to spot anything abnormal.

    3) I was able to connect successfully to the MetaWear device using the Python SDK. I actually have looked before at both the Python and Java SDKs for reference when I was trying to improve my C++ code to its current state today. Hence, I'm wondering what exactly I'm missing in my C++ code. You did mention that, with my existing C++ code, "it looks like everything is correctly setup since you are receiving notifications".

    4) Not necessary, since I used the same dongle to connect successfully to the MetaWear device when using the Python SDK.

    Again, thanks a lot for your help!

    Warmest regards
    Li

  • I have a few questions regarding the Python SDK code:

    1) When initialising btle_connection, no context is required?? Only the functions write_gatt_char, read_gatt_char, enable_char_notify and on_disconnect are required?

    2) It also seems that warble_gatt_connect_async is called after mbl_mw_metawearboard_create, and that mbl_mw_metawearboard_initialise is called in the callback function of warble_gatt_connect_async?

    In my code, I had called warble_gatt_connect_async to establish connection first to the device, and then this would give me the pointer to the WarbleGatt object, which I pass to the btle_connection object as the context. Is my timeout error due to the wrong order of commands?

    3) Furthermore, I'm puzzled about how asynchronous functions like read_value_async in the Python code do not require a context argument to work, whereas in my C++ code, I have to pass in a std::promise argument as my context and retrieve the future later on after the read of a value is done; otherwise no value is read at all.

    Cheers!

Sign In or Register to comment.