@@ -48,12 +48,12 @@ def __init__(self, esp, secrets, status_pixel=None, attempts=2):
48
48
:param int attempts: (Optional) Failed attempts before resetting the ESP32 (default=2)
49
49
"""
50
50
# Read the settings
51
- self ._esp = esp
51
+ self .esp = esp
52
52
self .debug = False
53
53
self .ssid = secrets ['ssid' ]
54
54
self .password = secrets ['password' ]
55
55
self .attempts = attempts
56
- requests .set_interface (self ._esp )
56
+ requests .set_interface (self .esp )
57
57
self .statuspix = status_pixel
58
58
self .pixel_status (0 )
59
59
@@ -63,26 +63,26 @@ def reset(self):
63
63
"""
64
64
if self .debug :
65
65
print ("Resetting ESP32" )
66
- self ._esp .reset ()
66
+ self .esp .reset ()
67
67
68
68
def connect (self ):
69
69
"""
70
70
Attempt to connect to WiFi using the current settings
71
71
"""
72
72
if self .debug :
73
- if self ._esp .status == adafruit_esp32spi .WL_IDLE_STATUS :
73
+ if self .esp .status == adafruit_esp32spi .WL_IDLE_STATUS :
74
74
print ("ESP32 found and in idle mode" )
75
- print ("Firmware vers." , self ._esp .firmware_version )
76
- print ("MAC addr:" , [hex (i ) for i in self ._esp .MAC_address ])
77
- for access_pt in self ._esp .scan_networks ():
75
+ print ("Firmware vers." , self .esp .firmware_version )
76
+ print ("MAC addr:" , [hex (i ) for i in self .esp .MAC_address ])
77
+ for access_pt in self .esp .scan_networks ():
78
78
print ("\t %s\t \t RSSI: %d" % (str (access_pt ['ssid' ], 'utf-8' ), access_pt ['rssi' ]))
79
79
failure_count = 0
80
- while not self ._esp .is_connected :
80
+ while not self .esp .is_connected :
81
81
try :
82
82
if self .debug :
83
83
print ("Connecting to AP..." )
84
84
self .pixel_status ((100 , 0 , 0 ))
85
- self ._esp .connect_AP (bytes (self .ssid , 'utf-8' ), bytes (self .password , 'utf-8' ))
85
+ self .esp .connect_AP (bytes (self .ssid , 'utf-8' ), bytes (self .password , 'utf-8' ))
86
86
failure_count = 0
87
87
self .pixel_status ((0 , 100 , 0 ))
88
88
except (ValueError , RuntimeError ) as error :
@@ -105,7 +105,7 @@ def get(self, url, **kw):
105
105
:return: The response from the request
106
106
:rtype: Response
107
107
"""
108
- if not self ._esp .is_connected :
108
+ if not self .esp .is_connected :
109
109
self .connect ()
110
110
self .pixel_status ((0 , 0 , 100 ))
111
111
return_val = requests .get (url , ** kw )
@@ -124,7 +124,7 @@ def post(self, url, **kw):
124
124
:return: The response from the request
125
125
:rtype: Response
126
126
"""
127
- if not self ._esp .is_connected :
127
+ if not self .esp .is_connected :
128
128
self .connect ()
129
129
self .pixel_status ((0 , 0 , 100 ))
130
130
return_val = requests .post (url , ** kw )
@@ -142,7 +142,7 @@ def put(self, url, **kw):
142
142
:return: The response from the request
143
143
:rtype: Response
144
144
"""
145
- if not self ._esp .is_connected :
145
+ if not self .esp .is_connected :
146
146
self .connect ()
147
147
self .pixel_status ((0 , 0 , 100 ))
148
148
return_val = requests .put (url , ** kw )
@@ -161,7 +161,7 @@ def patch(self, url, **kw):
161
161
:return: The response from the request
162
162
:rtype: Response
163
163
"""
164
- if not self ._esp .is_connected :
164
+ if not self .esp .is_connected :
165
165
self .connect ()
166
166
self .pixel_status ((0 , 0 , 100 ))
167
167
return_val = requests .patch (url , ** kw )
@@ -180,7 +180,7 @@ def delete(self, url, **kw):
180
180
:return: The response from the request
181
181
:rtype: Response
182
182
"""
183
- if not self ._esp .is_connected :
183
+ if not self .esp .is_connected :
184
184
self .connect ()
185
185
self .pixel_status ((0 , 0 , 100 ))
186
186
return_val = requests .delete (url , ** kw )
@@ -196,22 +196,22 @@ def ping(self, host, ttl=250):
196
196
:return: The response time in milliseconds
197
197
:rtype: int
198
198
"""
199
- if not self ._esp .is_connected :
199
+ if not self .esp .is_connected :
200
200
self .connect ()
201
201
self .pixel_status ((0 , 0 , 100 ))
202
- response_time = self ._esp .ping (host , ttl = ttl )
202
+ response_time = self .esp .ping (host , ttl = ttl )
203
203
self .pixel_status (0 )
204
204
return response_time
205
205
206
206
def ip_address (self ):
207
207
"""
208
208
Returns a formatted local IP address, update status pixel.
209
209
"""
210
- if not self ._esp .is_connected :
210
+ if not self .esp .is_connected :
211
211
self .connect ()
212
212
self .pixel_status ((0 , 0 , 100 ))
213
213
self .pixel_status (0 )
214
- return self ._esp .pretty_ip (self ._esp .ip_address )
214
+ return self .esp .pretty_ip (self .esp .ip_address )
215
215
216
216
def pixel_status (self , value ):
217
217
"""
@@ -230,6 +230,6 @@ def signal_strength(self):
230
230
"""
231
231
Returns receiving signal strength indicator in dBm
232
232
"""
233
- if not self ._esp .is_connected :
233
+ if not self .esp .is_connected :
234
234
self .connect ()
235
- return self ._esp .rssi ()
235
+ return self .esp .rssi ()
0 commit comments