31
31
32
32
# pylint: disable=no-name-in-module
33
33
34
+ from micropython import const
34
35
from adafruit_esp32spi import adafruit_esp32spi
35
36
import adafruit_esp32spi .adafruit_esp32spi_requests as requests
36
37
37
- class WiFiConnType : # pylint: disable=too-few-public-methods
38
- """An enum-like class representing the different types of WiFi connections
39
- that can be made. The values can be referenced like ``WiFiConnType.normal``.
40
- Possible values are
41
- - ``ThermocoupleType.normal``
42
- - ``ThermocoupleType.enterprise``
43
- """
44
- # pylint: disable=invalid-name
45
- normal = 1
46
- enterprise = 2
47
-
48
38
class ESPSPI_WiFiManager :
49
39
"""
50
40
A class to help manage the Wifi connection
51
41
"""
52
- def __init__ (self , esp , secrets , status_pixel = None , attempts = 2 , wificonntype = WiFiConnType .normal ):
42
+ NORMAL = const (1 )
43
+ ENTERPRISE = const (2 )
44
+
45
+ def __init__ (self , esp , secrets , status_pixel = None , attempts = 2 , connection_type = NORMAL ):
53
46
"""
54
47
:param ESP_SPIcontrol esp: The ESP object we are using
55
48
:param dict secrets: The WiFi and Adafruit IO secrets dict (See examples)
@@ -68,9 +61,9 @@ def __init__(self, esp, secrets, status_pixel=None, attempts=2, wificonntype=WiF
68
61
self .ent_ssid = secrets ['ent_ssid' ]
69
62
self .ent_ident = secrets ['ent_ident' ]
70
63
self .ent_user = secrets ['ent_user' ]
71
- self .ent_passwd = secrets ['ent_passwd ' ]
64
+ self .ent_password = secrets ['ent_password ' ]
72
65
self .attempts = attempts
73
- self .wificonntype = wificonntype
66
+ self ._connection_type = connection_type
74
67
requests .set_interface (self ._esp )
75
68
self .statuspix = status_pixel
76
69
self .pixel_status (0 )
@@ -95,7 +88,7 @@ def connect(self):
95
88
for access_pt in self ._esp .scan_networks ():
96
89
print ("\t %s\t \t RSSI: %d" % (str (access_pt ['ssid' ], 'utf-8' ), access_pt ['rssi' ]))
97
90
failure_count = 0
98
- if self .wificonntype == WiFiConnType . normal :
91
+ if self ._connection_type == ESPSPI_WiFiManager . NORMAL :
99
92
while not self ._esp .is_connected :
100
93
try :
101
94
if self .debug :
@@ -111,11 +104,11 @@ def connect(self):
111
104
failure_count = 0
112
105
self .reset ()
113
106
continue
114
- elif self .wificonntype == WiFiConnType . enterprise :
107
+ elif self ._connection_type == ESPSPI_WiFiManager . ENTERPRISE :
115
108
self ._esp .wifi_set_network (bytes (self .ent_ssid , 'utf-8' ))
116
109
self ._esp .wifi_set_entidentity (bytes (self .ent_ident , 'utf-8' ))
117
110
self ._esp .wifi_set_entusername (bytes (self .ent_user , 'utf-8' ))
118
- self ._esp .wifi_set_entpassword (bytes (self .ent_passwd , 'utf-8' ))
111
+ self ._esp .wifi_set_entpassword (bytes (self .ent_password , 'utf-8' ))
119
112
self ._esp .wifi_set_entenable ()
120
113
while not self ._esp .is_connected :
121
114
try :
@@ -132,8 +125,7 @@ def connect(self):
132
125
self .reset ()
133
126
continue
134
127
else :
135
- print ("Invalid connection type! Exiting..." )
136
- exit (1 )
128
+ raise TypeError ("Invalid WiFi connection type specified" )
137
129
138
130
def get (self , url , ** kw ):
139
131
"""
0 commit comments