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)