LoPy stops detecting BLE advertisements

  • @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).

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

  • @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)

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

  • @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.

  • @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?

  • @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.

  • @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
    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)
                    anydata = False
    bluetooth.callback(trigger = Bluetooth.NEW_ADV_EVENT, handler = new_adv_event)
    print('Starting BLE scan')
    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')
        # 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('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
    mode:DIO, clock div:1
    ho 0 tail 12 room 4
    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
    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
    Run time in seconds  3743
    MicroPython v1.8.6-776-gd01a46cd on 2017-09-29; LoPy with ESP32
    Type "help()" for more information.

  • @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.

  • @papasmurph Thanks!

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

  • @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.

  • @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.

  • 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.

  • @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.

  • 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.

  • @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.

  • 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.

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

  • @alanm101 I had a demo today. It did not go well. Last night in the hotel room, there were no issues with my solution running for several hours. Today, the Lopy stopped finding BLE advertisements every few minutes. Even a machine.reset() every 50 cycles made no difference, nor did some other solutions proposed elsewhere in this thread. This is soul-destroying. I understand that modules like Lopy are not intended for full-blown production solutions, but for makers who are trying to enter a market, some degree of reliability is important.

    The demo environment was saturated with high-tech. The hotel room, not so much. Perhaps that had a negative influence that led to the instability.

    Bottom line; the Lopy is, in my opinion, untrustworthy. I wish there was a possibility to return the two Lopy and two expansion boards. Sadly, in my neck of the woods (South Africa) that's not gonna happen. Since I'm stuck with the chips, I will follow other suggestions to hook up a serial monitor to look for esp-idf errors, once I've regained some dignity and enthusiasm after today's embarrassment.

Pycom on Twitter