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
Ping responce stops working after several hours
Port, board and/or hardware
Raspberry Pi Pico W with RP2040; Raspberry Pi Pico 2 W with RP2350
MicroPython version
MicroPython v1.24.0; MicroPython v1.25.0;
Reproduction
- Install RPI_PICO2_W-20250415-v1.25.0.uf2 on Raspberry Pi Pico 2 W.
- Create main.py with script below on device.
- Power on device with USB or batery.
- Wait 10 hours. Do not access the device over the network.
- On PC (in my case Windows 10) run command "ping 192.168.10.241 -t".
# main.py
import network
from time import sleep
from machine import Timer, Pin
led = machine.Pin("LED", machine.Pin.OUT);
wfssid = "xxxxxxxxxx"
wfpass = "xxxxxxxxxx"
wlan = network.WLAN(network.STA_IF);
wlan.active(True);
print(f'Connecting to "{wfssid}" AP. ', end="")
wlan.connect(wfssid, wfpass);
while wlan.isconnected() == False:
sleep(1.0);
print('.', end="");
print(' Done !');
print(wlan.ifconfig())
def cb1sec(timer):
# To be sure that the device is working
led.on()
sleep(0.001);
led.off()
timer1sec = Timer(period=1000, mode=Timer.PERIODIC, callback=cb1sec)
while True:
sleep(10.0);
Expected behaviour
Starts respond on pings immidiately.
Observed behaviour
Starts to respond after 10...60 unsuccessful pings.
Additional Information
The device stops responding to ping after a few hours of operation.
Powered by USB or battery, no USB connection (with USB connection it also sometimes "hangs")
The device "hangs" after 1...10 hours.
During this time, do not access the device over the network!
During "hanging":
- Unable to connect to FTP server on device.
- Ping from device continues to work!
When device is "frozen", you can "wake it up" using command:
ping 192.168.10.241 -t
Initially, the device does not respond to pings, but after 10...60 unsuccessful pings, device starts responding and normal operation of network interface is restored.
See:
Raspberry Pi Pico W network becomes inaccessible when not used for some time #9455
With network.PPP device hangs after several hours of operation #16340
#9455 and #16340 probably have the same root cause.
Not Reproducing on:
MicroPython v1.25.0 on 2025-04-15; ESP module with ESP8266. (ESP8266 Wemos D1 mini)
Code of Conduct
Yes, I agree