Fail to read ble characteristic when type(char.uuid)==int

  • I am stuck with an issue that is preventing me from evaluating the possibility of including pycom boards in our products.

    Connecting to and reading from the same device, but using other clients works (eg. from an android/iphone system).

    With pycom:

    1. Scanning and connecting to a ble device works, but only when the char.uuid() is of type int.
    2. If char.uuid() is of type bytes, it fails.

    Is this a know bug or merely a coincidence? What additional information can I provide?

    Best regards,

  • @ricardo If you can read the device from other apps/devices, is there anything specific for the characteristics you get errors for?

    When you scan in reverse order, do you actually get exactly the same ones working and not working? If you do get the ones that work (so they should be at the end at that point) then that means the BLE connection is still active.

    I see you tried adding a sleep at some point, did that change anything?

    There must be something special about those characteristics, but from your logs I'm not quite sure it's the fact they have long UUIDs, as a few others have the issue as well.

    You would probably have to dig into the BLE stack source code to see if there's anything relevant in there. You may try previous versions of the firmware as well. Usually newer versions fix things, but they occasionally also break things here or there.

  • @jcaron Thanks again for your reply. Yes, i defined callbacks, but they are not called.

    Tried scanning the services in reverse order and got the same result as before. Still cannot read the same services as before.

    On tracebacks, you are right. I tried "sys.print_exception(e)", but that only gave me the info i already know.

    Unfortunately I have no access to the other device (the one I am trying to connect to). What I know is that it is possible to do that with an android app i built, and also with some python scripts on my laptop using other python libraries.

    A BLE scanner could be an option. What would I be looking for?

  • @ricardo Did you define functions to call for your callbacks? If you just define the callback but there isn't anything to call, it won't give much info.

    A traceback won't give you much more information since you already know where you are and what the context is Python-wise.

    Do you have access to logs/traces on the other device? Or a BLE scanner?

    Just for fun can you scan the services/characteristics in reverse order?

  • @jcaron any idea on how to investigate this issue further? It would be really nice to be able to consider pycom for our prototyping of new products...

  • @jcaron Initially, when i bumped into this issue, I was trying to read directly characteristic b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12V%\x00\x00' from service b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12T%\x00\x00'.

    As this was failing, I decided to iterate over all of characteristics and try to read all that report Bluetooth.PROP_READ.

    So, I tried again now and when skipping services 1800, 1801 and 1801a, I get the same result as before:

    Reading chars from service 2 = 1800
    Reading chars from service 2 = 1801
    Reading chars from service 2 = 180a
    Reading chars from service 1 = b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12T\x15\x00\x00'
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12U\x15\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12U\x15\x00\x00'
    the requested operation failed
    uuid=b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12U\x15\x00\x00' type=<class 'NoneType'> value=None
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12V\x15\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12V\x15\x00\x00'
    the requested operation failed

    also setting the callbacks didn't show any info, but most likely i am doing it wrongly:

        bt = Bluetooth()
        bt.callback(trigger=Bluetooth.NEW_ADV_EVENT, handler=new_adv_event)
        bt.callback(trigger=Bluetooth.CLIENT_CONNECTED, handler=new_client_connected)
        bt.callback(trigger=Bluetooth.CLIENT_DISCONNECTED, handler=new_client_disconnected)

    Is there a way to get the full stack trace of an exception (similar to the traceback module in normal python)?

  • @ricardo The issue does not seem to be related to the format of the characteristic uuid, it starts when reading characteristic 10793 from service 180a, and from then on nothing else is returned, as if the connection had been broken.

    Try skipping services 1801 and/or 180a to see if there's something special about those.

    Also, try listening for events (using bluetooth.callback) to see if there isn't a spurious disconnect.

  • This post is deleted!

  • reading works when char.uuid() is int, but when char.uuid() returns a binary string, reading fails. Could be just a coincidence. Is there some more information i can prove and how? Namely, how can i provide a full traceback as requested?

    I am currently running the latest dev firmware, but get the same result with both stable and pybytes.


    services =
        for service in services:
              if type(service.uuid()) == bytes:
                  print('Reading chars from service 1 = {}'.format(service.uuid()))
                  print('Reading chars from service 2 = %x' % service.uuid())
              chars = service.characteristics()
              for char in chars:
                  #if char.uuid()==CHAR_2556 and ( & Bluetooth.PROP_READ):
                  if ( & Bluetooth.PROP_READ):
                      print("reading", type(char.uuid()), char.uuid())
                      value = None
                          value =
                      except Exception as e:
                          print("failed to read", char.uuid())
                          print('uuid={} type={} value={}'.format(char.uuid(), type(value), value))
                          print("failed to print", char.uuid())

    Pycom MicroPython 1.20.0.rc9 [v1.9.4-7eeaf3f] on 2019-04-01; SiPy with ESP32
    Type "help()" for more information.


    start bt scan
    Waiting for device
    found device DEVICE1
    connecting to DEVICE1
    Reading chars from service 2 = 1800
    reading <class 'int'> 10752
    uuid=10752 type=<class 'bytes'> value=b'DEVICE1'
    reading <class 'int'> 10753
    uuid=10753 type=<class 'bytes'> value=b'\x80\x04'
    reading <class 'int'> 10756
    uuid=10756 type=<class 'bytes'> value=b'\x10\x00@\x01\x04\x00\x90\x01'
    Reading chars from service 2 = 1801
    Reading chars from service 2 = 180a
    reading <class 'int'> 10793
    failed to read 10793
    the requested operation failed
    uuid=10793 type=<class 'NoneType'> value=None
    reading <class 'int'> 10789
    failed to read 10789
    the requested operation failed
    uuid=10789 type=<class 'NoneType'> value=None
    reading <class 'int'> 10791
    failed to read 10791
    the requested operation failed
    uuid=10791 type=<class 'NoneType'> value=None
    reading <class 'int'> 10790
    failed to read 10790
    the requested operation failed
    uuid=10790 type=<class 'NoneType'> value=None
    reading <class 'int'> 10792
    failed to read 10792
    the requested operation failed
    uuid=10792 type=<class 'NoneType'> value=None
    Reading chars from service 1 = b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12T\x15\x00\x00'
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12U\x15\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12U\x15\x00\x00'
    the requested operation failed
    uuid=b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12U\x15\x00\x00' type=<class 'NoneType'> value=None
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12V\x15\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12V\x15\x00\x00'
    the requested operation failed
    uuid=b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12V\x15\x00\x00' type=<class 'NoneType'> value=None
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12W\x15\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12W\x15\x00\x00'
    the requested operation failed
    uuid=b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12W\x15\x00\x00' type=<class 'NoneType'> value=None
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12Y\x15\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12Y\x15\x00\x00'
    the requested operation failed
    uuid=b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12Y\x15\x00\x00' type=<class 'NoneType'> value=None
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12Z\x15\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12Z\x15\x00\x00'
    the requested operation failed
    uuid=b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12Z\x15\x00\x00' type=<class 'NoneType'> value=None
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12\\x15\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12\\x15\x00\x00'
    the requested operation failed
    uuid=b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12\\x15\x00\x00' type=<class 'NoneType'> value=None
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12]\x15\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12]\x15\x00\x00'
    the requested operation failed
    uuid=b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12]\x15\x00\x00' type=<class 'NoneType'> value=None
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12b\x15\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12b\x15\x00\x00'
    the requested operation failed
    uuid=b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12b\x15\x00\x00' type=<class 'NoneType'> value=None
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12c\x15\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12c\x15\x00\x00'
    the requested operation failed
    uuid=b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12c\x15\x00\x00' type=<class 'NoneType'> value=None
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12e\x15\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12e\x15\x00\x00'
    the requested operation failed
    uuid=b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12e\x15\x00\x00' type=<class 'NoneType'> value=None
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12f\x15\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12f\x15\x00\x00'
    the requested operation failed
    uuid=b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12f\x15\x00\x00' type=<class 'NoneType'> value=None
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12^\x15\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12^\x15\x00\x00'
    the requested operation failed
    uuid=b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12^\x15\x00\x00' type=<class 'NoneType'> value=None
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12_\x15\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12_\x15\x00\x00'
    the requested operation failed
    uuid=b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12_\x15\x00\x00' type=<class 'NoneType'> value=None
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12d\x15\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12d\x15\x00\x00'
    the requested operation failed
    uuid=b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12d\x15\x00\x00' type=<class 'NoneType'> value=None
    Reading chars from service 1 = b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12T%\x00\x00'
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12V%\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12V%\x00\x00'
    the requested operation failed
    uuid=b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12V%\x00\x00' type=<class 'NoneType'> value=None
    reading <class 'bytes'> b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12X%\x00\x00'
    failed to read b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12X%\x00\x00'
    the requested operation failed
    uuid=b'#\xd1\xbc\xea_x#\x15\xde\xef\x12\x12X%\x00\x00' type=<class 'NoneType'> value=None

  • @ricardo Can you provide the relavant parts of your code, and the exact error message (full traceback)?

Log in to reply

Pycom on Twitter