Fix PyPlanter; update other catches of requests exceptions

This commit is contained in:
Dan Halbert 2022-07-26 18:20:19 -04:00
parent 24436a1ea7
commit 9eb5844d4c
40 changed files with 51 additions and 50 deletions

View file

@ -168,7 +168,7 @@ while True:
# Hourly reset
if cur_time.tm_min == 0:
prv_mins = 0
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Failed to fetch time, retrying\n", e)
wifi.reset()
wifi.connect()
@ -200,7 +200,7 @@ while True:
io.send_data(feed_temperature["key"], str(temperature))
io.send_data(feed_humidity["key"], str(humidity))
print("Published!")
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Failed to send data to IO, retrying\n", e)
wifi.reset()
wifi.connect()

View file

@ -129,7 +129,7 @@ client.subscribe(feed_relay)
while True:
try: # Poll for new messages on feed_relay
client.loop()
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Failed to get data, retrying\n", e)
wifi.reset()
client.reconnect()

View file

@ -169,7 +169,7 @@ while True:
print("Published!")
prv_sensor_value = sensor_value
start_time = now
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Failed to get data, retrying\n", e)
wifi.reset()
client.reconnect()

View file

@ -141,7 +141,7 @@ io.get("relay")
while True:
try:
io.loop()
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Failed to get data, retrying\n", e)
wifi.reset()
io.reconnect()

View file

@ -51,7 +51,7 @@ while True:
try:
value = matrixportal.fetch()
print("Response is", value)
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occured, retrying! -", e)
time.sleep(3 * 60) # wait 3 minutes

View file

@ -216,8 +216,8 @@ while True:
device.loop()
# if something disrupts the loop, reconnect
# pylint: disable=broad-except
except (ValueError, RuntimeError, OSError, Exception) as e:
print("Connection error, reconnecting\n", str(e))
except (ValueError, RuntimeError, OSError, ConnectionError) as e:
print("Network error, reconnecting\n", str(e))
supervisor.reload()
continue
# delay

View file

@ -36,6 +36,6 @@ while True:
try:
value = magtag.fetch()
print("Response is", value)
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occured, retrying! -", e)
timestamp = time.monotonic()

View file

@ -43,6 +43,6 @@ while True:
magtag.peripherals.neopixels.fill(color)
external_pixels.fill(color)
timestamp = time.monotonic()
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occured, retrying! -", e)
time.sleep(1)

View file

@ -137,7 +137,7 @@ while True:
)
timestamp = time.monotonic()
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
# Catch any random errors so the code will continue running.
print("Some error occured, retrying! -", e)
try:

View file

@ -60,7 +60,7 @@ while True:
seconds = int(datetime_str[17:19])
rtc.RTC().datetime = time.struct_time((year, month, mday, hours, minutes, seconds, 0, 0, False))
lasttimefetch_stamp = time.monotonic()
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occured, retrying! -", e)
continue

View file

@ -95,7 +95,7 @@ try:
# OK we're done!
magtag.peripherals.neopixels.fill(0x000F00) # greten
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occured, trying again later -", e)
time.sleep(2) # let screen finish updating

View file

@ -112,7 +112,7 @@ try:
SECONDS_TO_SLEEP = 24 * 60 * 60 # Sleep for one day
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occured, retrying in one hour! -", e)
seconds_to_sleep = 60 * 60 # Sleep for one hour

View file

@ -95,5 +95,5 @@ while True:
PAUSE = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + 60 * 60)
alarm.exit_and_deep_sleep_until_alarms(PAUSE)
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occured, retrying! -", e)

View file

@ -43,7 +43,7 @@ while True:
qn_idx = header.index("Queens")
si_idx = header.index("Staten Island")
nyc_idx = header.index("Citywide")
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occured, retrying! -", e)
continue

View file

@ -85,6 +85,6 @@ try:
progress_bar.progress = value[1] / 100.0
magtag.refresh()
magtag.exit_and_deep_sleep(24 * 60 * 60) # one day
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occurred, retrying! -", e)
magtag.exit_and_deep_sleep(60) # one minute

View file

@ -67,6 +67,6 @@ try:
print(now)
magtag.exit_and_deep_sleep(24 * 60 * 60) # one day
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occurred, retrying after 1 minute! -", e)
magtag.exit_and_deep_sleep(60) # one minute

View file

@ -48,7 +48,7 @@ try:
magtag.network.connect()
value = magtag.fetch()
print("Response is", value)
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
magtag.set_text(e)
print("Some error occured, retrying later -", e)
# wait 2 seconds for display to complete

View file

@ -50,7 +50,7 @@ try:
magtag.network.connect()
value = magtag.fetch()
print("Response is", value)
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
magtag.set_text(e)
print("Some error occured, retrying! -", e)

View file

@ -95,7 +95,7 @@ try:
# This statement gets the JSON data and displays it automagically
value = magtag.fetch()
print("Response is", value)
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occured, retrying! -", e)
# wait 2 seconds for display to complete

View file

@ -68,7 +68,7 @@ magtag.preload_font()
try:
value = magtag.fetch()
print("Response is", value)
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occured, retrying! -", e)
time.sleep(2)

View file

@ -172,6 +172,6 @@ while True:
# Reset timer
initial = now
aws_iot.loop()
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Failed to get data, retrying", e)
wifi.reset()

View file

@ -88,7 +88,7 @@ while True:
io.send_data(light_feed['key'], light_value)
io.send_data(temperature_feed['key'], temperature, precision=2)
print('Sent to Adafruit IO!')
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Failed to get data, retrying\n", e)
wifi.reset()
continue

View file

