When I turn on the wifi station and wifi AP at the same time in esp32, the newly created thread cannot run.
When I turn on the wifi station and wifi AP at the same time in esp32, the newly created thread cannot run. It is tested in multiple versions of firmware. What is the reason?
boot.py:
import network
import jsondb
import gc
import json
import machine
import time
import _thread
import urequests
machine.freq(240000000)
jsondb.read()
sta_if = network.WLAN(network.STA_IF);
sta_if.active(True)
sta_if.connect(jsondb.data["sta_ssid"],jsondb.data["sta_pass"])
ap_if = network.WLAN(network.AP_IF)
ap_if.active(True)
ap_if.config(essid=jsondb.data["ap_ssid"], authmode=network.AUTH_WPA_WPA2_PSK, password=jsondb.data["ap_pass"])
def th_ota() :
print("[ OTA ] task start.")
while True :
if sta_if.isconnected() :
break
time.sleep(1)
print("[ OTA ] Checking OTA update...")
base = "http://192.168.1.1/ota/"
updatelist = urequests.get(base + "uplist.json")
info = json.loads(updatelist.text)
version = jsondb.data["version"]
print("[ OTA ] local version : {} , cloud version : {}".format(version,info["version"]))
if info["version"] != version:
jsondb.data.update({"version":info["version"]})
jsondb.write()
print("[ OTA ] new version detect {}".format(info["version"]))
for i in info["files"] :
resp = urequests.get(url=base + i, stream=True)
print("OTA update {}...".format(i))
if type(resp.raw) != None :
f = open(i,"wb")
while True :
gc.collect()
content = resp.raw.read(8192)
if content == b"" :
f.close()
break
f.write(content)
print("[ OTA ] Reset machine.")
machine.reset()
else:
print("[ OTA ] version not change.")
_thread.start_new_thread(th_ota,())
ESP32 wifi issues
Port, board and/or hardware
ESP32
MicroPython version
esp32-20220618-v1.19.1.bin
Reproduction
Issue No.1:On startup
Issue No.2:On startup / while running
Expected behaviour
Connected to the wifi smooth and keep that.
Observed behaviour
Issue No.1: "Wifi internal error" occurs. After power off and on, sometimes it works but mostly not. Once it gets recovered, it keep working without any error which looks strange for me. Just adding print(anything) may have solved...
Issue No.2:I'm using 30+ ESP32 with micropython. Most of them connect wifi smooth and keep it. But some 1 or 2 of them suddenly start struggling to connect wifi when start up(cannot connect even after the reboot, unplug power and plug) or lose connection when it's working. But after a while, it works completely normal. The boards which have this issue is random.
(1)This is the code to connect wifi.
"""Wifi"""
def connect_wifi(ssid, passkey, timeout=5):
global speed_filtered, bias, speed_raw
wifi= network.WLAN(network.STA_IF)
wifi.active(False)
time.sleep(1)
wifi.active(True)
wifi.connect(ssid, passkey)
start = time.time()
start_count = time.time()
while not wifi.isconnected():
print('*')
time.sleep(1)
if time.time()-start > timeout:
wifi.disconnect()
time.sleep(1)
wifi.connect(ssid, passkey)
start = time.time()
if wifi.isconnected():
print('Connected')
print(time.time() - start_count)
return wifi
.
(2) this is the code to check wifi status. if it's not connected, it try to reconnect.
if wifi.isconnected():
if wifi_strength > 80:
wifi_strength_category = 4
elif wifi_strength > 60:
wifi_strength_category = 3
elif wifi_strength > 40:
wifi_strength_category = 2
else:
wifi_strength_category = 1
else:
wifi = connect_wifi(SSID_NAME, SSID_PASS)
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree