Skip to content

Commit cd63372

Browse files
author
Melissa LeBlanc-Williams
committed
Added reset to the get and post methods on error
1 parent 3034250 commit cd63372

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

adafruit_esp32spi/adafruit_esp32spi_wifimanager.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, esp, settings, status_neopixel=None, attempts=1):
4343
"""
4444
:param ESP_SPIcontrol esp: The ESP object we are using
4545
:param dict settings: The WiFi and Adafruit IO Settings (See examples)
46-
:param int attempts: (Optional) Failed attempts before resetting the ESP32 (default=3)
46+
:param int attempts: (Optional) Failed attempts before resetting the ESP32 (default=1)
4747
:param status_neopixel: (Optional) The neopixel pin - Usually board.NEOPIXEL (default=None)
4848
:type status_neopixel: Pin
4949
"""
@@ -104,7 +104,16 @@ def get(self, url, **kw):
104104
if not self._esp.is_connected:
105105
self.connect()
106106
self.neo_status((100, 100, 0))
107-
return_val = requests.get(url, **kw)
107+
attempt_count = 0
108+
while attempt_count < self.attempts:
109+
try:
110+
attempt_count += 1
111+
return_val = requests.get(url, **kw)
112+
except(ValueError, RuntimeError) as error:
113+
if attempt_count >= self.attempts:
114+
attempt_count = 0
115+
self._esp.reset()
116+
print("Resetting ESP32\n", error)
108117
self.neo_status(0)
109118
return return_val
110119

0 commit comments

Comments
 (0)