1212
1313class BoardsInterface :
1414
15- EXISTING = 1
16- WIFI = 2
17- LTE = 3
15+ EXISTING_NETWORK = 2
16+ WIFI = 3
17+ LTE = 4
1818
1919 @staticmethod
20- def create_credentials (mode ):
21- return LiveObjects .Credentials (mode )
20+ def create_credentials (net_type ):
21+ return LiveObjects .Credentials (net_type )
2222
2323 def get_apikey (self ):
2424 return self ._credentials .get_apikey ()
@@ -35,7 +35,7 @@ def mqtt_lib_import_str(lang):
3535 return import_strings [lang ]
3636
3737 def get_security_level (self ):
38- return LiveObjects . SSL if self . _wifi_tls_capability else LiveObjects . NONE
38+ pass
3939
4040 def network_connect (self ):
4141 pass
@@ -49,63 +49,91 @@ class LoPy(BoardsInterface):
4949
5050
5151class GPy (BoardsInterface ):
52- def __init__ (self ):
52+ def __init__ (self , net_type ):
5353 self ._lang = 'microPython'
54+ self ._net_type = net_type
5455 self ._wifi_tls_capability = True
55- self ._lte_tls_capability = True
56+ self ._lte_tls_capability = False
5657 self ._mqtt_lib = super ().mqtt_lib_import_str (self ._lang )
57- self ._credentials = super ().create_credentials (BoardsInterface . WIFI )
58+ self ._credentials = super ().create_credentials (net_type )
5859
5960 def network_connect (self ):
60- pycom_wifi_connect (self ._credentials .get_wifi_creds ()['ssid' ], self ._credentials .get_wifi_creds ()['password' ])
61+ if self ._net_type == BoardsInterface .WIFI :
62+ pycom_wifi_connect (self ._credentials .get_creds ()['ssid' ], self ._credentials .get_creds ()['password' ])
63+ elif self ._net_type == BoardsInterface .LTE :
64+ lte_connect (self ._credentials .get_creds ()['pin' ])
65+
66+ def get_security_level (self ):
67+ if self ._net_type == BoardsInterface .WIFI :
68+ return LiveObjects .SSL if self ._wifi_tls_capability else LiveObjects .NONE
69+ elif self ._net_type == BoardsInterface .LTE :
70+ return LiveObjects .SSL if self ._lte_tls_capability else LiveObjects .NONE
6171
6272
6373class Esp8266 (BoardsInterface ):
64- def __init__ (self ):
74+ def __init__ (self , net_type ):
6575 self ._lang = 'microPython'
76+ self ._net_type = net_type
6677 self ._wifi_tls_capability = False
6778 self ._wifi_lte_capability = False
6879 self ._mqtt_lib = super ().mqtt_lib_import_str (self ._lang )
6980 self ._credentials = super ().create_credentials (BoardsInterface .WIFI )
7081
7182 def network_connect (self ):
72- wifi_connect (self ._credentials .get_wifi_creds ()['ssid' ], self ._credentials .get_wifi_creds ()['password' ])
83+ if self ._net_type == BoardsInterface .WIFI :
84+ wifi_connect (self ._credentials .get_creds ()['ssid' ], self ._credentials .get_creds ()['password' ])
85+
86+ def get_security_level (self ):
87+ if self ._net_type == BoardsInterface .WIFI :
88+ return LiveObjects .SSL if self ._wifi_tls_capability else LiveObjects .NONE
7389
7490
7591class Win32 (BoardsInterface ):
7692 pass
7793
7894
7995class Esp32 (BoardsInterface ):
80- def __init__ (self ):
96+ def __init__ (self , net_type ):
8197 self ._lang = 'microPython'
98+ self ._net_type = net_type
8299 self ._wifi_tls_capability = True
83100 self ._wifi_lte_capability = False
84101 self ._mqtt_lib = super ().mqtt_lib_import_str (self ._lang )
85102 self ._credentials = super ().create_credentials (BoardsInterface .WIFI )
86103
87104 def network_connect (self ):
88- wifi_connect (self ._credentials .get_wifi_creds ()['ssid' ], self ._credentials .get_wifi_creds ()['password' ])
105+ if self ._net_type == BoardsInterface .WIFI :
106+ wifi_connect (self ._credentials .get_creds ()['ssid' ], self ._credentials .get_creds ()['password' ])
107+
108+ def get_security_level (self ):
109+ if self ._net_type == BoardsInterface .WIFI :
110+ return LiveObjects .SSL if self ._wifi_tls_capability else LiveObjects .NONE
89111
90112
91113class Linux (BoardsInterface ):
92- def __init__ (self ):
114+ def __init__ (self , net_type ):
93115 self ._lang = 'Python'
116+ self ._net_type = net_type
94117 self ._wifi_tls_capability = True
95118 self ._wifi_lte_capability = False
96119 self ._mqtt_lib = super ().mqtt_lib_import_str (self ._lang )
97- self ._credentials = super ().create_credentials (BoardsInterface . EXISTING )
120+ self ._credentials = super ().create_credentials (self . _net_type )
98121
99122 def network_connect (self ):
100- use_existing_network_connection ()
123+ if self ._net_type == BoardsInterface .EXISTING_NETWORK :
124+ use_existing_network_connection ()
125+
126+ def get_security_level (self ):
127+ if self ._net_type == BoardsInterface .EXISTING_NETWORK :
128+ return LiveObjects .SSL if self ._wifi_tls_capability else LiveObjects .NONE
101129
102130
103131class BoardsFactory :
104132
105- def __new__ (cls ):
133+ def __new__ (cls , net_type ):
106134 s = os .uname ().sysname
107135 sn = s [0 ].upper () + s [1 :] # capitalize first letter
108- board = eval (sn )() # instance of board
136+ board = eval (sn )(net_type ) # instance of board w/ net type: WiFi, LTE, etc.
109137 return board
110138
111139
@@ -130,6 +158,7 @@ def wifi_connect(ssid, password):
130158CONN_TIMEOUT = 20
131159
132160
161+ # noinspection PyUnresolvedReferences
133162def pycom_wifi_connect (ssid , password ):
134163 from network import WLAN
135164
@@ -149,10 +178,10 @@ def pycom_wifi_connect(ssid, password):
149178 break
150179
151180
181+ # noinspection PyUnresolvedReferences
152182def lte_connect (pin ):
153183
154184 from network import LTE
155- import socket
156185
157186 lte = LTE ()
158187 time .sleep (2 )
0 commit comments