@@ -39,11 +39,11 @@ class ESPSPI_WiFiManager:
39
39
"""
40
40
A class to help manage the Wifi connection
41
41
"""
42
- def __init__ (self , esp , settings , status_neopixel = None , attempts = 1 ):
42
+ def __init__ (self , esp , settings , status_neopixel = None , attempts = 2 ):
43
43
"""
44
44
:param ESP_SPIcontrol esp: The ESP object we are using
45
45
: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 )
47
47
:param status_neopixel: (Optional) The neopixel pin - Usually board.NEOPIXEL (default=None)
48
48
:type status_neopixel: Pin
49
49
"""
@@ -60,6 +60,14 @@ def __init__(self, esp, settings, status_neopixel=None, attempts=1):
60
60
self .neopix = None
61
61
self .neo_status (0 )
62
62
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
+
63
71
def connect (self ):
64
72
"""
65
73
Attempt to connect to WiFi using the current settings
@@ -85,8 +93,7 @@ def connect(self):
85
93
failure_count += 1
86
94
if failure_count >= self .attempts :
87
95
failure_count = 0
88
- self ._esp .reset ()
89
- print ("Resetting ESP32\n " , error )
96
+ self .reset ()
90
97
continue
91
98
92
99
def get (self , url , ** kw ):
@@ -104,16 +111,7 @@ def get(self, url, **kw):
104
111
if not self ._esp .is_connected :
105
112
self .connect ()
106
113
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 )
117
115
self .neo_status (0 )
118
116
return return_val
119
117
@@ -132,17 +130,7 @@ def post(self, url, **kw):
132
130
if not self ._esp .is_connected :
133
131
self .connect ()
134
132
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 )
146
134
return return_val
147
135
148
136
def put (self , url , ** kw ):
0 commit comments