31
31
32
32
# pylint: disable=no-name-in-module
33
33
34
- import neopixel
35
34
import adafruit_esp32spi
36
35
import adafruit_esp32spi .adafruit_esp32spi_requests as requests
37
36
38
37
class ESPSPI_WiFiManager :
39
38
"""
40
39
A class to help manage the Wifi connection
41
40
"""
42
- def __init__ (self , esp , secrets , status_neopixel = None , attempts = 2 ):
41
+ def __init__ (self , esp , secrets , status_pixel , attempts = 2 ):
43
42
"""
44
43
:param ESP_SPIcontrol esp: The ESP object we are using
45
44
:param dict secrets: The WiFi and Adafruit IO secrets dict (See examples)
45
+ :param status_pixel: (Optional) The pixel device - A NeoPixel or DotStar (default=None)
46
+ :type status_pixel: NeoPixel or DotStar
46
47
:param int attempts: (Optional) Failed attempts before resetting the ESP32 (default=2)
47
- :param status_neopixel: (Optional) The neopixel pin - Usually board.NEOPIXEL (default=None)
48
- :type status_neopixel: Pin
49
48
"""
50
49
# Read the settings
51
50
self ._esp = esp
@@ -54,11 +53,8 @@ def __init__(self, esp, secrets, status_neopixel=None, attempts=2):
54
53
self .password = secrets ['password' ]
55
54
self .attempts = attempts
56
55
requests .set_interface (self ._esp )
57
- if status_neopixel :
58
- self .neopix = neopixel .NeoPixel (status_neopixel , 1 , brightness = 0.2 )
59
- else :
60
- self .neopix = None
61
- self .neo_status (0 )
56
+ self .statuspix = status_pixel
57
+ self .pixel_status (0 )
62
58
63
59
def reset (self ):
64
60
"""
@@ -84,10 +80,10 @@ def connect(self):
84
80
try :
85
81
if self .debug :
86
82
print ("Connecting to AP..." )
87
- self .neo_status ((100 , 0 , 0 ))
83
+ self .pixel_status ((100 , 0 , 0 ))
88
84
self ._esp .connect_AP (bytes (self .ssid , 'utf-8' ), bytes (self .password , 'utf-8' ))
89
85
failure_count = 0
90
- self .neo_status ((0 , 100 , 0 ))
86
+ self .pixel_status ((0 , 100 , 0 ))
91
87
except (ValueError , RuntimeError ) as error :
92
88
print ("Failed to connect, retrying\n " , error )
93
89
failure_count += 1
@@ -110,9 +106,9 @@ def get(self, url, **kw):
110
106
"""
111
107
if not self ._esp .is_connected :
112
108
self .connect ()
113
- self .neo_status ((0 , 0 , 100 ))
109
+ self .pixel_status ((0 , 0 , 100 ))
114
110
return_val = requests .get (url , ** kw )
115
- self .neo_status (0 )
111
+ self .pixel_status (0 )
116
112
return return_val
117
113
118
114
def post (self , url , ** kw ):
@@ -129,7 +125,7 @@ def post(self, url, **kw):
129
125
"""
130
126
if not self ._esp .is_connected :
131
127
self .connect ()
132
- self .neo_status ((0 , 0 , 100 ))
128
+ self .pixel_status ((0 , 0 , 100 ))
133
129
return_val = requests .post (url , ** kw )
134
130
return return_val
135
131
@@ -147,9 +143,9 @@ def put(self, url, **kw):
147
143
"""
148
144
if not self ._esp .is_connected :
149
145
self .connect ()
150
- self .neo_status ((0 , 0 , 100 ))
146
+ self .pixel_status ((0 , 0 , 100 ))
151
147
return_val = requests .put (url , ** kw )
152
- self .neo_status (0 )
148
+ self .pixel_status (0 )
153
149
return return_val
154
150
155
151
def patch (self , url , ** kw ):
@@ -166,9 +162,9 @@ def patch(self, url, **kw):
166
162
"""
167
163
if not self ._esp .is_connected :
168
164
self .connect ()
169
- self .neo_status ((0 , 0 , 100 ))
165
+ self .pixel_status ((0 , 0 , 100 ))
170
166
return_val = requests .patch (url , ** kw )
171
- self .neo_status (0 )
167
+ self .pixel_status (0 )
172
168
return return_val
173
169
174
170
def delete (self , url , ** kw ):
@@ -185,9 +181,9 @@ def delete(self, url, **kw):
185
181
"""
186
182
if not self ._esp .is_connected :
187
183
self .connect ()
188
- self .neo_status ((0 , 0 , 100 ))
184
+ self .pixel_status ((0 , 0 , 100 ))
189
185
return_val = requests .delete (url , ** kw )
190
- self .neo_status (0 )
186
+ self .pixel_status (0 )
191
187
return return_val
192
188
193
189
def ping (self , host , ttl = 250 ):
@@ -201,17 +197,17 @@ def ping(self, host, ttl=250):
201
197
"""
202
198
if not self ._esp .is_connected :
203
199
self .connect ()
204
- self .neo_status ((0 , 0 , 100 ))
200
+ self .pixel_status ((0 , 0 , 100 ))
205
201
response_time = self ._esp .ping (host , ttl = ttl )
206
- self .neo_status (0 )
202
+ self .pixel_status (0 )
207
203
return response_time
208
204
209
- def neo_status (self , value ):
205
+ def pixel_status (self , value ):
210
206
"""
211
207
Change Status NeoPixel if it was defined
212
208
213
209
:param value: The value to set the Board's Status NeoPixel to
214
210
:type value: int or 3-value tuple
215
211
"""
216
- if self .neopix :
217
- self .neopix .fill (value )
212
+ if self .statuspix :
213
+ self .statuspix .fill (value )
0 commit comments