@@ -50,12 +50,12 @@ def __init__(self, esp, secrets, status_pixel=None, attempts=2, debug=False):
50
50
:param int attempts: (Optional) Failed attempts before resetting the ESP32 (default=2)
51
51
"""
52
52
# Read the settings
53
- self ._esp = esp
53
+ self .esp = esp
54
54
self .debug = debug
55
55
self .ssid = secrets ['ssid' ]
56
56
self .password = secrets .get ('password' , None )
57
57
self .attempts = attempts
58
- requests .set_interface (self ._esp )
58
+ requests .set_interface (self .esp )
59
59
self .statuspix = status_pixel
60
60
self .pixel_status (0 )
61
61
# pylint: enable=too-many-arguments
@@ -66,26 +66,26 @@ def reset(self):
66
66
"""
67
67
if self .debug :
68
68
print ("Resetting ESP32" )
69
- self ._esp .reset ()
69
+ self .esp .reset ()
70
70
71
71
def connect (self ):
72
72
"""
73
73
Attempt to connect to WiFi using the current settings
74
74
"""
75
75
if self .debug :
76
- if self ._esp .status == adafruit_esp32spi .WL_IDLE_STATUS :
76
+ if self .esp .status == adafruit_esp32spi .WL_IDLE_STATUS :
77
77
print ("ESP32 found and in idle mode" )
78
- print ("Firmware vers." , self ._esp .firmware_version )
79
- print ("MAC addr:" , [hex (i ) for i in self ._esp .MAC_address ])
80
- for access_pt in self ._esp .scan_networks ():
78
+ print ("Firmware vers." , self .esp .firmware_version )
79
+ print ("MAC addr:" , [hex (i ) for i in self .esp .MAC_address ])
80
+ for access_pt in self .esp .scan_networks ():
81
81
print ("\t %s\t \t RSSI: %d" % (str (access_pt ['ssid' ], 'utf-8' ), access_pt ['rssi' ]))
82
82
failure_count = 0
83
- while not self ._esp .is_connected :
83
+ while not self .esp .is_connected :
84
84
try :
85
85
if self .debug :
86
86
print ("Connecting to AP..." )
87
87
self .pixel_status ((100 , 0 , 0 ))
88
- self ._esp .connect_AP (bytes (self .ssid , 'utf-8' ), bytes (self .password , 'utf-8' ))
88
+ self .esp .connect_AP (bytes (self .ssid , 'utf-8' ), bytes (self .password , 'utf-8' ))
89
89
failure_count = 0
90
90
self .pixel_status ((0 , 100 , 0 ))
91
91
except (ValueError , RuntimeError ) as error :
@@ -103,15 +103,15 @@ def create_ap(self):
103
103
Other WiFi devices will be able to connect to the created Access Point
104
104
"""
105
105
failure_count = 0
106
- while not self ._esp .ap_listening :
106
+ while not self .esp .ap_listening :
107
107
try :
108
108
if self .debug :
109
109
print ("Waiting for AP to be initialized..." )
110
110
self .pixel_status ((100 , 0 , 0 ))
111
111
if self .password :
112
- self ._esp .create_ap (bytes (self .ssid , 'utf-8' ), bytes (self .password , 'utf-8' ))
112
+ self .esp .create_ap (bytes (self .ssid , 'utf-8' ), bytes (self .password , 'utf-8' ))
113
113
else :
114
- self ._esp .create_ap (bytes (self .ssid , 'utf-8' ), None )
114
+ self .esp .create_ap (bytes (self .ssid , 'utf-8' ), None )
115
115
failure_count = 0
116
116
self .pixel_status ((0 , 100 , 0 ))
117
117
except (ValueError , RuntimeError ) as error :
@@ -135,7 +135,7 @@ def get(self, url, **kw):
135
135
:return: The response from the request
136
136
:rtype: Response
137
137
"""
138
- if not self ._esp .is_connected :
138
+ if not self .esp .is_connected :
139
139
self .connect ()
140
140
self .pixel_status ((0 , 0 , 100 ))
141
141
return_val = requests .get (url , ** kw )
@@ -154,7 +154,7 @@ def post(self, url, **kw):
154
154
:return: The response from the request
155
155
:rtype: Response
156
156
"""
157
- if not self ._esp .is_connected :
157
+ if not self .esp .is_connected :
158
158
self .connect ()
159
159
self .pixel_status ((0 , 0 , 100 ))
160
160
return_val = requests .post (url , ** kw )
@@ -172,7 +172,7 @@ def put(self, url, **kw):
172
172
:return: The response from the request
173
173
:rtype: Response
174
174
"""
175
- if not self ._esp .is_connected :
175
+ if not self .esp .is_connected :
176
176
self .connect ()
177
177
self .pixel_status ((0 , 0 , 100 ))
178
178
return_val = requests .put (url , ** kw )
@@ -191,7 +191,7 @@ def patch(self, url, **kw):
191
191
:return: The response from the request
192
192
:rtype: Response
193
193
"""
194
- if not self ._esp .is_connected :
194
+ if not self .esp .is_connected :
195
195
self .connect ()
196
196
self .pixel_status ((0 , 0 , 100 ))
197
197
return_val = requests .patch (url , ** kw )
@@ -210,7 +210,7 @@ def delete(self, url, **kw):
210
210
:return: The response from the request
211
211
:rtype: Response
212
212
"""
213
- if not self ._esp .is_connected :
213
+ if not self .esp .is_connected :
214
214
self .connect ()
215
215
self .pixel_status ((0 , 0 , 100 ))
216
216
return_val = requests .delete (url , ** kw )
@@ -226,22 +226,22 @@ def ping(self, host, ttl=250):
226
226
:return: The response time in milliseconds
227
227
:rtype: int
228
228
"""
229
- if not self ._esp .is_connected :
229
+ if not self .esp .is_connected :
230
230
self .connect ()
231
231
self .pixel_status ((0 , 0 , 100 ))
232
- response_time = self ._esp .ping (host , ttl = ttl )
232
+ response_time = self .esp .ping (host , ttl = ttl )
233
233
self .pixel_status (0 )
234
234
return response_time
235
235
236
236
def ip_address (self ):
237
237
"""
238
238
Returns a formatted local IP address, update status pixel.
239
239
"""
240
- if not self ._esp .is_connected :
240
+ if not self .esp .is_connected :
241
241
self .connect ()
242
242
self .pixel_status ((0 , 0 , 100 ))
243
243
self .pixel_status (0 )
244
- return self ._esp .pretty_ip (self ._esp .ip_address )
244
+ return self .esp .pretty_ip (self .esp .ip_address )
245
245
246
246
def pixel_status (self , value ):
247
247
"""
@@ -260,6 +260,6 @@ def signal_strength(self):
260
260
"""
261
261
Returns receiving signal strength indicator in dBm
262
262
"""
263
- if not self ._esp .is_connected :
263
+ if not self .esp .is_connected :
264
264
self .connect ()
265
- return self ._esp .rssi ()
265
+ return self .esp .rssi ()
0 commit comments