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

    Cannot get WiPy 3 to work as station (WLAN.STA)

    Scheduled Pinned Locked Moved WiPy 2&3
    wipy 3.0wlansta mode
    4 Posts 2 Posters 43 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.
    • D Offline
      danielk
      last edited by

      Hi,

      I have two WiPy boards on an expansion 3 board. I'm having the same trouble with both getting them to communicate in Wi-Fi STA mode with a variety of software releases. Other aspects of the WiPy device appear to work, eg. flashing the RGBLed, and it can be put into AP mode and I can successfully authenticate with it from another Wi-Fi device.

      I've pasted my code below (hiding SSID/password etc), but what I am observing is that:

      • with a static ifconfig, the unit associates (authenticates) with my home Wi-Fi AP, but is not reachable with ping on the assigned address. Further, I can see no evidence that any packets are sent by the WiPy as the ARP does not complete with the ping, and I do not see the WiPy MAC address in my home switch.
      • with static ifconfig, but the incorrect password, the unit does not associate. This proves the unit is talking to my AP at one level.
      • with dhcp ifconfig, the unit associates but the DHCP does not complete and again, no evidence of any packets sent on the switch or DHCP server.

      I guess there might be an incompatibility between the AP and the WiPy, but I'd like to check my boot.py code first.

      I've tried this code on three releases:

      • 1.18.2.r1 (as supplied with the WiPy)
      • 1.20.0.rc13
      • 1.20.2.rc7

      Thanks for any assistance.

      Daniel

      # boot.py
      import machine
      import os
      
      print("Starting boot...")
      
      from network import WLAN
      wl = WLAN(mode=WLAN.STA)
      
      # save the default ssid and auth
      original_ssid = wl.ssid()
      original_auth = wl.auth()
      
      wl.disconnect()
      wl.mode(WLAN.STA)
      
      try:
          # Select one of these two ifconfig()s
          #wl.ifconfig(config=('192.168.17.210', '255.255.255.0', '192.168.17.1', '192.168.17.2'))
          wl.ifconfig(config='dhcp')
          wl.connect('<REDACTED>', auth=(WLAN.WPA2, '<REDACTED>'), timeout=5000)
      
          # Progress indicator
          n = 0
          while not wl.isconnected():
              n += 1
              if n > 2500:
                  print(".", end="")
                  n = 0
              machine.idle()
      
          # Check final status
          if wl.isconnected():
              print("\nConnected to WiFi")
              print(wl.ifconfig())
          else:
              print("\nWiFi not connected")
      except:
          print("\nReverting to WiFi AP")
          wl.init(mode=WLAN.AP, ssid=original_ssid, auth=original_auth, channel=6, antenna=WLAN.INT_ANT)
      
      print("Finishing boot...")
      
      
      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @danielk
        last edited by robert-hh

        @danielk Instead of busy waiting, I have time.sleep(0.5) in the loop. In my experience, busy waiting makes it hard to connect.
        Edit: The code I use is:

        def do_connect():
            import network
            import time
            from uos import uname
            wlan = network.WLAN(mode=network.WLAN.STA) # create station interface
            if not wlan.isconnected():      # check if the station is connected to an AP
                wlan.ifconfig(config=(WIFI_IP, "255.255.255.0", "10.0.0.240",  "10.0.0.240"))
                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())
        
        D 1 Reply Last reply Reply Quote 0
        • D Offline
          danielk
          last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • D Offline
            danielk @robert-hh
            last edited by

            @robert-hh Thanks I agree busy-waiting is bad, my understanding was that machine.idle() would give other threads/interrupts the opportunity to run. That code was added to aid the debugging, to see activity while waiting for the network layer to configure itself.

            I've substituted your code but unfortunately it hasn't changed the networking behaviour - still no IP layer connectivity.

            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