@ -97,7 +97,7 @@ while True:
gfx.display_azure_status("Data sent!")
print("Data sent!")
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Failed to get data, retrying\n", e)
wifi.reset()
wifi.connect()

View file

@ -42,7 +42,7 @@ while True:
try:
value = pyportal.fetch()
print("Response is", value)
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occured, retrying! -", e)
time.sleep(3*60) # wait 3 minutes

View file

@ -46,7 +46,7 @@ while True:
try:
value = pyportal.fetch()
print("Response is", value)
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occured, retrying! -", e)
time.sleep(3*60) # wait 3 minutes

View file

@ -189,7 +189,7 @@ while True:
# Reset timer
initial = now
google_mqtt.loop()
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, OSError, ConnectionError) as e:
print("Failed to get data, retrying", e)
wifi.reset()
google_mqtt.reconnect()

View file

@ -51,7 +51,7 @@ while True:
print("New star!")
pyportal.play_file(cwd+"/coin.wav")
last_value = value
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occured, retrying! -", e)
time.sleep(60) # wait a minute before getting again

View file

@ -104,7 +104,7 @@ while True:
text_label.text = 'sending...'
# send data to Adafruit IO (rounded to one decimal place)
io.send_data(weight_feed['key'], round(reading.weight, 1))
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("failed to send data..retrying...")
wifi.reset()
continue

View file

@ -52,7 +52,7 @@ while True:
print("New level!")
pyportal.play_file(cwd+"/triode_low_fade.wav")
last_value = value
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occurred, retrying! -", e)
#check again in two minutes
time.sleep(60*2)

View file

@ -90,7 +90,7 @@ while True:
refresh_time = time.monotonic()
# set the_time
the_time = time.localtime()
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Failed to get data, retrying\n", e)
esp.reset()
continue

View file

@ -119,7 +119,7 @@ while True:
refresh_time = time.monotonic()
# set the_time
the_time = time.localtime()
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Failed to get data, retrying\n", e)
esp.reset()
continue

View file

@ -34,6 +34,6 @@ while True:
try:
value = pyportal.fetch()
print("Response is", value)
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occured, retrying! -", e)
time.sleep(60)

View file

@ -42,7 +42,7 @@ while True:
print("New subscriber!")
pyportal.play_file(cwd+"/coin.wav")
last_value = value
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occured, retrying! -", e)
time.sleep(60)

View file

@ -88,7 +88,7 @@ def getchannels():
channel_dict[name] = chan_id
response.close()
return channel_dict
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Failed to get data\n", e)
wifi.reset()
return None
@ -104,7 +104,7 @@ def sendkey(key):
if response:
response.close()
print("OK")
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Failed to get data\n", e)
wifi.reset()
return
@ -119,7 +119,7 @@ def sendletter(letter):
if response:
response.close()
print("OK")
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Failed to get data\n", e)
wifi.reset()
return
@ -135,8 +135,8 @@ def openchannel(channel):
response.close()
print("OK")
response = None
except (ValueError, RuntimeError):
print("Probably worked")
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Probably worked, but got error\n", e)
wifi.reset()
response = None

View file

@ -105,7 +105,7 @@ while True:
gfx.display_io_status('Data sent!')
except AdafruitIO_RequestError as e:
raise AdafruitIO_RequestError('IO Error: ', e)
except (ValueError, RuntimeError) as e: # WiFi Connection Failure
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Failed to get data, retrying\n", e)
wifi.reset()
continue

View file

@ -45,7 +45,7 @@ while True:
print("New follower!")
pyportal.play_file(cwd+"/coin.wav") # uncomment make a noise!
last_value = value
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Some error occured, retrying! -", e)
time.sleep(60) # wait a minute before getting again

View file

@ -82,7 +82,7 @@ while True:
try:
json_payload = pyportal.fetch()
raw_data = json.loads(json_payload)
except (ValueError, RuntimeError) as ex:
except (ValueError, RuntimeError, ConnectionError, OSError) as ex:
print('Error: ', ex)
if isinstance(ex, ValueError):
print('JSON:', json_payload)

View file

@ -439,7 +439,7 @@ while True:
else:
pass
gc.collect()
except (ValueError, RuntimeError) as err:
except (ValueError, RuntimeError, ConnectionError, OSError) as err:
print("Failed to get data, retrying\n", err)
wifi.reset()
mqtt_client.reconnect()

View file

@ -23,7 +23,8 @@ from simpleio import map_range
#---| User Config |---------------
# How often to poll the soil sensor, in seconds
DELAY_SENSOR = 30
# Polling every 30 seconds or more may cause connection timeouts
DELAY_SENSOR = 15
# How often to send data to adafruit.io, in minutes
DELAY_PUBLISH = 5
@ -179,7 +180,7 @@ label_status.text = "Connecting..."
while not esp.is_connected:
try:
wifi.connect()
except RuntimeError as e:
except (RuntimeError, ConnectionError) as e:
print("could not connect to AP, retrying: ",e)
wifi.reset()
continue
@ -269,7 +270,7 @@ while True:
# to keep the connection active
try:
io.loop()
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Failed to get data, retrying...\n", e)
wifi.reset()
continue
@ -314,7 +315,7 @@ while True:
# reset timer
initial = now
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
label_status.text = "ERROR!"
print("Failed to get data, retrying...\n", e)
wifi.reset()

View file

@ -136,7 +136,7 @@ while True:
print('Data sent!')
except AdafruitIO_RequestError as e:
raise AdafruitIO_RequestError('IO Error: ', e)
except (ValueError, RuntimeError) as e:
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
print("Failed to get data, retrying\n", e)
wifi.reset()
continue