Python, reliability, haptics.

Hello,

I'm running a metamotionR+ with firmware 1.5.0, on python 3.7.x with bluetooth 5 and 4 (experimenting with 2 different BLE chips, both native and usb). The device is in direct line of sight to the bluetooth dongles at about 2m away.

We're having several reliability issues with python code, these can be broken down into two parts. Firstly, establishing a connection. 1 in every 3 attempts at connection we see:

error 1575905670.888103: Error on line: 296 (src/blestatemachine.cc): Operation now in progress
Traceback (most recent call last):
File "", line 2, in
File "/usr/local/lib/python3.7/dist-packages/mbientlab/metawear/metawear.py", line 195, in connect
raise result[0]
mbientlab.warble.WarbleException: Timed out while trying to connect to remote device

OR

error 1575905754.181966: Error on line: 296 (src/blestatemachine.cc): Operation now in progress
Connected
Traceback (most recent call last):
File "", line 2, in
File "/usr/local/lib/python3.7/dist-packages/mbientlab/metawear/metawear.py", line 195, in connect
raise result[0]
mbientlab.warble.WarbleException: Failed to discover gatt services (status = 1)

It doesn't matter which bluetooth dongle we are using. Is this a common experience?

If we do connect to the device successfully, we struggle to fire haptics reliably:

libmetawear.mbl_mw_haptic_start_motor(board, 100, 1000)
Failed to write value to characteristic(Error trying to issue command mid state).

Is there a way around this error without software resetting? It is happening so frequently we unable to use the device properly at present.

Finally, i noted in the 1.4.5 firmware changelog is says: "Allow haptic pulses to be extended or cancelled"
I cannot find any documentation on this. Pythonic/C++ examples of this would be gratefully received.

Thanks!

Comments

  • edited December 2019

    Python bluetooth libraries are notoriously unreliable so you have to implement reconnects and graceful error handling if you are going to use python.
    In our experience, we have much better reliability with javascript (noble).

  • OK, we can live with careful error handling.

    Any ideas on the second point? I.e. "Failed to write value to characteristic(Error trying to issue command mid state)," after a haptic command. In this case, i seem to be connected to the board but unable to issue any further instructions. Is there a way of dealing with this without disconnecting and reconnecting?

    Also see my final point re extending/cancelling haptics.

    Thanks for coming back to us.

  • An occasional reset might do the trick.

  • Hrmm, maybe i'm not being clear enough:

    the following code connects to the board and vibrates, as the logs show, it then immediately fails. This is a common experience, and we get to, perhaps, a maximum of 5 sequential haptic vibrations before we see this error. What does this error mean! Is the issue fundamentally caused by a connection issue? Or is it related to some internal error on the board itself? How do we debug? Is there a solution without reconnecting? This is important as in some use cases we need to fire haptics very regularly (I.e. 10 times per minute or more - where we don't have time to reconnect).

    from mbientlab.metawear import MetaWear, libmetawear from mbientlab.metawear.cbindings import * device = MetaWear('F5:CD:EE:C5:F5:47', hci_mac='hci0') device.connect() error 1575999856.924795: Error on line: 296 (src/blestatemachine.cc): Operation now in progress Connected Services disconvered Characteristics discovered Descriptors found board = device.board libmetawear.mbl_mw_haptic_start_motor(board, 100, 1000) libmetawear.mbl_mw_haptic_start_motor(board, 100, 1000) Failed to write value to characteristic(Error trying to issue command mid state) libmetawear.mbl_mw_haptic_start_motor(board, 100, 1000) Failed to write value to characteristic(Error trying to issue command mid state) libmetawear.mbl_mw_haptic_start_motor(board, 100, 1000) Failed to write value to characteristic(Error trying to issue command mid state) libmetawear.mbl_mw_haptic_start_motor(board, 100, 1000) Failed to write value to characteristic(Error trying to issue command mid state)

  • why are you calling this more than once: libmetawear.mbl_mw_haptic_start_motor

  • That's just an example of me interacting with the board from a python shell. In this case i'm repeatedly calling the haptic motor, until it fails, which in this case is on the second call.

  • Further, unfortunately the metawear SDK doesn't even raise an appropriate exception here, which means we cannot error handle gracefully!

  • Since this was not the intended way to use our sensor; it is difficult to comment appropriately.

  • edited December 2019

    What is the intended way of using your sensor? All we are doing is connecting to the board using the python library you provide - most, if not all of the code is from examples your company provide . So, i'd be grateful if you could try.

    Ill repeat once more: our intention is to buzz when the board receives a certain combination of readings from the sensor. As we have made quite clear, at present we aren't able to reliably buzz at all. Could you please answer any of the questions i raised previously?

    What does this error mean?
    Is the issue fundamentally caused by a connection issue?
    Or, is it related to some internal error on the board itself?
    How do we debug?
    Is there a solution without reconnecting?

    At the moment, for others reading, we can't recommend using this board with python as the current implementation is incredibly buggy.

  • What I meant was that the motor should just turn on once. You shouldn't be calling libmetawear.mbl_mw_haptic_start_motor non stop. That's not the intended use of the motor

  • So you can only call the haptics once? Once per ... connection, reset, ever? Your comment doesn't make sense to me because we are able to call the haptics over and over again, it's just that it will eventually, randomly fail with that error, and we'd like to know why.

    It would be really helpful if you could help us actually debug the error message.

  • You should wait a few seconds for the action to be over before you call it again.

Sign In or Register to comment.