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.3k 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.
    • J Offline
      jcaron @alanm101
      last edited by

      @alanm101 did it stop finding any BLE advertisements at all, or specifically those you were looking for?

      A 1 Reply Last reply Reply Quote 0
      • A Offline
        alanm101 @alanm101
        last edited by

        Apologies for yet another post. Please issue a cease and desist if this it too much.

        Anyway, back at the hotel, and further tests (sans my serial monitor that's pining away at home). Perhaps the complexity of the demo environment was a factor. The code I'm running now at the hotel suggests that volume of BLE advertisements overwhelmed the chip. So one must figure out how to code around this. A callback that intelligently discards? I'm getting out of my depth on this and will happily accept derision from the community but would prefer constructive guidance.

        A 1 Reply Last reply Reply Quote 1
        • A Offline
          alanm101 @jcaron
          last edited by

          @jcaron All advs. I specifically put in debug code to determine this. As mentioned, the machine.reset() had no impact, yet a physical reset via the reset button got the BLE scanning showing results.

          1 Reply Last reply Reply Quote 0
          • A Offline
            alanm101 @alanm101
            last edited by

            No code change. No power supply change. At the hotel, no problems. The hypothesis that the chip can't handle technologically complex environments appears to have some merit.

            Hopefully a community member will highlight a solution.

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

              @alanm101
              I'm afraid it's impossible to highlight any correct solution based on so little information.

              You're saying that the module - mounted on the expansion board, not a breadboard or something custom - stops scanning BLE beacons in "complex technological environments"?

              Can you post what appears in the serial output (from the Expansion Board USB port) from the module when this happens? This is crucial to understanding - and potentially fixing - the problem.

              A 1 Reply Last reply Reply Quote 0
              • J Offline
                jcaron
                last edited by

                I wouldn't be too surprised if some specific advertisements could break the scanning code. However without an idea of what that advertisement could be, it might be difficult to find out.

                If you have some other device that can capture all BLE advertisements, it could be useful to get that capture so that each advertisement could then be tested again the BLE code to see how it handles it.

                1 Reply Last reply Reply Quote 0
                • A Offline
                  alanm101
                  last edited by

                  @jcaron @jmarcelino Thanks for the comments guys. I will be spending quality time on this and will give feedback sometime. No problems when it ran all night at the hotel. Only my 4 iBeacons in range though.

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

                    @papasmurph Please help me understand how you posted the code? When I try pasting inline, it's a mess. I don't have permission to upload a file.

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

                      @alanm101 Three left apostrophs (```) on separate lines before and after the code.

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

                        @papasmurph Thanks!

                        1 Reply Last reply Reply Quote 0
                        • A Offline
                          alanm101 @jmarcelino
                          last edited by

                          @jmarcelino My goodness j, I'm embarrassed. Somehow I concluded that the expansion board has a separate debug serial output. So I hooked up on pins G1, G2 and GND as per other posts and found it's the exact same serial output as via the MicroUSB serial output. I'm seeing no extra output other than my own debug print statements. I will post the full source code and the serial output a little later.

                          1 Reply Last reply Reply Quote 0
                          • A Offline
                            alanm101 @alanm101
                            last edited by alanm101

                            @jcaron @jmarcelino Here's the code and the serial output. You will notice that, without warning or raised exception, the scanning becomes unsuccessful at around 3450 seconds (58 minutes). That's indicated by the repeated beacon ID and rssi, despite having moved that beacon out of range when the repetition started. As always, advice greatly appreciated. Options: a) repeat test on Lopy using standard espessif's standard firmware, b) repeat test with a standard ESP32.

                            from network import Bluetooth
                            import pycom
                            import time
                            import gc
                            import binascii
                            import machine
                            
                            mybeaconids = ['d3e0f6cd4ca9','eea068fa3738','f51e1bced835','ea204c29bb1f','e9f1db4814ef']
                            enditall = False
                            
                            pycom.heartbeat(False)
                            timeSleep = 0.01
                            
                            bluetooth = Bluetooth()
                            starttime = time.time()
                            
                            devid = ''
                            rssi = ''
                            
                            def new_adv_event(event):
                                global devid, rssi
                                if event.events() == Bluetooth.NEW_ADV_EVENT:
                                    anydata = True
                                    while anydata:
                                        adv = bluetooth.get_adv()
                                        if adv != None:
                                            devid = binascii.hexlify(adv[0]).decode('utf-8')
                                            rssi = str(adv[3]*-1)
                                        else:
                                            anydata = False
                            
                            bluetooth.callback(trigger = Bluetooth.NEW_ADV_EVENT, handler = new_adv_event)
                            
                            print('Starting BLE scan')
                            bluetooth.init()
                            bluetooth.start_scan(-1)
                            
                            p_in = machine.Pin("G17",machine.Pin.IN, pull=machine.Pin.PULL_UP)
                            
                            loopcnt = 0
                            while True:
                                loopcnt += 1
                                if not bluetooth.isscanning():
                                    print('--------- Restarting BLE scan')
                                    bluetooth.deinit()
                                    bluetooth.init()
                                    bluetooth.start_scan(-1)
                            
                                # to keep the log manageable, print details only every 500 loops.
                                if loopcnt%500 == 0:
                                    print(time.time() - starttime, devid, rssi)
                                if p_in() == 0:
                                    print('pin')
                                    break
                                time.sleep(0.05)
                            
                            bluetooth.callback(None)
                            bluetooth.stop_scan()
                            bluetooth.deinit()
                            
                            print('Run time in seconds ', time.time() - starttime)
                            
                            
                            
                            
                            
                            ------  Serial output. 
                            
                            
                            rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
                            ets Jun  8 2016 00:22:57
                            
                            rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
                            configsip: 0, SPIWP:0xee
                            clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
                            mode:DIO, clock div:1
                            load:0x3fff9010,len:12
                            ho 0 tail 12 room 4
                            load:0x3fff9020,len:388
                            load:0x40078000,len:11584
                            load:0x4009fb00,len:848
                            entry 0x4009fc9c
                            Starting BLE scan
                            25 f51e1bced835 74
                            50 6c8009ac5ece 71
                            75 d5e2f8cf4eab 76
                            100 7e0504d53526 51
                            125 e9f1db4814ef 73
                            150 7e0504d53526 49
                            175 7e0504d53526 52
                            200 730088c7c467 49
                            225 6c8009ac5ece 78
                            250 6c8009ac5ece 72
                            275 d5e2f8cf4eab 75
                            300 d5e2f8cf4eab 75
                            325 d3e0f6cd4ca9 67
                            350 7e0504d53526 49
                            <snip>
                            ...
                            </snip>
                            2850 6c28333b9548 52
                            2875 73bc08769bce 62
                            2900 d5e2f8cf4eab 66
                            2925 f7201dd0da37 76
                            2950 73bc08769bce 61
                            2975 6c28333b9548 50
                            3000 73bc08769bce 59
                            3025 d5e2f8cf4eab 63
                            3050 73bc08769bce 62
                            3075 ea204c29bb1f 69
                            3100 73bc08769bce 58
                            3125 73bc08769bce 58
                            3150 73bc08769bce 58
                            3175 6c28333b9548 51
                            3200 6c28333b9548 51
                            3225 73bc08769bce 62
                            3250 d3e0f6cd4ca9 63
                            3275 6c28333b9548 50
                            3300 73bc08769bce 58
                            3325 d5e2f8cf4eab 63
                            3350 6c28333b9548 51
                            3375 d5e2f8cf4eab 63
                            3400 6c28333b9548 50
                            3425 6c28333b9548 51
                            3450 73bc08769bce 62
                            3475 73bc08769bce 62
                            3500 73bc08769bce 62
                            3525 73bc08769bce 62
                            3550 73bc08769bce 62
                            3575 73bc08769bce 62
                            3600 73bc08769bce 62
                            3625 73bc08769bce 62
                            3650 73bc08769bce 62
                            3675 73bc08769bce 62
                            3700 73bc08769bce 62
                            3725 73bc08769bce 62
                            pin
                            Run time in seconds  3743
                            
                            MicroPython v1.8.6-776-gd01a46cd on 2017-09-29; LoPy with ESP32
                            Type "help()" for more information.
                            >>> 
                            
                            J J 2 Replies Last reply Reply Quote 0
                            • J Offline
                              jmarcelino @alanm101
                              last edited by

                              @alanm101
                              Thank you, that information is very helpful.

                              Yes it would be interesting to compare with the C level ESP-IDF code on the ESP32.

                              I'll look into it in the coming days.

                              1 Reply Last reply Reply Quote 0
                              • J Offline
                                jcaron @alanm101
                                last edited by

                                @alanm101 What's the advertising interval of your beacons? If you change the advertising interval or the number of beacons, does the time scanning fails change?

                                A 1 Reply Last reply Reply Quote 0
                                • A Offline
                                  alanm101 @jcaron
                                  last edited by alanm101

                                  @jcaron Time to failure is random. Just ran another test in same controlled environment (home). Failed after 13 minutes.

                                  Unfortunately I'm using Estimotes that cannot be transferred to me so frequency is a) fixed, b) unknown. The Estimote app refuses to divulge the info. Nordic's app can't list it either. If it will help, I can move them out of range and turn my phone into an iBeacon for a new test.

                                  Update: Can't seem to set update frequency for virtual beacon. At least not with the software I have.

                                  J 1 Reply Last reply Reply Quote 0
                                  • J Offline
                                    jcaron @alanm101
                                    last edited by

                                    @alanm101 AFAIK there’s no frequency selection in BLE, it uses frequency hopping on predefined frequencies.

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

                                      @jcaron ah sorry you meant the frequency of the advertisements. It’s usually not possible to find on the receiver side (as it does not necessarily listen all the time), but there are often ways to change it on the beacon (it’s a matter of compromise between time to discovery and power consumption)

                                      A 1 Reply Last reply Reply Quote 0
                                      • A Offline
                                        alanm101 @jcaron
                                        last edited by

                                        @jcaron Yes, I meant broadcast rate/frequency. Apologies. Sadly I can't configure these.

                                        1 Reply Last reply Reply Quote 0
                                        • J Offline
                                          jcaron
                                          last edited by

                                          @alanm101 this: https://community.estimote.com/hc/en-us/articles/204100806-What-are-the-default-settings-of-Estimote-Beacons-How-to-edit-settings- says you should be able to adjust them.

                                          Alternatively you may want to try to see if varying the number of beacons has an influence on the time to failure. Just in case it’s a simple matter of the code failing after receiving a given number of advertisements (which would also explain the issue you had at the exhibition).

                                          A 1 Reply Last reply Reply Quote 0
                                          • A Offline
                                            alanm101 @jcaron
                                            last edited by

                                            @jcaron Sadly, you have to "own" the Estimotes to make changes. The ones I have were allocated to someone else who now has no access to the registered email.

                                            I'm running a test with the native IDF on a DOIT ESP32 board. Hacked the gatt_client.c code. No problems so far (58 minutes).

                                            J J 2 Replies 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
                                            • 4 / 7
                                            • First post
                                              Last post

                                            Pycom on Twitter

                                            Pycom