I'm working on debugging this script. It's been a slow process since I can't run serial in VScode.
It's collecting moisture readings and then sending them to a Adafruit IO feed through a POST. I found my way around th 113 errors from urequests
, but now I'm getting OSerror 118
. I guess this indicates the wifi isn't connected.
I'm using wifiCfg
's doConnect function in a while loop in hopes that it will keep trying until it works. This works on an initial run, but it looks like it fails after a lightsleep.
Does anyone have any idea about how I can get the wifi to connect more reliably? What am I missing?
while(True):
gc.collect()
while not wifiCfg.doConnect('guest', '12345678', lcdShow=True): pass
lcd.clear()
lcd.setTextColor(0xaaaaaa, lcd.BLACK)
lcd.font(lcd.FONT_DejaVu18)
axp.setLcdBrightness(50)
test.display(int(get_moisture()/10))
wait(2)
moisture = get_moisture() #get moisture
try:
response = urequests.request(
method='POST',
url='http://io.adafruit.com/api/v2/********/feeds/moisture/data',
json={'value':moisture},
headers={'Content-Type':'application/json','X-AIO-Key':'**************************'}
)
if response.status_code == 200:
led.duty(99)
lcd.clear()
lcd.print("sent", lcd.CENTER, 5)
lcd.image(0, 50, 'img/success.jpg')
wait(1)
axp.setLDO2Volt(0)
else:
lcd.print("request \r\n error", lcd.CENTER, 0, 0xFFFFFF)
lcd.image(0, 50, 'img/error.jpg')
led.duty(50)
wait(10)
except Exception as e:
lcd.print("OS error", lcd.CENTER, 0, 0xFFFFFF)
lcd.image(0, 50, 'img/error.jpg')
print(e)
gc.collect()
lightsleep(60*1000)