Pi Pico W hangs with "Exception in uplink reconnection loop"

Hi Meredydd,
Thanks for the great example. I got it working. But after about 5 minutes the Pi Pico W hangs up and I get this error message in Thonny:

Connecting to Anvil…
Exception in uplink reconnection loop:
Traceback (most recent call last):
File “anvil/pico.py”, line 152, in _connect_async
File “anvil/pico.py”, line 110, in _connect
File “async_websocket_client.py”, line 94, in handshake
OSError: [Errno 12] ENOMEM

What can you do there?

How can I now install a watchdog?
If the Pico W gets stuck.

With sunny greetings from Freiburg, Germany

Konrad

P.S

#main.py
import anvil.pico
import uasyncio as a
from machine import Pin, I2C

from time import sleep
from dht import DHT11
from pico_i2c_lcd import I2cLcd

i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)

I2C_ADDR = i2c.scan()[0]

lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)

lcd.backlight_off()
lcd.blink_cursor_on()

UPLINK_KEY = “”

Initialisierung GPIO und DHT11

dht11_sensor = DHT11(Pin(14, Pin.IN, Pin.PULL_UP))

@anvil.pico.callable(is_async=True)
async def dht11data():
dht11_sensor.measure()
temp = round(dht11_sensor.temperature(),1)
hum = round(dht11_sensor.humidity(),1)
data = ("Temperatur: {}°C\nLuftfeuchtigkeit: {:.0f}% ".format(temp, hum))
print(data)
return data

@anvil.pico.callable(is_async=True)
async def show_message(message):
for i in range(3):
lcd.backlight_on()
sleep(0.2)
lcd.backlight_off()
sleep(0.2)
lcd.backlight_on()
lcd.putstr(message)
sleep(10)
lcd.clear()
lcd.backlight_off()

anvil.pico.connect(UPLINK_KEY)

#boot.py
#############################################

Provide your Wifi connection details here

#############################################

WIFI_SSID = “****"
WIFI_PASSWORD = "

#############################################

import network
from time import sleep
from machine import Pin
import ntptime

sleep(1) # Without this, the USB handshake seems to break this script and then fail sometimes.

led = Pin(“LED”, Pin.OUT, value=1)

wlan = None
while not wlan or wlan.status() != 3:
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASSWORD)

# Blink LED slowly until the Wifi is connected.

while True:
    print(wlan)
    led.toggle()
    sleep(0.2)
    if wlan.status() in [-1, -2, 3]:
        break

Set the RTC to the current time

ntptime.settime()

Solid LED means we’re connected and ready to go

led.on()
print(wlan)

Hi Meredydd,
and the app shows this error message:

This app ha s experienced an error

UplinkDisconnectedError: The uplink server for “dht11data” has been disconnected

No Idea, but could it have something to do with the Pico going into low-power mode interfering with the WiFi?

I have not had a chance to test mine yet I just got one a few days ago…

I’m only wondering because you say it happens after running for a short amount of time.

I have a similar problem for which I opened an issue on the Github repo. My issue is that the program goes to sleep after a couple of seconds of no input. This is ok. However, when it tries to reconnect, it successfully connects to anvil (printing "Authenticated to app xxxxxxxx), but fails to run the main program . This behavior is the same with both the on_first_connect and on_every_connect arguments.

Hi @vtt-info,

What version of the firmware are you using? This looks like a (memory leak) bug that’s been fixed in the latest version.

@edmondssesay sounds like a different problem - could you start a separate thread, and provide some example code to demonstrate what you’re trying and what’s going wrong?

Btw, I’m using v0.1.2, the latest in the repo. Ok, will open another thread and post my code there.