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 2018

    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 2018
    • 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 2018

    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 2018

    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;

  • @Eric said:
    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;

    I added a trace to my first post on this discussion, if this is not useful then I can get another. In terms of recreating the error, it seems to happen mostly when trying to initiate connections to multiple sensors.

  • @pwwooldridge said:

    @Eric said:
    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;

    I added a trace to my first post on this discussion, if this is not useful then I can get another. In terms of recreating the error, it seems to happen mostly when trying to initiate connections to multiple sensors.

    How many is multiple?

  • @Eric said:

    @pwwooldridge said:

    @Eric said:
    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;

    I added a trace to my first post on this discussion, if this is not useful then I can get another. In terms of recreating the error, it seems to happen mostly when trying to initiate connections to multiple sensors.

    How many is multiple?

    I'm getting the issue fairly consistently trying to connect to 3 Metawear-C sensors

  • Hi All,

    Updating this thread.

    I did a fresh ubuntu install and tried Python examples using Python2 and Python3 and everything worked like a charm. I updated the tutorials as such: www.mbientlab.com/tutorials. It might help a few folks here.

  • edited February 2019

    Hi Laura,

    we are working since couple of months in a project with Python (linux) and we are struggling with randomly connection problems with multiple boards and cannot determine the origin of the issues.
    Could you please share with us your working environment:

    .1. OS Version (is it native Linux installation or in a VM, if in VM then which VM Version is used)
    2. BlueZ Version
    3. Bluetooth dongle (which chip is used)
    4. Metaboard type and Firmware

    Have you tried to connect multiple board to one BLE dongle/multiple BLE Dongles (we are experiencing connection probems here too)?

    Thanks in advance

  • edited February 2019

    @Akash,

    A few things to note in our experience with Bluetooth and multiple devices:

    • You will have to build in code to automatically handle reconnects and disconnects
    • Our boards advertise slowly but BLE on Linux is FAST, so again, don't be afraid to attempt connecting multiple times (that being said, once connected you can change the AD interval of our devices to ensure faster future connections). We typically see a failure to connect on the first try but it works just fine the second time (again this is completely normal - our ad rates are slowwwwwwwww)
    • Different dongles will behave differently, for some of our more "hardcore" projects, we don't use cheap Chinese dongles or rely on built in hardware that may have an antenna shared with Wifi. Instead we will use SENNAs or other high performance high range dongles: http://www.senanetworks.com/ud100-g03.html
    • Also, you will get about 1-4 reliable connections with one BLE dongle, you won't get more. The faster the connections, the fewer the sensors you should allocate per dongle. Understand those limitations with some experimentation and build your perfect architecture
    • You will need to use more than one dongle
    • You will need separate threads per dongle (split up the processing as much as possible)
    • RaspberryPis suck (no processing power). We like to build our higher performance projects on things like the IntelNUC or a comparable mini PC running a good flavor of Linux like Ubuntu. Don't use VMs or low performance hardware

    Hope this helps.

  • I'm having the same issue:

    python led.py "CA:0A:65:86:22:1B"
    error 1561471015.358345: Error on line: 296 (src/blestatemachine.cc): Operation now in progress
    Traceback (most recent call last):
    File "led.py", line 11, in
    device.connect()
    File "/home/ssqr/SSquare/sspy35_env/lib/python3.5/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 reinstalled MetaWear-SDK-Python first from master branch and the from 0.7.0 tag.

    I also upgraded the sensor firmware to 1.4.4.

    /first, I tested in master and 0.7.0 w/o firmware change.
    Then with the 1.4.4 firmware. Same result.

    uname -a
    Linux SSQR 4.19.42-v7+ #1219 SMP Tue May 14 21:20:58 BST 2019 armv7l GNU/Linux

    python --version
    Python 3.5.3

    Am I missing something here?

    Please help.

  • @panjar said:
    I'm having the same issue:

    python led.py "CA:0A:65:86:22:1B"
    error 1561471015.358345: Error on line: 296 (src/blestatemachine.cc): Operation now in progress
    Traceback (most recent call last):
    File "led.py", line 11, in
    device.connect()
    File "/home/ssqr/SSquare/sspy35_env/lib/python3.5/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 reinstalled MetaWear-SDK-Python first from master branch and the from 0.7.0 tag.

    I also upgraded the sensor firmware to 1.4.4.

    /first, I tested in master and 0.7.0 w/o firmware change.
    Then with the 1.4.4 firmware. Same result.

    uname -a
    Linux SSQR 4.19.42-v7+ #1219 SMP Tue May 14 21:20:58 BST 2019 armv7l GNU/Linux

    python --version
    Python 3.5.3

    Am I missing something here?

    Please help.

    Post a log of bt adapter activity like OP

Sign In or Register to comment.