@@ -39,11 +39,11 @@ class ESPSPI_WiFiManager:
3939 """
4040 A class to help manage the Wifi connection
4141 """
42- def __init__ (self , esp , settings , status_neopixel = None , attempts = 1 ):
42+ def __init__ (self , esp , settings , status_neopixel = None , attempts = 2 ):
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=1 )
46+ :param int attempts: (Optional) Failed attempts before resetting the ESP32 (default=2 )
4747 :param status_neopixel: (Optional) The neopixel pin - Usually board.NEOPIXEL (default=None)
4848 :type status_neopixel: Pin
4949 """
@@ -60,6 +60,14 @@ def __init__(self, esp, settings, status_neopixel=None, attempts=1):
6060 self .neopix = None
6161 self .neo_status (0 )
6262
63+ def reset (self ):
64+ """
65+ Perform a hard reset on the ESP32
66+ """
67+ if self .debug :
68+ print ("Resetting ESP32\n " , error )
69+ self ._esp .reset ()
70+
6371 def connect (self ):
6472 """
6573 Attempt to connect to WiFi using the current settings
@@ -85,8 +93,7 @@ def connect(self):
8593 failure_count += 1
8694 if failure_count >= self .attempts :
8795 failure_count = 0
88- self ._esp .reset ()
89- print ("Resetting ESP32\n " , error )
96+ self .reset ()
9097 continue
9198
9299 def get (self , url , ** kw ):
@@ -104,16 +111,7 @@ def get(self, url, **kw):
104111 if not self ._esp .is_connected :
105112 self .connect ()
106113 self .neo_status ((100 , 100 , 0 ))
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 )
114+ return_val = requests .get (url , ** kw )
117115 self .neo_status (0 )
118116 return return_val
119117
@@ -132,17 +130,7 @@ def post(self, url, **kw):
132130 if not self ._esp .is_connected :
133131 self .connect ()
134132 self .neo_status ((100 , 100 , 0 ))
135- attempt_count = 0
136- while attempt_count < self .attempts :
137- try :
138- attempt_count += 1
139- return_val = requests .post (url , ** kw )
140- except (ValueError , RuntimeError ) as error :
141- if attempt_count >= self .attempts :
142- attempt_count = 0
143- self ._esp .reset ()
144- print ("Resetting ESP32\n " , error )
145- self .neo_status (0 )
133+ return_val = requests .post (url , ** kw )
146134 return return_val
147135
148136 def put (self , url , ** kw ):
0 commit comments