lopy4 hangs with "ERROR! Could not connect to Pybytes"

  • I provisioned a third LoPy4. Trying to get a fresh start on this one and enable multiple network connectivity if one SSID isn't available.
    I put this in boot.py

    # boot.py -- run on boot-up
    import os
    import machine
    uart = machine.UART(0, 115200)
    known_nets = {
        'firstlan': {'pwd': 'firstl@n'},
        'secondlan': {'pwd': 'secondl@n'},#, 'wlan_config':  ('', '', '', '')}, # (ip, subnet_mask, gateway, DNS_server)
    if machine.reset_cause() != machine.SOFT_RESET:
        from network import WLAN
        wl = WLAN()
        original_ssid = wl.ssid()
        original_auth = wl.auth()
        print("Scanning for known wifi nets")
        available_nets = wl.scan()
        nets = frozenset([e.ssid for e in available_nets])
        known_nets_names = frozenset([key for key in known_nets])
        net_to_use = list(nets & known_nets_names)
            net_to_use = net_to_use[0]
            net_properties = known_nets[net_to_use]
            pwd = net_properties['pwd']
            sec = [e.sec for e in available_nets if e.ssid == net_to_use][0]
            if 'wlan_config' in net_properties:
            wl.connect(net_to_use, (sec, pwd), timeout=10000)
            while not wl.isconnected():
                machine.idle() # save power while waiting
            print("Connected to "+net_to_use+" with IP address:" + wl.ifconfig()[0])
        except Exception as e:
            print("Failed to connect to any known network, going into AP mode")
            wl.init(mode=WLAN.AP, ssid=original_ssid, auth=original_auth, channel=6, antenna=WLAN.INT_ANT)

    I copied the code from the WLAN tutorial and added my SSIDs. It connected the first time, I tried pushing a change to main.py and when it restarted, it halted with this:

    rst:0x1 (POWERON_RESET),boot:0x32 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    mode:DIO, clock div:1
    entry 0x400a059c
    Scanning for known wifi nets
    Connected to firstlan with IP address:
    WMAC: 807D3A937918
    Firmware: 1.18.2
    Pybytes: 0.9.6
    Pybytes configuration read from /flash/pybytes_config.json
    WiFi connection established
    MQTT ERROR! Avialable Interfaces are down
    Trying to join LoRa.ABP for 15 seconds...
    Setting up LoRa socket...
    ERROR! Could not connect to Pybytes!

    I have two other devices using the same SSID and both are online.
    I went to the Firmware tool and checked "erase flash filesystem", thinking this would wipe it.
    when it finised and I removed the boot jumper to ground, it came up once. But the filesystem wasn't blank. It ran and connected to pybytes.. went and changed a line of code, and the problem returned.

    Is there any way to make it just wait and reboot if it can't connect to pybyes?
    Would any of this code be the culprit?
    Also, in the code, this line has a comma at the end in the example.. but it seems it shouldn't be there?

        'secondlan': {'pwd': 'secondl@n'},

  • @Paul-Thornton I have the same problem. Using the solution proposed by you does not fix the issue. I disabled also the firewall.

    Firmware: 1.18.2.r3
    Pybytes: 0.9.10
    Pybytes configuration read from /flash/pybytes_config.json
    WiFi connection established
    MQTT ERROR! Avialable Interfaces are down
    ERROR! Could not connect to Pybytes!

    This is error printed in the REPL console.

    @dnear1 If you want to connect to Pybytes and you did all the steps to register your board it is not necessary to connect to wi-fi in the boot.py
    The wi-fi network connection is handled by pybytes so basically the pybytes will not have the wlan interface.

  • Are you still able to connect to the repl?

    if so try running

    >>> import os 
    >>> os.mkfs('/flash')

    to wipe the storage if the checkbox fails on the firmware updater.

Log in to reply

Pycom on Twitter