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
- Hardware revision:
Host Device Information
- Ubuntu 16.04
- Linux Bluetooth library, version 5.54
Description of Problem
- Expected to print the message
Board initialised
frominitBoard(board)
with a status of0
(MBL_MW_STATUS_OK
). - Instead, observed the message
Error initialising board
frominitBoard(board)
with a status of16
(MBL_MW_STATUS_ERROR_TIMEOUT
). - The steps leading up to this behaviour in
main.cpp
:- A
WarbleGatt
object is first created using the device MAC address and the host HCI address. - Connection to the device MAC address via
warble_gatt_connect_async
is successful. - An
MblMwBtleConnection
object is created using our own implementations of the GATT operations. - An
MblMwMetaWearBoard
object is instantiated usingmbl_mw_metawearboard_create
. - Finally,
initBoard(board)
callsmbl_mw_metawearboard_initialize
, which initialises the internal state of theMblMwMetaWearBoard
object. This is where the observed message is printed.
- A
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:- Warble (version 1.1.5) for setting up Bluetooth LE connection
- Boost to help with UUIDs
All the output from
stdout
/stderr
(with the messageError initialising board
and the status of16
forMBL_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 likembl_mw_sensor_fusion_set_mode(board, MBL_MW_SENSOR_FUSION_MODE_IMU_PLUS)
will throw astd::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
btmon
to log the bt adapter activityHi 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
, nocontext
is required?? Only the functionswrite_gatt_char
,read_gatt_char
,enable_char_notify
andon_disconnect
are required?2) It also seems that
warble_gatt_connect_async
is called aftermbl_mw_metawearboard_create
, and thatmbl_mw_metawearboard_initialise
is called in the callback function ofwarble_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 theWarbleGatt
object, which I pass to thebtle_connection
object as thecontext
. 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 acontext
argument to work, whereas in my C++ code, I have to pass in astd::promise
argument as mycontext
and retrieve the future later on after the read of a value is done; otherwise no value is read at all.Cheers!