1515
1616
1717class Startup :
18- def __init__ (self ) -> None :
19- self .wlan = network .WLAN (network .STA_IF )
20- self .wlan .active (False )
21- self .wlan .active (True )
22-
23- def connect_network (self , ssid : str , pswd : str ) -> bool :
24- if len (ssid ) > 0 :
25- self .wlan .connect (ssid , pswd )
18+ STAT_GOT_IP = 1010
19+ ETH_GOT_IP = 5
20+
21+ def __init__ (self , network_type : str = "WIFI" ) -> None :
22+ self .network_type = network_type
23+ if network_type == "WIFI" :
24+ self .network = network .WLAN (network .STA_IF )
25+ self .network .active (False )
26+ self .network .active (True )
27+
28+ def connect_network (
29+ self ,
30+ ssid : str = "" ,
31+ pswd : str = "" ,
32+ lan_if : "network.LAN" = None ,
33+ eth_mode : str = "DHCP" ,
34+ ip : str = "" ,
35+ netmask : str = "" ,
36+ gateway : str = "" ,
37+ dns : str = "" ,
38+ ) -> bool :
39+ if self .network_type == "WIFI" and len (ssid ) > 0 :
40+ self .network .connect (ssid , pswd )
41+ return True
42+ elif self .network_type == "ETH" :
43+ self .network = lan_if
44+ self .network .active (True )
45+ if eth_mode == "STATIC" :
46+ self .network .ifconfig ((ip , netmask , gateway , dns ))
2647 return True
2748 else :
2849 return False
2950
51+ def active (self , is_active : bool ) -> None :
52+ self .network .active (is_active )
53+
3054 def connect_status (self ) -> int :
31- return self .wlan .status ()
55+ return self .network .status ()
3256
3357 def local_ip (self ) -> str :
34- return self .wlan .ifconfig ()[0 ]
58+ return self .network .ifconfig ()[0 ]
59+
60+ def status (self , param : str ) -> int :
61+ return self .network .status (param )
3562
3663 def get_rssi (self ) -> int :
37- return self .wlan .status ("rssi" )
64+ if hasattr (self .network , "status" ):
65+ return self .network .status ("rssi" )
66+ else :
67+ return 0
3868
3969
4070def _is_psram ():
@@ -49,8 +79,14 @@ def startup(boot_opt, timeout: int = 60) -> None:
4979 M5 .begin ()
5080 # Read saved Wi-Fi information from NVS
5181 nvs = esp32 .NVS ("uiflow" )
82+ net_mode = nvs .get_str ("net_mode" )
5283 ssid = nvs .get_str ("ssid0" )
5384 pswd = nvs .get_str ("pswd0" )
85+ eth_mode = nvs .get_str ("eth_mode" )
86+ ip = nvs .get_str ("ip_addr" )
87+ netmask = nvs .get_str ("netmask" )
88+ gateway = nvs .get_str ("gateway" )
89+ dns = nvs .get_str ("dns" )
5490 try :
5591 tz = nvs .get_str ("tz" )
5692 time .timezone (tz )
@@ -254,8 +290,8 @@ def startup(boot_opt, timeout: int = 60) -> None:
254290 elif board_id == M5 .BOARD .M5StamPLC :
255291 from .stamplc import StampPLC_Startup
256292
257- station = StampPLC_Startup ()
258- station .startup (ssid , pswd , timeout )
293+ plc = StampPLC_Startup ()
294+ plc .startup (net_mode , ssid , pswd , eth_mode , ip , netmask , gateway , dns , timeout )
259295
260296 elif board_id == M5 .BOARD .M5Tab5 :
261297 from .tab5 import Tab5_Startup
0 commit comments