Pycom LoPy, boot.py and WiFi connection.



  • Hello, started fiddling with a LoPy, for now just making it so that it connects to any WiFi connections that are in its list of known networks, and this works when used in main.py, but not in boot.py.

    It makes me wonder, when boot finishes and main is started, does something like a WiFi setting persist? The documentation makes it sound like it should, but my device is giving me what seems to be the opposite behavior, so I'm a little confused here, can anyone shed some light on this?

    (LoPy is running v1.20.1.r1, WiFi script used is the same as here. (Multliple Networks Script.))

    Edit: Some more stuff, I guess I could put this in main.py, though what confuses me is that most sources really make it sound like it should go in boot.py. WLAN is a class that has settings, but, when imported, run and the script closing, won't that also drop all settings and processes? I'm really confused as to how this works.



  • @mnovella

    The weird thing is, I'm trying this code now on a WiPy too, both that and the Lopy have the latest firmware as of writing this. 1.20.1.r2.

    wlan.ssid() doesn't return anything, even if I set it and then check it again...



  • @NickBoots

    Can you tell me a bit more about how to obtain the current instance and its data?

    In all the LoPys I've tried I use:

    from network import WLAN
    #no parameters give the existing instance
    current_wlan = WLAN()
    #now, you can get its attributes
    the_ssid = current_wlan.ssid()
    print(the_ssid)
    

    To obtain the SSID, for example.

    We could perhaps help you better if you showed us what you have tried, or what Firmware version your LoPys have. For me, the above included code works fine.



  • @mnovella Can you tell me a bit more about how to obtain the current instance and its data?

    Edit: Been testing around a bit, seeing if I can make a new WiFi connection using the interactive REPL, when I try wlan.ssid() it returns empty, but wlan.auth() does return a tuple with security and password that matches what I set in the boot script. I'm confused as to why ssid returns empty.

    Also, how does everyone else do, just drop it in main.py, I just don't understand still what is going wrong.



  • @NickBoots Reading the docs on the WLAN module, it reads, emphasis mine:

    The WLAN constructor is special in the sense that if no arguments besides the id are given, it will return the already existing WLAN instance without re-configuring it. This is because WLAN is a system feature of the WiPy. If the already existing instance is not initialised it will do the same as the other constructors an will initialise it with default values.

    So it seems that WLAN is a system feature (i.e: it will always be there) and that you can obtain the current instance by calling the constructor that way.

    In some tests I've done with the WLAN module, I have been able to successfully obtain the current instance, and obtain things like, say, the ssid and other data. One can also init() and deinit() the WLAN if you need to.



  • Still no help, anyone? I assume this is not a big mystery or anything. :/


Log in to reply
 

Pycom on Twitter