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

    LoPy4 boot.py Wifi

    Scheduled Pinned Locked Moved LoPy
    6 Posts 2 Posters 97 Views 2 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.
    • N Offline
      nemke.petrovic
      last edited by

      Hi all
      I am new

      I like to have script in boot.py in Lopy4 for Wifi. So I have connection all time with devices. No mater waht happed to main.py code to have access to change it.
      Also I need to use external Antenna for wifi (alredy connected), so in script I like to specific antenna=WLAN.EXT_ANT and mode to be STE

      My wifi Network is secure auth=WPA2, and I like dhcp to assigne IP to LoPY4 (I configure MAC IP reservation on router, so same IP is given to module)

      Help. I need example of this script ?

      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @nemke.petrovic
        last edited by

        @nemke-petrovic you can put any code into boot.py. Did you have a look at the examples in the documentation? E.g. https://docs.pycom.io/tutorials/all/wlan/

        1 Reply Last reply Reply Quote 0
        • N Offline
          nemke.petrovic
          last edited by

          Yes, of course. But didn't manage to work.
          So, i write here maybe someone have working script

          robert-hhR 1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @nemke.petrovic
            last edited by

            @nemke-petrovic You could try that one, which is except for the antenna switch the one I am using:

            def do_connect():
                import network
                import time
                wlan = network.WLAN(mode=network.WLAN.STA) # create station interface
                wlan.antenna(WLAN.EXT_ANT)
                if not wlan.isconnected():      # check if the station is connected to an AP
                    wlan.connect(ssid=WIFI_SSID, auth=(network.WLAN.WPA2, WIFI_PASSWD))
                    for _ in range(100):
                        if wlan.isconnected():      # check if the station is connected to an AP
                            break
                        print('.', end='')
                        time.sleep_ms(200)
                    else:
                        print("Connect attempt timed out\n")
                        return
                print('\nnetwork config:', wlan.ifconfig())
            
            do_connect()
            

            WIFI_SSID and WIFI_PASSWD have to be set accordingly.

            N 1 Reply Last reply Reply Quote 0
            • N Offline
              nemke.petrovic @robert-hh
              last edited by

              import machine
              import time
              from network import WLAN
              wlan = WLAN() # get current object, without changing the mode
              
              if machine.reset_cause() != machine.SOFT_RESET:
                  wlan.init(mode=WLAN.STA)
                  # configuration below MUST match your home router settings!!
              
              if not wlan.isconnected():
                  # change the line below to match your network ssid, security and password
                  wlan.connect('IoT Network', auth=(WLAN.WPA2, '19Akacki_Ryu86'), timeout=5000)
                  while not wlan.isconnected():
                      machine.idle() # save power while waiting
                      break
              

              Interesting, it doesn't work. I write new using examples from pycom documenty, end this is work.
              LoPy4 ver 1.20.2.rc6

              Many thanks for reply

              robert-hhR 1 Reply Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @nemke.petrovic
                last edited by

                @nemke-petrovic The break statement in the last line is wrong. That way, the code will not wait for a connection. And also, the antenna is internal.

                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 / 1
                • First post
                  Last post

                Pycom on Twitter

                Pycom