Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    [SOLVED] Need Help with GATTC services

    Scheduled Pinned Locked Moved Discussion
    blegattcharacteristicsformats
    3 Posts 2 Posters 1.1k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      TCB
      last edited by jmarcelino

      Hi All

      Forgive me if this is a dumb question but I am struggling with understanding the GATT packet I am getting from my Lopy.

      I have a BLE beacon (a TILT hydrometer) and am reading the GATT output from it using the "Class Bluetooth "Quick Usage Example".

      The LoPy is connecting OK. but when I execute the line "print('Reading chars from service = {}'.format(service.uuid()))"

      I get a bunch of replies most of which I understand. But one service returns the line Quote "Reading chars from service = b'\xdet-\xf0p\x13\x12\xb5DK\xb1\xc5 \xff\x95\xa4' Unquote.

      I realize this may be a dumb question but what does this mean. I understand the 'b' means byte ( I could not find this documented anywhere so this is an educated guess) but what is the significance of "xdet" and what format are the included numbers in. I have never seen a number with DK in it.

      Thanks for any help anybody can provide. And by the way if this IS documented could somebody tell me where?

      Thanks in advance

      Tom B

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jmarcelino @TCB
        last edited by jmarcelino

        @TCB

        b'...' is a standard Python 3 bytes literal (docs)

        Printable characters are shown as they are, while non-printable are shown as \xYZ where YZ is the hexadecimal value, so in your example \xdet means 0xDE, 0x74 (which prints as t)

        If you want everything in hexadecimal use the binascii module:

        import binascii
        print(binascii.hexlify(service.uuid()))
        
        1 Reply Last reply Reply Quote 0
        • T Offline
          TCB
          last edited by

          @jmarcelino

          SOLVED

          Thanks for the help. Was able to adapt the example to connect to my Lopy and get a specific service with no issues.

          Some tips for anybody else trying to do access a GATT service.

          If you use the Pycom example it will print out a services.uuid like this

          b'\xdet-\xf0p\x13\x12\xb5DK\xb1\xc5 \xff\x95\xa4' .

          But if you are trying to access the service using the UUID as it appears it will not work.

          So what I did (as suggested by jmarcelino) was use binascii.hexlify to get a hex value. Which in this case was -----de742df0701312b5444bb1c520ff95a4' ,then use that as the value with binascci.unhexlify as the uuid input like this

          service.uuid()==binascii.unhexlify(b'de742df0701312b5444bb1c520ff95a4'):

          Another way to get the uuid is to use the Android Nordic Semiconductor nRF Connect app (or similar) to get the hex value for the UUID and then use unhexlify as above.

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better đź’—

          Register Login
          • 1 / 1
          • First post
            Last post

          Pycom on Twitter

          Pycom