ESP8266 WiFi client

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
enzo
Posts: 23
Joined: Thu Jun 11, 2020 1:03 am

ESP8266 WiFi client

Post by enzo » Wed Dec 30, 2020 10:26 pm

Hi everybody,
please, can anyone explain why this code:

Code: Select all

def connectToWifi(SSID, PW):
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        print("Connecting to network...")
        wlan.connect(SSID, PW)
        while not wlan.isconnected():
            pass
    print('Connection successful')
    mac = ubinascii.hexlify(network.WLAN().config('mac'),':').decode()
    return(wlan.ifconfig())   

client_config = connectToWifi(SSID, PW)
print(client_config)
sometimes outputs this messages:

Code: Select all

>>> bcn_timout,ap_probe_send_start
ap_probe_send over, rest wifi status to disassoc
state: 5 -> 0 (1)
rm 0
pm close 7
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 1
cnt

connected with synwiuninet, channel 6
dhcp client start...
ip:10.0.0.191,mask:255.255.255.0,gw:10.0.0.2
pm open,type:2 0
Please note that other devices (smartphones) connected to the same network works fine.
Is there anywhere a list of these MicroPython wifi related warning/errors?
Thanks.

User avatar
pythoncoder
Posts: 4789
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ESP8266 WiFi client

Post by pythoncoder » Thu Dec 31, 2020 6:51 am

This guide might help.
Peter Hinch

bitninja
Posts: 134
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Re: ESP8266 WiFi client

Post by bitninja » Thu Dec 31, 2020 7:32 pm

Those are normal ESP debug messages. Add...

Code: Select all

import esp
esp.osdebug(None)
And the messages will be suppressed.

User avatar
pythoncoder
Posts: 4789
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ESP8266 WiFi client

Post by pythoncoder » Sat Jan 02, 2021 5:51 am

Yes, but the fact that they are spontaneously being emitted suggests that something untoward is happening.
Peter Hinch

bitninja
Posts: 134
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Re: ESP8266 WiFi client

Post by bitninja » Sat Jan 02, 2021 7:19 am

pythoncoder wrote:
Sat Jan 02, 2021 5:51 am
Yes, but the fact that they are spontaneously being emitted suggests that something untoward is happening.
I don't believe so.
I have always seen these messages when working with the ESP8266. By default the latest image (esp8266-20200911-v1.13.bin) seems to be setup to have the Access Point enabled and the debug messages disabled.

I just tested this with a freshly burned Wemos D1 Mini...

Code: Select all

>>>
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== import network
=== wlan = network.WLAN(network.STA_IF)
=== wlan.active(True)
=== wlan.connect('testap', 'password')
===
#5 ets_task(4020f560, 28, 3fff9ed8, 10)
>>>
>>>
>>> wlan.connect('testap', 'password')
>>> wlan.disconnect()
>>> wlan.connect('testap', 'password')
>>>
>>>
>>> import esp
>>> esp.osdebug(0)
>>> wlan.disconnect()
state: 5 -> 0 (0)
rm 0
>>> wlan.connect('testap', 'password')
>>> scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 2
cnt

connected with testap, channel 11
dhcp client start...
ip:10.0.2.10,mask:255.255.255.0,gw:10.0.2.2

>>>
While

Code: Select all

esp.osdebug(None)
seems to be the default now, I do not believe it always has been. In any case, I usually leave

Code: Select all

esp.osdebug(0)
enabled until I am ready to release the code.

User avatar
pythoncoder
Posts: 4789
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ESP8266 WiFi client

Post by pythoncoder » Sun Jan 03, 2021 10:02 am

@bitninja I agree that debug messages are emitted after events like connect and disconnect. My reading of @enzo's message was that, having established the connection, his board then subsequently emitted these messages on occasion with no obvious cause.

This could be evidence of a problem. In my view it's more likely that it results from occasional WiFi outages with the ESP8266 reconnecting: this does occur, about once an hour here.
Peter Hinch

bitninja
Posts: 134
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Re: ESP8266 WiFi client

Post by bitninja » Sun Jan 03, 2021 3:35 pm

Ah, I see what you mean.

Yes, that would a problem if enzo is not expecting the disconnect/connects.

enzo
Posts: 23
Joined: Thu Jun 11, 2020 1:03 am

Re: ESP8266 WiFi client

Post by enzo » Sun Jan 03, 2021 3:54 pm

bitninja wrote:
Sun Jan 03, 2021 3:35 pm
Ah, I see what you mean.

Yes, that would a problem if enzo is not expecting the disconnect/connects.
That isn't an issue if the messages don't interfere with the software, i.e. I can ignore them in production.

enzo
Posts: 23
Joined: Thu Jun 11, 2020 1:03 am

Re: ESP8266 WiFi client

Post by enzo » Tue Jan 12, 2021 7:57 pm

Ok, now I disabled the Micropython debugger and don't see all those messages anymore.
Only

Code: Select all

#6 ets_task(4020ee60, 28, 3fff8e18, 10)
still appears but that's not an issue (however I'd like to be able to understand what is tells!).
But can anyone please suggest me why this code:

Code: Select all

def connectToWifi(SSID, PW):
    print(ubinascii.hexlify(network.WLAN().config('mac'),':').decode())
    client = network.WLAN(network.STA_IF)
    client.active(True)
    print(client.scan())
    if not client.isconnected():
        print("Connecting to network...")
        client.connect(SSID, PW)
        while not client.isconnected():
            pass
    print('Connection successful')
    return(client)    

client = connectToWifi("homeSSID", "homepw")
print(client.ifconfig())
print(client.status())
works perfectly on a ESP8266 node MCU an gets stuck in the

Code: Select all

client.connect(SSID, PW)
row in other 3 identical boards?
The boot file is the same in all of them:

Code: Select all

import esp
esp.osdebug(None)
import uos, machine, gc
gc.collect()
All of them work fine when configured as AP.
All the boards correctly see the existing networks when they

Code: Select all

client.scan()
so the hardware is ok.
I deleted and re-inserted all the MAC addresses in my router's ACL to exclude problem on that side.
I'm going nut on this, I re-flashed Micropython on all the boards just to be sure it is ok but nothing changes on any board.
Please, any idea about this?

User avatar
Roberthh
Posts: 2276
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ESP8266 WiFi client

Post by Roberthh » Tue Jan 12, 2021 8:43 pm

Two notes. I do not recommend a busy wait in the loop for wait connected. better add a small delay, like:

Code: Select all

import time
def connectToWifi(SSID, PW):
    print(ubinascii.hexlify(network.WLAN().config('mac'),':').decode())
    client = network.WLAN(network.STA_IF)
    client.active(True)
    print(client.scan())
    if not client.isconnected():
        print("Connecting to network...")
        client.connect(SSID, PW)
        while not client.isconnected():
            time.sleep_ms(100)
    print('Connection successful')
    return(client)    
Since a while I have the issue with the ESP8266 that they only connect to the WiFi STA after a power cycle. Pushing reset is not sufficient. I cannot exactly tell the time or version at which that started, but it could be the change from v1.12 to v1.13.

Post Reply