1818from misc import Power
1919
2020
21- # 用户需要配置的APN信息,根据实际情况修改
21+ # Configure the APN information according to your actual needs
2222usrCfg1 = {'profileID' : 1 , 'apn' : '3gnet' , 'username' : '' , 'password' : '' }
2323usrCfg2 = {'profileID' : 2 , 'apn' : '3gwap' , 'username' : '' , 'password' : '' }
2424
@@ -29,15 +29,15 @@ def checkAPN(usrCfg, reboot=False):
2929 return False
3030
3131 print ('Check the APN configuration of the {} network card.' .format (usrCfg ['profileID' ]))
32- # 获取网卡的APN信息,确认当前使用的是否是用户指定的APN
32+ # Get the APN information of the cellular NICs and check if the current one is the one you specified
3333 pdpCtx = dataCall .getPDPContext (usrCfg ['profileID' ])
3434 if pdpCtx != - 1 :
3535 if pdpCtx [1 ] != usrCfg ['apn' ]:
36- # 如果不是用户需要的APN,使用如下方式配置
36+ # If it is not the APN you need, configure it as follows
3737 ret = dataCall .setPDPContext (usrCfg ['profileID' ], 0 , usrCfg ['apn' ], usrCfg ['username' ], usrCfg ['password' ], 0 )
3838 if ret == 0 :
3939 print ('APN configuration successful.' )
40- # 重启后按照配置的信息进行拨号
40+ # Make a data call according to the configured information after the module reboots
4141 if reboot :
4242 print ('Ready to restart to make APN take effect.' )
4343 print ('Please re-execute this program after restarting.' )
@@ -56,28 +56,28 @@ def checkAPN(usrCfg, reboot=False):
5656
5757
5858def main ():
59- # 使能第一路网卡开机自动激活功能
59+ # Enable automatic activation for NIC1
6060 dataCall .setAutoActivate (1 , 1 )
61- # 使能第一路网卡自动重连功能
61+ # Enable automatic reconnection for NIC1
6262 dataCall .setAutoConnect (1 , 1 )
63- # 使能第二路网卡开机自动激活功能
63+ # Enable automatic activation for NIC2
6464 dataCall .setAutoActivate (2 , 1 )
65- # 使能第二路网卡自动重连功能
65+ # Enable automatic reconnection for NIC2
6666 dataCall .setAutoConnect (2 , 1 )
6767
68- # 检查第一路网卡的APN配置,暂时不重启
68+ # Check the APN configuration of NIC1. Do not reboot now.
6969 checkpass = checkAPN (usrCfg1 , reboot = False )
7070 if not checkpass :
7171 return
72- # 检查第二路网卡的APN配置,配置后重启
72+ # Check the APN configuration of NIC2. Reboot the module after configuration.
7373 checkpass = checkAPN (usrCfg2 , reboot = True )
7474 if not checkpass :
7575 return
7676
7777 stage , state = checkNet .waitNetworkReady (20 )
7878 if stage == 3 and state == 1 :
7979 print ('Network connected successfully.' )
80- # 分别获取第一路和第二路网卡的IP地址信息
80+ # Get the IP addresses of NIC1 and NIC2
8181 ret1 = dataCall .getInfo (usrCfg1 ['profileID' ], 0 )
8282 ret2 = dataCall .getInfo (usrCfg2 ['profileID' ], 0 )
8383 print ('NIC{}:{}' .format (usrCfg1 ['profileID' ], ret1 ))
@@ -98,45 +98,45 @@ def main():
9898 print ('NIC{} ip:{}' .format (usrCfg2 ['profileID' ], ip_nic2 ))
9999
100100 print ('---------------sock1 test-----------------' )
101- # 创建socket对象
101+ # Create a socket object
102102 sock1 = usocket .socket (usocket .AF_INET , usocket .SOCK_STREAM )
103- # 解析域名
103+ # Resolve the domain name
104104 try :
105105 sockaddr = usocket .getaddrinfo ('python.quectel.com' , 80 )[0 ][- 1 ]
106106 except Exception :
107107 print ('Domain name resolution failed.' )
108108 sock1 .close ()
109109 return
110- # 建立连接
110+ # Connect to the server
111111 sock1 .connect (sockaddr )
112- # 向服务端发送消息
112+ # Send data to the server
113113 ret = sock1 .send ('GET /News HTTP/1.1\r \n Host: python.quectel.com\r \n Accept-Encoding: deflate\r \n Connection: keep-alive\r \n \r \n ' )
114114 print ('send {} bytes' .format (ret ))
115- # 接收服务端消息
115+ # Receive data from the server
116116 data = sock1 .recv (256 )
117117 print ('recv {} bytes:' .format (len (data )))
118118 print (data .decode ())
119- # 关闭连接
119+ # Close the connection
120120 sock1 .close ()
121121 print ('---------------sock2 test-----------------' )
122122 sock2 = usocket .socket (usocket .AF_INET , usocket .SOCK_STREAM , usocket .TCP_CUSTOMIZE_PORT )
123123 sock2 .bind ((ip_nic2 , 0 ))
124124 sock2 .settimeout (10 )
125- # 服务器IP和端口,下面的IP和端口仅作示例参考
125+ # Configure server IP address and port number. The IP address and port number below are for example only
126126 server_addr = ('220.180.239.212' , 8305 )
127- # 建立连接
127+ # Connect to the server
128128 sock2 .connect (server_addr )
129- # 向服务器发送消息
129+ # Send data to the server
130130 ret = sock2 .send ('test data.' )
131131 print ('send {} bytes' .format (ret ))
132- # 接收服务端消息
132+ # Receive data from the server
133133 try :
134134 data = sock2 .recv (256 )
135135 print ('recv {} bytes:' .format (len (data )))
136136 print (data .decode ())
137137 except Exception :
138138 print ('No reply from server.' )
139- # 关闭连接
139+ # Close the connection
140140 sock2 .close ()
141141 else :
142142 print ('Network connected failed, stage={}, state={}' .format (stage , state ))
0 commit comments