Inconsistent connecting with python client

I have recently bought four MetaWearC boards. They are running firmware version 1.3.6. I am experiencing inconsistent behaviour when trying to connect to the sensors via the pymetawear package. Sometimes things work fine, but after using any of the sensors for a while I fail to connect. The stack traces vary but the most common one I see is the following:

client = MetaWearClient("E6:E6:5A:18:7A:57")
error 1543082933.873459: Error on line: 296 (src/blestatemachine.cc): Operation now in progress
Traceback (most recent call last):
File "/home/peter/repos/venv36/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3267, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
client = MetaWearClient("E6:E6:5A:18:7A:57")
File "/home/peter/repos/venv36/lib/python3.6/site-packages/pymetawear/client.py", line 87, in init
self.connect()
File "/home/peter/repos/venv36/lib/python3.6/site-packages/pymetawear/client.py", line 122, in connect
self.mw.connect()
File "/home/peter/repos/venv36/lib/python3.6/site-packages/mbientlab/metawear/metawear.py", line 160, in connect
raise RuntimeError("Error initializing the API (%d)" % (self._init_status))
RuntimeError: Error initializing the API (64)

I have attatched a bluetooth trace whilst running the connect command above.

I have tried to use the MetaBase app to update the firmware on the sensors. I get the following error:

Error
Firmware update failed
(reason = Cannot use firmware v1.3.6 with this board)

Any help much appreciated!

