Debugging wifi connectivity

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
amartino
Posts: 6
Joined: Mon Feb 20, 2017 11:00 am

Debugging wifi connectivity

Post by amartino » Fri Feb 24, 2017 9:27 am

Hi there,
I've suddenly experienced that most all three ESP8266 boards (WeMod D1 mini) have stopped connecting to the Wifi. Below is the code, stripped to the network related parts, that was successfully used to connect before:

Code: Select all

import network

sta_if = network.WLAN(network.STA_IF)
ap_if = network.WLAN(network.AP_IF)

ap_if.active(False)
sta_if.active(True)
sta_if.connect('o2-WLAN42', '94796AV9436KQQN3')

while not sta_if.isconnected(): pass

print('Connected to wireless')
I'm checking in parallel that there wasn't something changes with the access point, though all my other devices aren't having issues connecting.

Code: Select all

>>> sta_if.active()
True
>>> sta_if.status()
4
>>> sta_if.ifconfig()
('0.0.0.0', '0.0.0.0', '0.0.0.0', '208.67.222.222')
>>> sta_if.isconnected()
False
>>> sta_if.scan()
[(b'CORRECT-SSID', b'L\t\xd4,\x82\x9a', 10, -89, 3, 0)]
The status description can be found https://docs.micropython.org/en/latest/ ... twork.html. Based on that, the reason the connection is failing (4) is:

Code: Select all

STAT_CONNECT_FAIL – failed due to other problems
Tried to see what kind of error would Arduino give. Ended up with a similar

Code: Select all

WL_CONNECT_FAILED = 4
Ref. https://github.com/esp8266/Arduino/blob ... initions.h
  • Could you please point me to the source for the network module?
  • Other suggestions how to approach the problem from the esp8266 side.

amartino
Posts: 6
Joined: Mon Feb 20, 2017 11:00 am

Re: Debugging wifi connectivity

Post by amartino » Sun Feb 26, 2017 1:17 pm

I've just discovered something peculiar :)

The code below:

Code: Select all

import machine
import network
import time
from umqtt.simple import MQTTClient

led = machine.Pin(D1, machine.Pin.OUT)
button = machine.Pin(D0, machine.Pin.IN)
sta_if = network.WLAN(network.STA_IF)
ap_if = network.WLAN(network.AP_IF)

ap_if.active(False)
sta_if.active(True)
sta_if.connect('my-SSID', 'my-password')

while not sta_if.isconnected(): 
    time.sleep_ms(1000)
    print("Still connecting to Wireless")

print('Connected to wireless')

client = MQTTClient("esp-reciever", "192.168.1.142")
time.sleep_ms(1000)
client = MQTTClient("esp-reciever", "192.168.1.142")
client.connect()

once_presset = False

while True:
    time.sleep_ms(20)
    if button.value() == 1 and once_pressed == False:
        led.value(1)
        client.publish(b"/lopy", b"Button on")
        once_pressed = True
        print

    if button.value() == 0 :
        led.value(0)
        once_pressed = False
Manages to kill my routers ability to accept new devices into the WiFi network. Once I restart the router new devices can again be connected. I've copied the exact same code with which I managed to cause it. Will update once I have the filtered reason.
Will try to set a dedicated AP on my laptop to see whats happening on the other side.

Post Reply