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

    LoPy stops detecting BLE advertisements

    Scheduled Pinned Locked Moved Issues & Bugs
    lopybluetoothblebeaconibeacon
    123 Posts 15 Posters 84.1k Views 14 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.
    • papasmurphP Offline
      papasmurph @livius
      last edited by

      @livius So collect will not kick in anyway? I'll try it, but it seems like brute force considering the amount of calls and possible effects on timing.

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

        @papasmurph
        Yes, but without you after some time get automatic call to gc.collect with longer wait time

        then stop for a few seconds

        and this can be the case

        think about people first, then computers

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

          @livius Agreed, that could be the case for the short stops, even though garbage collection taking several seconds for such simple code seems strange. In any case, it doesn't explain the complete stop after a while. collect is added now for each loop and I removed the timeout. Let's see what happens.

          papasmurphP 1 Reply Last reply Reply Quote 0
          • papasmurphP Offline
            papasmurph @papasmurph
            last edited by papasmurph

            @livius As far as I can see it's a real problem. After some time get_adv stops returning any data back, despite multiple beacons in close proximity. I tried calling start_scan again, but then the code stopped. I changed the code so it sleeps for a much shorter time. That way it keeps up with a huge margin. The gc.collect() is still there, but I hope I will not need it down the road. It also generally misses a lot of BLE advertisements, while a nearby phone doesn't.

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

              @papasmurph
              Please report your findings here
              https://github.com/pycom/pycom-micropython-sigfox/issues

              think about people first, then computers

              1 Reply Last reply Reply Quote 0
              • S Offline
                stef
                last edited by

                Same problem here , but solved it by perfoming a deepsleep beetween scans ( as deepsleep is acting like a reset).
                I just finishing coding the same loop in C using ESP-IDF . will try it tomorow on a Generic ESP32 Board , will report here if i got the same bug . ( if not maybe that 's mean it's a Python Bug )

                1 Reply Last reply Reply Quote 0
                • D Offline
                  Duane Kaufman
                  last edited by

                  Hello,

                  I recently started playing with my LoPy, and have a similar issue trying to harvest multiple advertisements at the same time.

                  Using other BLE tools, I know I have three devices advertising within range, yet I only get data from one of them when using code like in the Example for 'bluetooth.resolve_adv_data(data, data_type)' in the PyCom documentation.

                  In the Example code, how does one get a different advertising packet when calling bluetooth.get_adv()? Is it supposed to be simply chance timing that uncovers all of the device advertising that can be seen?

                  As you can probably tell, I am also a BLE newbie!

                  Thanks in advance!
                  Duane

                  papasmurphP 1 Reply Last reply Reply Quote 0
                  • papasmurphP Offline
                    papasmurph @Duane Kaufman
                    last edited by

                    @Duane-Kaufman I could detect multiple beacons. Note that they have to be kept apart to not interfere with each other. For each call to get_adv you get another advertisement from the queue, but the queue can only keep up to 8 values. Without any time.sleep (or at least very short), Python easily keeps up.

                    D 1 Reply Last reply Reply Quote 0
                    • D Offline
                      Duane Kaufman @papasmurph
                      last edited by

                      @papasmurph Thanks for replying!

                      I'll keep in mind the physical separation issue. a couple of mine were pretty close together (but their advertisements should have been pretty asynchronous)

                      So, I should loop on get_adv until it returns None to exhaust it? I guess I never thought of that, but then again, the Example code should loop pretty fast on the get_adv call anyway?:

                      link to Example code

                      Sincerely,
                      Duane

                      papasmurphP 2 Replies Last reply Reply Quote 0
                      • papasmurphP Offline
                        papasmurph @Duane Kaufman
                        last edited by

                        @Duane-Kaufman I've noted that they can still completely "scramble" the communication. Yes, wait for None, and you should capture all if only the loop is fast enough.

                        1 Reply Last reply Reply Quote 0
                        • papasmurphP Offline
                          papasmurph @Duane Kaufman
                          last edited by

                          @Duane-Kaufman I note that 1.7 works better in detecting pings, even though no enhancement was listed for this specifically. It remains to see if it ever stops scanning.

                          S J D 3 Replies Last reply Reply Quote 0
                          • S Offline
                            stef @papasmurph
                            last edited by

                            @papasmurph
                            Some BT enhancement have been listed on the official ESP32 board for the last framework version .
                            My test with the last ESP Framework in C see no bug for BT detection even with more than 12h of scanning.
                            Will flash one of my lopy with 1.7 and report here the result.
                            Stéphane A.

                            papasmurphP 1 Reply Last reply Reply Quote 0
                            • papasmurphP Offline
                              papasmurph @stef
                              last edited by

                              @stef That sounds promising. I'm now testing it continuously.

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

                                @papasmurph
                                Yes, BLE scan type has been changed to BLE_SCAN_TYPE_PASSIVE in the latest build which should help with beacons (at the cost of losing the device name for devices which only return it after a SCAN_REQ query from an active scan)

                                papasmurphP 1 Reply Last reply Reply Quote 0
                                • papasmurphP Offline
                                  papasmurph @jmarcelino
                                  last edited by papasmurph

                                  @jmarcelino Sadly, scanning (or detection) still stops though. After an hour or so get_adv stopped returning data, despite there being beacons close by that I hadn't moved. A hard reset got it started again.

                                  papasmurphP 1 Reply Last reply Reply Quote 0
                                  • papasmurphP Offline
                                    papasmurph @papasmurph
                                    last edited by

                                    @papasmurph When this happens, neither is it possible to attach to the LoPy's WiFi access point. My code still runs though.

                                    1 Reply Last reply Reply Quote 0
                                    • D Offline
                                      Duane Kaufman @papasmurph
                                      last edited by

                                      @papasmurph I think I might have a bad board, as I have not been able to get BLE to see devices I can detect with my phone around me. My code:

                                      `from network import Bluetooth
                                      import time
                                      import binascii

                                      bluetooth = Bluetooth()
                                      bluetooth.init()

                                      bluetooth.start_scan(20) # start scanning with 10s timeout
                                      while bluetooth.isscanning():
                                      time.sleep(1)
                                      adv_list = []
                                      adv_list = bluetooth.get_adv()
                                      if adv_list != None:
                                      for adv in adv_list:
                                      print("Time: {0} adv.mac: {1}".format(time.time(), binascii.hexlify(adv.mac)))
                                      else:
                                      print("Time: {0} adv.mac: {1}".format(time.time(), "None"))
                                      `
                                      and I get:
                                      MicroPython v1.8.6-607-g9c8a0e9e on 2017-05-01; LoPy with ESP32
                                      Login as: micro
                                      Password:
                                      Login succeeded!
                                      Type "help()" for more information.

                                      import BLE_Raw
                                      Time: 229 adv.mac: None
                                      Time: 230 adv.mac: None
                                      Time: 231 adv.mac: None
                                      Time: 232 adv.mac: None
                                      Time: 233 adv.mac: None
                                      Time: 234 adv.mac: None
                                      Time: 235 adv.mac: None
                                      Time: 236 adv.mac: None
                                      Time: 237 adv.mac: None
                                      Time: 238 adv.mac: None
                                      Time: 239 adv.mac: None
                                      Time: 240 adv.mac: None
                                      Time: 241 adv.mac: None
                                      Time: 242 adv.mac: None
                                      Time: 243 adv.mac: None
                                      Time: 244 adv.mac: None
                                      Time: 245 adv.mac: None
                                      Time: 246 adv.mac: None
                                      Time: 247 adv.mac: None
                                      Time: 248 adv.mac: None`

                                      Thanks for your review,
                                      Duane
                                      `

                                      papasmurphP 1 Reply Last reply Reply Quote 0
                                      • papasmurphP Offline
                                        papasmurph @Duane Kaufman
                                        last edited by papasmurph

                                        @Duane-Kaufman get_adv returns a single tuple, not an array, so "for" doesn't make sense here. See the code I posted initially.

                                        Example: (mac=b'\xb4\x99Lm\x80\xcd', addr_type=0, adv_type=0, rssi=-87, data=b'\x02\x01\x06\x03\x02\xf0\xff\x15\xffBH\xcd\x80mL\x99\xb4\xa2@\x10\x01\x00\x00\xff\xff\x0f\xff\xff\xff\x00\x00')

                                        D 1 Reply Last reply Reply Quote 1
                                        • D Offline
                                          Duane Kaufman @papasmurph
                                          last edited by

                                          @papasmurph Thanks for looking this over. Changed code to this, but still no response:

                                          import time
                                          import binascii
                                          
                                          bluetooth = Bluetooth()
                                          bluetooth.init()
                                          
                                          bluetooth.start_scan(20)    # start scanning with 10s timeout
                                          while bluetooth.isscanning():
                                          	time.sleep(1)
                                          	adv_list = bluetooth.get_adv()
                                          	if adv_list != None:
                                          		print("Time: {0} adv.rssi: {1}".format(time.time(), adv.rssi))
                                          	else:
                                          		print("Time: {0} adv.mac: {1}".format(time.time(), "None"))```
                                          
                                          and I still get nothing :( as before
                                          
                                          Duane
                                          papasmurphP 1 Reply Last reply Reply Quote 0
                                          • papasmurphP Offline
                                            papasmurph @Duane Kaufman
                                            last edited by papasmurph

                                            @Duane-Kaufman It works fine if you fix a few bugs. Well, at least it did for me.

                                            from network import Bluetooth
                                            import time
                                            
                                            bluetooth = Bluetooth()
                                            bluetooth.init()
                                            bluetooth.start_scan(20)
                                            
                                            while bluetooth.isscanning():
                                                adv_list = bluetooth.get_adv()
                                                if adv_list != None:
                                                    print("Time: {0} adv.rssi: {1}".format(time.time(), adv_list.rssi))
                                            
                                                time.sleep(0.05)
                                            
                                            print("I give up!")
                                            
                                            D 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
                                            • 2
                                            • 3
                                            • 4
                                            • 5
                                            • 6
                                            • 7
                                            • 1 / 7
                                            • First post
                                              Last post

                                            Pycom on Twitter

                                            Pycom