Occasional Error while scanning and Occasional Logger Problem

  1. When running the following part of my code:

    # CURRENT_DIR = os.getcwd()
    # ble_filename = os.path.join(CURRENT_DIR, 'ble_device.txt')
    ble_filename = viz.res.getPublishedPath('ble_device.txt')
    use_address = str(open(ble_filename, 'r').read())

    selection = -1
    devices = None
    scan_flag = False
    loop_count = 0
    while selection == -1:
        print("scanning for devices...")
        devices = {}
        def handler(result):
            devices[result.mac] = result.name
        addr_count = 0
        for address, name in six.iteritems(devices):
            print("[%d] %s (%s)" % (addr_count, address, name))
            if address == use_address:
                selection = addr_count
                scan_flag = True
                print(selection, address)
            addr_count+= 1
        loop_count+= 1
        if loop_count >= 4:
            print('Sensor not found')
            viz.message('Sensor not found')
            if text3D_reset is not None:
            text_str_reset = "Sensor not found!"
            text3D_reset = viz.addText3D(text_str_reset,pos=[0,9,145],align=viz.ALIGN_CENTER_BOTTOM)

I get the following occasional error seen in my output log. It finds the device but then the API error occurs and other errors then follow.

scanning for devices...
[0] E6:12:88:19:7C:9F (MetaWear)
[1] 72:D4:8E:03:E8:4F ()
[2] CA:61:16:C4:11:A5 (MetaWear)
[3] F3:FC:F7:60:B4:8C (MetaWear)
(3, 'F3:FC:F7:60:B4:8C')
Operation aborted

(HRESULT = -2147467260)
Error initializing the API (64)

Traceback (most recent call last):
File "_ctypes/callbacks.c", line 315, in 'calling callback function'
File "E:\Program Files\WorldViz\Vizard6\bin\Lib\site-packages\mbientlab\metawear\metawear.py", line 237, in _write_gatt_char
File "E:\Program Files\WorldViz\Vizard6\bin\Lib\site-packages\mbientlab\metawear\metawear.py", line 229, in _write_char_async
next[0].write_without_resp_async(next[1], completed)
AttributeError: 'NoneType' object has no attribute 'write_without_resp_async'

What is happening here?

  1. Occasionally I do not also get data back from my acc logger portion of my code. I am using your example. Is there a way to check on the status of the logger? Is there a way to query the logger (re-download) until I can get the data?

I feel that both of these reliability issues may be related. Is it an advertising issue with your BLE sensor and Windows 10?

When the sensor works, it works well, but reliability issues like these can't exist. Please provide specific approaches to address these issues. Thanks.


    1. Ble is not guaranteed to connect the first time. You need to handle that and attempt to connect again.
    2. Yes, please see our APIs, specifically the cppdocs regarding logging to understand more.
  • For 1, I will add in exceptions in Python to try to address this. I have not seen any examples of code at your github site for setting up white lists and advertising. Do any exist? Would filtering and adjusting the ad parameters help here? Looking at this forum, I have seen that others have had connections issues and tried to adjust ad and connection parameters to address this. This should be further addressed since your IMUs will need to operate around other IoT devices (and the number of devices is only growing).

    For 2, I have looked at the logging documentation. How can I detect when a logger download has finished?

  • I started looking at the pymetawear module, so this code appears to address some of the issues that I am seeing. Therefore, I will try to implement their approach.

    In terms of whitelisting, I saw from a closed discussion in 2018:


    that the whitelisting commands were "only experimental." Did this ever change?

Sign In or Register to comment.