rp2: Accept not responding on Pico W after 5 mins
Port, board and/or hardware
Raspberry Pi Pico W
MicroPython version
MicroPython v1.23.0 on 2024-06-02; Raspberry Pi Pico W with RP2040
Reproduction
import network
import socket
import time
ssid = 'SSID'
password = 'PASSWORD'
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
while not wlan.isconnected():
time.sleep(1)
print("Connected", wlan.ifconfig()[0])
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(addr)
s.listen(1)
while True:
cl, addr = s.accept()
request = cl.recv(1024)
cl.send("HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n")
cl.send("<html><body>{}</body></html>".format(time.time()))
cl.close()
Expected behaviour
I expected the Pico W to accept requests and respond with the time (single integer) indefinitely.
Observed behaviour
Running the example code (which is a simplified version of the webserver example on the RPI site) I can send requests from FIrefox to thePico W ip address and get an imediate response. If the Pico W is left about 5 minutes or more with receiving a request then it no longer appears to accept on he socket.
Additional Information
If I put a timeout on the socket of 30 seconds the Pico W works for longer than 5 minutes but does eventually stop responding.
Putting a line into the html so that it refeshes every minute will keep the Pico responding for hours.
Code of Conduct
Yes, I agree
RP2: Pico 2 W Not connecting with thread running
Port, board and/or hardware
RP2 - Pico 2 W
MicroPython version
MicroPython v1.25.0-preview.229.g0d46e45a1 on 2025-01-27; Raspberry Pi Pico 2 W with RP2350
Reproduction
import time
import _thread
import urequests
SSID = ""
password = ""
def connect_normal():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, password)
print("Connecting to network")
start_time = time.time()
while not wlan.isconnected() and time.time() - start_time < 20:
print("Waiting for connection...")
time.sleep(2)
if wlan.isconnected():
print("Connected to network")
else:
print("Failed to connect to network")
print("Sleep for 2 seconds")
time.sleep(2)
wlan.disconnect()
def main_thread():
connect_normal()
def second_thread():
for (i) in range(10):
print("Second thread")
time.sleep(2)
_thread.start_new_thread(second_thread, ())
main_thread()
Other things tested but not working:
- Extending the 20-second time limit.
- Putting
wlan = network.WLAN(network.STA_IF),wlan.active(True), andwlan.connect(SSID, password)before starting a thread. - Switching the functions
connection_normalandsecond_threadto run in the other thread. So the connection is made on the newly opened thread. - Building firmware with the latest Pico SDK develop
- Adding
rp2.country("NL")andnetwork.country(country).
Expected behaviour
Expected to connect to the network and print Connected to network.
Observed behaviour
No connection is established after the set time of 20 seconds. (Time is irrelevant as it never seems to connect). When the line _thread.start_new_thread(second_thread, ()) is commented out, a connection is found almost every single time.
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree