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

    BLE does not read whole buffer data

    Scheduled Pinned Locked Moved Issues & Bugs
    ble
    15 Posts 3 Posters 3.2k Views 3 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.
    • L Offline
      livius
      last edited by livius

      Hi,

      current firmware wipy2:

      os.uname()
      (sysname='WiPy', nodename='WiPy', release='1.10.2.b1', version='v1.8.6-849-g0af003a4 on 2017-11-24', machine='WiPy with ESP32')
      

      when i read adv = bt.get_adv()
      adv data contain truncated data
      e.g.
      it reads

      b'\x02\x01\x06\x1b\xffW\x01\x003"c\xe6\xb4\xd19\xdc\x83\xa6\x82\x98\xf3\x19w\xc3\x03\xd2lBk\xad\xc2'
      

      which is:
      0201061bff570100332263e6b4d139dc83a68298f31977c303d26c426badc2

      but should be
      '\x02\x01\x06\x1b\xffW\x01\x003"c\xe6\xb4\xd19\xdc\x83\xa6\x82\x98\xf3\x19w\xc3\x03\xd2lBk\xad\xc2\n\tMI Band 2\x03\x02\xe0\xfe'

      0201061bff570100332263e6b4d139dc83a68298f31977c303d26c426badc20a094d492042616e6420320302e0fe

      without correct buffer it is not possible to retrive name of device correctly

      think about people first, then computers

      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @livius
        last edited by

        @livius
        I do not know much about sources but maybe someone know how to debug this
        how can i send something to UART from e.g.
        BTA_GATTC_GetAllChar or bta_gattc_get_db_with_opration
        https://github.com/pycom/pycom-esp-idf/blob/master/components/bt/bluedroid/bta/gatt/bta_gattc_cache.c

        think about people first, then computers

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

          Hi @livius ,
          The Bluetooth 4.1 spec only allows up to 31 bytes of LE advertising data (39 bytes maximum LL PDU packet composed of 2 bytes of header + 6 bytes of device address + 31 bytes of Advertising Data (AD)

          Anything above that gets truncated in the stack.

          L 1 Reply Last reply Reply Quote 0
          • L Offline
            livius @jmarcelino
            last edited by

            @jmarcelino
            then why all scanners which i have got whole buffer?
            Do you think that all are in BT4.2?

            think about people first, then computers

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

              @livius
              I don know what devices you're trying to read from and what the scanner is but I think that it's unlikely they're all 4.2 devices.

              Probably they combine advertising data and scan response somehow?

              L 1 Reply Last reply Reply Quote 0
              • L Offline
                livius @jmarcelino
                last edited by livius

                @jmarcelino
                I see that MI BAND 2 is BLE4.2 device.
                and it follow spec
                http://microchipdeveloper.com/wireless:ble-link-layer-packet-types

                think about people first, then computers

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

                  @livius
                  It's not possible to send such a long advertising packet even in Bluetooth 4.2, you'd need Bluetooth 5 (with LE Advertising Extensions) for that.

                  If you look up that Microchip reference the Advertising Channel PDUs have a 0-37 bytes Payload and you need the device address on top (6 bytes) on that so the maximum actual data is 31 bytes.

                  If you are seeing longer packets it's probably because your BLE scanner combines the result of the advertising packet with the scan response.

                  L 1 Reply Last reply Reply Quote 0
                  • L Offline
                    livius @jmarcelino
                    last edited by

                    @jmarcelino
                    Thank you Jose i am new in BLE protocol and must dig more.
                    But this will be strange if BLE4.2 device will advertise in mixed protocol
                    I suppose that your last sentence is much more possible.

                    think about people first, then computers

                    L 1 Reply Last reply Reply Quote 0
                    • L Offline
                      livius @livius
                      last edited by

                      @livius
                      It really combine SCAN_RSP packet.
                      And now i have question, how can i make active scan with wipy2.
                      Because i understand that 'start_scan' do passive scan only?

                      think about people first, then computers

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

                        @livius
                        The current scan is active: https://github.com/pycom/pycom-micropython-sigfox/blob/eca3b714a11c4b84e740a36b4096a20aac3c9be2/esp32/mods/modbt.c#L271

                        but we don't combine the scan response, only show advertising data.

                        L 1 Reply Last reply Reply Quote 0
                        • L Offline
                          livius @jmarcelino
                          last edited by livius

                          @jmarcelino
                          Is there possibility to got scan response data somehow then?

                          think about people first, then computers

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

                            @livius
                            That's not available yet, sorry

                            L T 3 Replies Last reply Reply Quote 0
                            • L Offline
                              livius @jmarcelino
                              last edited by

                              @jmarcelino
                              thank you for that info.
                              I will dig into sources if something can be done self here.

                              think about people first, then computers

                              1 Reply Last reply Reply Quote 0
                              • T Offline
                                tudro @jmarcelino
                                last edited by

                                @jmarcelino +1 to have the scan reponse available :) thank you

                                1 Reply Last reply Reply Quote 0
                                • L Offline
                                  livius @jmarcelino
                                  last edited by livius

                                  @jmarcelino
                                  I see that in public firmware it is now also avaiable :)

                                  (mac=b'\xd2lBk\xad\xc2', addr_type=1, adv_type=0, rssi=-83, data=b'\x02\x01\x06\x1b\xffW\x01\x00\xef\xbf\xc9\xac\xe7\xd5\xd0.\xe5\xf0\x8cr[\x8b[w\x03\xd2lBk\xad\xc2\n\tMI Band 2\x03\x02\xe0\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') {'NameShort': None, 'Flag': 6, 'Mac': b'd26c426badc2', 'NameComplete': b'4d492042616e642032', 'MfrData': b'570100efbfc9ace7d5d02ee5f08c725b8b5b7703d26c426badc2', 'Data': b'0201061bff570100efbfc9ace7d5d02ee5f08c725b8b5b7703d26c426badc20a094d492042616e6420320302e0fe00000000000000000000000000000000', 'Rssi': -83, 'Appearance': None}
                                  
                                  'NameComplete': b'4d492042616e642032'
                                  
                                  import binascii
                                  a=b'4d492042616e642032'
                                  c=binascii.unhexlify(a)
                                  print(c)
                                  

                                  give me proper result :)
                                  'MI Band 2'

                                  think about people first, then computers

                                  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