Understood - I have a watchdog that resets the board if I dont get network traffic for 10 minutes... but let me be clear as to my issue:
I have several (10) Adafruit QT Py ESP32-C3 WiFi Dev Boards and when they don't connect, they don't connect with gusto - in fact the one I have on my bench now NEVER connects. When they disconnect there seems to be a 30% chance that they'll need to be monkeyed with (re-flash, re-upload- disconnect power and futs in general till it comes back). Theyre horrifically unreliable connecting, and the one I have here is 8 feet from an AP.
Code: Select all
import network
import utime
import machine
sta_if = network.WLAN(network.STA_IF)
def connect():
count = 0
sta_if.active(True)
utime.sleep(0.1) # this could be important, recent posting by robert-hh
# seems more reliable to start with a fresh connect()
if sta_if.isconnected():
sta_if.disconnect()
print (f'started in the connected state, but now disconnected')
else:
print (f'started in the disconnected state')
utime.sleep(0.1) # this could be important
if not sta_if.isconnected():
print (f'connecting to hotspot...')
utime.sleep(0.1)
try:
# sta_if.ifconfig((config.WiFi_device, '255.255.255.0', config.gateway, '8.8.8.8'))
# another recent posting suggest that this should go after the call to sta_if.connect()
sta_if.connect("LAURENSON", "sekret is here")
except OSError as error:
try:
with open('errors.txt', 'a') as outfile:
outfile.write(str(error) + '\n')
except OSError:
pass
while (count < 10):
count += 1
if (sta_if.isconnected()):
count = 0
print (f'network config: {sta_if.ifconfig()}')
break
print (f'. ')
utime.sleep(1)
if (count == 10):
try:
with open('errors.txt', 'a') as outfile:
outfile.write('failed to connect after 10 tries' + '\n')
except Exception as e:
pass
disconnect() # or you could get errors
print (f'machine reset')
utime.sleep(0.1)
machine.reset() # start from scratch
rssi = sta_if.status('rssi')
print (f'RSSI = {rssi} dBm')
utime.sleep(0.1)
if ((rssi < -95) or (rssi == 0)):
print (f'signal level is below -95dBm')
utime.sleep(0.1)
disconnect() # or you could get errors
print (f'machine reset')
utime.sleep(0.1)
machine.reset() # start from scratch
def disconnect():
sta_if.disconnect()
sta_if.active(False)
connect()
and the result (with known good code, running [for the moment] on 8 other devices) is that this device never connects.
Code: Select all
MPY: soft reboot
started in the disconnected state
connecting to hotspot...
.
.
.
.
.
.
.
.
.
.
machine reset
ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0xc (RTC_SW_CPU_RST),boot:0xf (SPI_FAST_FLASH_BOOT)
Saved PC:0x403806e6
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0xe3c
load:0x403ce000,len:0x6dc
load:0x403d0000,len:0x28ac
entry 0x403ce000
started in the disconnected state
connecting to hotspot...
.
.
.
.
.
.
.
.
.
.
machine reset
ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0xc (RTC_SW_CPU_RST),boot:0xf (SPI_FAST_FLASH_BOOT)
Saved PC:0x403806e6
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0xe3c
load:0x403ce000,len:0x6dc
load:0x403d0000,len:0x28ac
entry 0x403ce000
started in the disconnected state
connecting to hotspot...
.
.
.
.
.
.
.
.
.
.
machine reset
ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0xc (RTC_SW_CPU_RST),boot:0xf (SPI_FAST_FLASH_BOOT)
Saved PC:0x403806e6
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0xe3c
load:0x403ce000,len:0x6dc
load:0x403d0000,len:0x28ac
entry 0x403ce000
started in the disconnected state
connecting to hotspot...
.
.
.
.
.
.
.
.
.
.
machine reset
ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0xc (RTC_SW_CPU_RST),boot:0xf (SPI_FAST_FLASH_BOOT)
Saved PC:0x403806e6
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0xe3c
load:0x403ce000,len:0x6dc
load:0x403d0000,len:0x28ac
entry 0x403ce000