Network.wlan.status() only outputing none

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
BananarmyG567
Posts: 2
Joined: Fri Sep 10, 2021 8:15 pm

Network.wlan.status() only outputing none

Post by BananarmyG567 » Fri Sep 10, 2021 8:23 pm

when i try to use Network.wlan.status() it only outputs none.

i have tryed in on an TTGO LORA32 and esp32-wroom-32D

code:

Code: Select all

import socket
import network
import time

SSID=""
PASSWORD=""
wlan=None
s=None

def connectWifi(ssid,passwd):
  global wlan
  wlan=network.WLAN(network.STA_IF)                 #create a wlan object
  wlan.active(True)                                 #Activate the network interface
  wlan.disconnect()                                 #Disconnect the last connected WiFi
  wlan.connect(ssid,passwd)                         #connect wifi
  while(wlan.ifconfig()[0]=='0.0.0.0'):
    time.sleep(1)
  return True
  
try:
  if(connectWifi(SSID,PASSWORD) == True):           #judge whether to connect WiFi
    ip=wlan.ifconfig()[0]                           #get ip addr
    while True:
      time.sleep(1)
      print(wlan.status())
except:
  if (s):
    s.close()
  wlan.disconnect()
  wlan.active(False)
Last edited by BananarmyG567 on Sat Sep 11, 2021 12:01 am, edited 1 time in total.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Network.wlan.status() only outputing none

Post by davef » Fri Sep 10, 2021 9:41 pm

Which board?

BananarmyG567
Posts: 2
Joined: Fri Sep 10, 2021 8:15 pm

Re: Network.wlan.status() only outputing none

Post by BananarmyG567 » Fri Sep 10, 2021 9:45 pm

i have tried it on an TTGO lora32 and esp32-wroom-32D

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Network.wlan.status() only outputing none

Post by davef » Sat Sep 11, 2021 6:41 am

Tried on a ESP32-WROOM-32D with v1.17 generic:

Code: Select all

import socket
import network
import time

SSID="AndroidAP8362"
PASSWORD="xyz"
wlan=None
s=None

def connectWifi(ssid,passwd):
    global wlan
    wlan=network.WLAN(network.STA_IF) #create a wlan object
    wlan.active(True) #Activate the network interface
    wlan.disconnect() #Disconnect the last connected WiFi
    wlan.connect(ssid,passwd) #connect wifi

    while(wlan.ifconfig()[0]=='192.168.43.1'):
        time.sleep(1)
    return True

try:
    if(connectWifi(SSID,PASSWORD) == True): #judge whether to connect WiFi
        ip=wlan.ifconfig()[0] #get ip addr
    while True:
        time.sleep(1)
        print(wlan.status())
except:
    if (s):
        s.close()
        wlan.disconnect()
        wlan.active(False)
Seems to work on my hotspot. I don't see the actual status message but:

1001
then
1010
1010
1010

I can't find the right document but think those numbers say not connected then connected. If I turn the hotspot off I only get:
1001
1001
1001
1001

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Network.wlan.status() only outputing none

Post by davef » Sat Sep 11, 2021 7:08 am

Found my notes and I didn't get them 100%

1000 Idle
1001 Connecting
1010 Got IP

Post Reply