Comments

  • zoozoo
    edited November 26

    Hi there, I'm getting an error RuntimeError: Error initializing the API (64) when connecting to my MetaMotionR. From looking at the code, 64 is STATUS_ERROR_ENABLE_NOTIFY, but not sure what that really means.

    The code that I run to do this is pretty simple I think:

    from mbientlab.metawear import MetaWear
    device = MetaWear('F5:70:20:A2:EA:45')
    device.connect()
    

    Any ideas what could be going on?

    thanks!
    -zo

  • edited November 26
    • Which platform are you running MetaBase on?
    • What Linux distro are you using?
    • Does resetting the BT adapter fix the issue?
    • How long does it take before this error appears?
  • zoozoo
    edited November 26

    Hi Eric, thanks for the quick response! Metabase is running on iOS. The code is running on Raspbian, very Ubuntu-like. Soft-resetting it indeed makes the initializing the API error disappear, but since soft-reset now it just hangs indefinitely on connect.

    Perhaps relatedly, I've also intermittently seen Failed to write value to characteristic(Error trying to issue command mid state) errors, that also seem to disappear when soft-resetting.

    Luckily, Metabase appears to work perfectly fine - can connect, get accelerometer data, etc. So it appears something's up with the API, perhaps with PyWarble / liblepp? Looks like I'm fundamentally misunderstanding something here, but I'm not sure what.

    Raspbian 4.14.71
    metawear 0.6.1
    warble 1.1.0
    requests 2.12.4
    liblepp latest version from its master branch
    Bluez 5.50
    boost 1.62
    dbus 1.10.26, if that matters
    firmware 1.4.2
    RSSI in the 70's, battery close to 100%

    And apologies, this should have been a new thread! I blindly hijacked someone else's, a bit rude.

    Any ideas?

    thanks!
    -zo

  • If it helps, this is a program that consistently requires me to soft-reset:

    from mbientlab.metawear import MetaWear, libmetawear
    from mbientlab.metawear.cbindings import *
    
    device = MetaWear('F5:70:20:A2:EA:44')
    device.connect()
    
    board = device.board
    module_id = libmetawear.mbl_mw_metawearboard_lookup_module(board, Module.HAPTIC). # dont believe this line's necessary for anything
    
    # first time this works fine
    libmetawear.mbl_mw_haptic_start_buzzer(board, 500)
    
    # second time, it fails, and must soft-reset. Error message is:
    # "Failed to write value to characteristic(Error trying to issue command mid state)"
    libmetawear.mbl_mw_haptic_start_buzzer(board, 500)
    

    Am I just missing something obvious here?

    thanks,
    -zo

  • @Eric said:

    • Which platform are you running MetaBase on?
    • What Linux distro are you using?
    • Does resetting the BT adapter fix the issue?
    • How long does it take before this error appears?
    • Metabase is running on Android version 7 (nougat)
    • Because I'm running on a mac, I'm collecting data inside a Ubuntu 18.04 Virtualbox machine with a bluetooth dongle on the host shared to the guest machine
    • A bluetooth restart on the linux box doesn't appear to help once the "RuntimeError: Error initializing the API (64)" error has occured
    • Today I was logging and downloading data from three sensors without an issue for around 40 mins before one sensor starting giving the "RuntimeError: Error initializing the API (64)". Once a sensor starts giving this error it seems to continue to give it.
  • I'll try to replicate these issues when I can. It seems like other users are also seeing issues with the Linux ble code.

  • We have also seen this issue a few times on Linux (RPi), usually when trying to communicate with multiple sensors simultaneously. A few reconnection attempts usually resolve it.

  • If it helps, I can also reproduce by running the stream_data.py example code.
    I can run python stream_data.py once, and it works just fine.
    If I try to run it a second time - immediately afterwards - it just hangs on connect.

    If I soft-reset, then I can run it again.

    Also tried upgrading to the firmware 1.4.4 but unfortunately same issue.

  • I'm am consistently seeing the same issues as zoo, meaning my sensors are effectively unusable with a Linux environment. Having had no luck upgrading the firmware via the metabase app I tried to do the upgrade programatically with the following code:

    from mbientlab.metawear import MetaWear
    from threading import Event
    
    import sys
    
    device = MetaWear(sys.argv[1])
    device.connect()
    print("Connected")
    
    args = {
        'progress_handler': lambda p: print("upload: %d%%" % (p)),
    }
    if (len(sys.argv) >= 3):
        args['version'] = sys.argv[2]
    
    e = Event()
    result = []
    def dfu_handler(err):
        result.append(err)
        e.set()
    
    device.update_firmware_async(dfu_handler, **args)
    e.wait()
    
    if (result[0] != None):
        raise result[0]
    

    This appears to load the latest firmware onto the sensor but then fails with the following message:
    Failed to write value to characteristic(Read Error.)

  • @pwwooldridge,

    Please don't update firmware via our Python script/example. We have actually removed the update_firmware.py script from the Python repository.

    You can only update firmware using the latest Android and iOS MetaBase App (and you should do so asap).

  • @Laura any thoughts on what the issue might be?

    thanks,
    -zo

  • The underlying issue is with how the libblepp library is used. We are still looking into it.

  • @Laura said:
    @pwwooldridge,

    Please don't update firmware via our Python script/example. We have actually removed the update_firmware.py script from the Python repository.

    You can only update firmware using the latest Android and iOS MetaBase App (and you should do so asap).

    Hi Laura,
    attached is a screenshot of what the app shows when I try to do update the firmware inside the metabase app

  • @pwwooldridge said:

    @Laura said:
    @pwwooldridge,

    Please don't update firmware via our Python script/example. We have actually removed the update_firmware.py script from the Python repository.

    You can only update firmware using the latest Android and iOS MetaBase App (and you should do so asap).

    Hi Laura,
    attached is a screenshot of what the app shows when I try to do update the firmware inside the metabase app

    v1.4.4 is not supported with your board.
    https://mbientlab.com/community/discussion/2773/firmware-upgrade-path#latest

  • @Eric said:
    The underlying issue is with how the libblepp library is used. We are still looking into it.

    Cool - thanks for the update Eric
    -zo

  • Is there perhaps a previous version of libblepp that's known to work? I installed the latest master version, perhaps being overly optimistic.

    thanks,
    -zo

  • @Eric said:

    @pwwooldridge said:

    @Laura said:
    @pwwooldridge,

    Please don't update firmware via our Python script/example. We have actually removed the update_firmware.py script from the Python repository.

    You can only update firmware using the latest Android and iOS MetaBase App (and you should do so asap).

    Hi Laura,
    attached is a screenshot of what the app shows when I try to do update the firmware inside the metabase app

    v1.4.4 is not supported with your board.
    https://mbientlab.com/community/discussion/2773/firmware-upgrade-path#latest

    @Eric - Thanks for clarifying!

  • zoozoo
    edited December 13

    Just checking in - any news / progress here?

  • I still have the same condition

  • I have not been able to replicate the init status 64 error in my VM or on our Pi.

    Record the BT adapter activity when you encounter this error and post it in the thread;

Sign In or Register to comment.