Skip to content

Commit 47cfafd

Browse files
committed
Change the comment of code into English.
1 parent 100db34 commit 47cfafd

11 files changed

+92
-92
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import request
22

3-
# http 协议的(非 https)百度URL
3+
# Baidu URL over HTTP protocol (not HTTPS)
44
url = 'http://www.baidu.com'
55

6-
# 发送 HTTP GET 请求
6+
# Send the HTTP GET request
77
response = request.get(url)
88

9-
# 创建文件baidu.html
9+
# Create file baidu.html
1010
f = open('/usr/baidu.html', 'wb') # 'wb' 表示写入二进制数据
1111

12-
# 获取网页文件内容,并写入文件
12+
# Get web page content and write to the file
1313
for i in response.content:
1414
f.write(i)
1515

16-
# 网页数据拉取完毕,关闭文件
16+
# Close the file after fetching the web page data
1717
f.close()
1818

19-
# 打开文件baidu.html
20-
with open('/usr/baidu.html', 'rb') as f: # 'rb' 以二进制方式读取文件
19+
# Open file baidu.html
20+
with open('/usr/baidu.html', 'rb') as f: # 'rb' means reading the file in binary mode
2121
r = f.read()
2222
while r:
2323
print(r)
2424
r = f.read()
2525

26-
# 关闭文件
26+
# Close the file
2727
f.close()

network-comm/net-protocols/http/example_get_weather.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import request
22

3-
# 天气查询URL
3+
# Weather query URL
44
url = 'http://restapi.amap.com/v3/weather/weatherInfo?key=2875b8171f67f3be3140c6779f12dcba&city=北京&extensions=base'
55

6-
# 发送 HTTP GET 请求
6+
# Send the HTTP GET request
77
response = request.get(url)
88

9-
# 获取天气查询网站返回的原始数据
9+
# Get the raw data returned by the weather query website
1010
data = ''
1111
for i in response.text:
1212
data += i

network-comm/net-protocols/http/example_get_weather_json_resolve.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import request
22

3-
# 天气查询URL
3+
# Weather query URL
44
url = 'http://restapi.amap.com/v3/weather/weatherInfo?key=2875b8171f67f3be3140c6779f12dcba&city=北京&extensions=base'
55

6-
# 发送 HTTP GET 请求
6+
# Send the HTTP GET request
77
response = request.get(url)
88

9-
# 获取天气查询网站返回的原始数据,并解析为dict
9+
# Get raw data from the website and parse it into a dict type by calling the json() method of response object
1010
data = response.json()
1111
data = data['lives'][0]
1212
for k,v in data.items():
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import ethernet
22

3-
# 创建以太网卡
3+
# Create an Ethernet NIC
44
eth = ethernet.W5500(b'\x12\x34\x56\x78\x9a\xbc','','','',-1,38,36,37, 0)
55
print('W5500 ethernet nic created.')
66

7-
# 开启 DHCP 功能
7+
# Enable DHCP
88
eth.dhcp()
99
print('DHCP enabled.')
1010

11-
# 网卡注册成功后,查看网络配置信息
11+
# After the NIC is registered, check the network configuration information
1212
ip_conf = eth.ipconfig()
1313
print('get ip_conf:', ip_conf)
1414

15-
# 将以太网卡设置为默认网卡
15+
# Set the Ethernet NIC as the default NIC
1616
eth.set_default_NIC(ip_conf[1][1])
1717
print('W5500 is set as default nic.')
1818

19-
# 启动网卡
19+
# Enable the NIC
2020
eth.set_up()
2121
print('Ethernet nic enabled.')
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
from usr.WLAN import ESP8266
22
from machine import UART
33

4-
# 创建Wi-Fi网卡
4+
# Create a Wi-Fi NIC
55
wifi = ESP8266(UART.UART2, ESP8266.STA)
66
print('Wi-Fi nic created.')
77

8-
# 配置连接的SSID和password,并连接路由器
8+
# Configure the SSID and password, and connect to the router
99
ssid = 'ssid'
1010
password = 'password'
1111
wifi.station(ssid,password)
1212
print('Wi-Fi connected:%s, %s.' % (ssid, password))
1313

14-
# 给Wi-Fi网卡配置DNS服务器地址
14+
# Configure the DNS server address for the Wi-Fi NIC
1515
wifi.set_dns('8.8.8.8', '114.114.114.114')
1616
print('Wi-Fi DNS server configured.')
1717

18-
# 查看网络配置信息
18+
# Check the network configuration information
1919
ip_conf = wifi.ipconfig()
2020
print('get ip_conf:', ip_conf)
2121

22-
# 将Wi-Fi网卡设置为默认网卡
22+
# Set the Wi-Fi NIC as the default NIC
2323
wifi.set_default_NIC(ip_conf[0])
2424
print('Wi-Fi is set as default nic.')
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
import ethernet
22
import usocket
33

4-
# 创建以太网卡
4+
# Create an Ethernet NIC
55
eth = ethernet.W5500(b'\x12\x34\x56\x78\x9a\xbc','','','',-1,38,36,37, 0)
66
print('W5500 ethernet nic created.')
77

8-
# 开启 DHCP 功能
8+
# Enable DHCP
99
eth.dhcp()
1010
print('DHCP enabled.')
1111

12-
# 启动网卡
12+
# Enable NIC
1313
eth.set_up()
1414
print('Ethernet nic enabled.')
1515

16-
# 网卡注册成功后,查看网络配置信息
16+
# After the NIC is registered, check the network configuration information
1717
ip_conf = eth.ipconfig()
1818
print('get ip_conf:', ip_conf)
1919

2020
def tcp_client(address, port):
21-
# 创建socket对象
21+
# Create a socket object
2222
sock = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM, usocket.IPPROTO_TCP)
2323
print('socket object created.')
2424

25-
# 创建完成socket对象以后,并且连接服务器之前 绑定以太网卡IP地址
25+
# Bind the Ethernet NIC IP address after creating the socket object and before connecting to the server
2626
local_address = ip_conf[1][1]
2727
sock.bind((local_address, 0))
2828
print('bind ethernet address: %s', local_address)
2929

30-
# 域名解析
30+
# Resolve the domain name
3131
sockaddr=usocket.getaddrinfo(address, port)[0][-1]
3232
print('DNS for %s: %s' % (address, sockaddr[0]))
3333

34-
# 连接tcp服务器
34+
# Connect to the TCP server
3535
sock.connect(sockaddr)
3636
print('tcp link established.')
3737

38-
# 更多代码请参考前面关于 TCP 客户端的代码示例
38+
# More code in TCP client samples above

network-comm/net-protocols/tcp-udp/example_socket_bind_of_wifi.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,40 @@
22
from machine import UART
33
import usocket
44

5-
# 创建Wi-Fi网卡
5+
# Create a Wi-Fi NIC
66
wifi = ESP8266(UART.UART2, ESP8266.STA)
77
print('Wi-Fi nic created.')
88

9-
# 配置连接的SSID和password,并连接路由器
9+
# Configure the SSID and password, and connect to the router
1010
ssid = 'ssid'
1111
password = 'password'
1212
wifi.station(ssid,password)
13-
print('Wi-Fi connected%s, %s.' % (ssid, password))
13+
print('Wi-Fi connected: %s, %s.' % (ssid, password))
1414

15-
# 给Wi-Fi网卡配置DNS服务器地址
15+
# Configure the DNS server address for the Wi-Fi NIC
1616
wifi.set_dns('8.8.8.8', '114.114.114.114')
1717
print('Wi-Fi DNS server configured.')
1818

19-
# 查看网络配置信息
19+
# Check the network configuration information
2020
ip_conf = wifi.ipconfig()
2121
print('get ip_conf:', ip_conf)
2222

2323
def tcp_client(address, port):
24-
# 创建socket对象
24+
# Create a socket object
2525
sock = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM, usocket.IPPROTO_TCP)
2626
print('socket object created.')
2727

28-
# 创建完成socket对象以后,并且连接服务器之前 绑定Wi-Fi网卡IP地址
28+
# Before connecting to the server, bind the Wi-Fi NIC IP address
2929
local_address = ip_conf[0]
3030
sock.bind((local_address, 0))
3131
print('bind ethernet address: %s', local_address)
3232

33-
# 域名解析
33+
# Resolve the domain name
3434
sockaddr=usocket.getaddrinfo(address, port)[0][-1]
3535
print('DNS for %s: %s' % (address, sockaddr[0]))
3636

37-
# 连接tcp服务器
37+
# Connect to the TCP server
3838
sock.connect(sockaddr)
3939
print('tcp link established.')
4040

41-
# 更多代码请参考前面关于 TCP 客户端的代码示例
41+
# More code in TCP client samples above

network-comm/net-protocols/tcp-udp/example_tcp_client_with_dns.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,46 @@
22
import checkNet
33

44
def tcp_client(address, port):
5-
# 创建socket对象
5+
# Create a socket object
66
sock = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM, usocket.IPPROTO_TCP)
77
print('socket object created.')
88

9-
# 域名解析
9+
# Domain name resolution
1010
sockaddr=usocket.getaddrinfo(address, port)[0][-1]
1111
print('DNS for %s: %s' % (address, sockaddr[0]))
1212

13-
# 连接tcp服务器
13+
# Connect to the TCP server
1414
sock.connect(sockaddr)
1515
print('tcp link established.')
1616

17-
# 打包用户数据
17+
# Package user data
1818
data = 'GET / HTTP/1.1\r\n'
1919
data += 'Host: ' + address + ':' + str(port) + '\r\n'
2020
data += 'Connection: close\r\n'
2121
data += '\r\n'
2222
data = data.encode()
2323

24-
# 发送数据
24+
# Send the data
2525
sock.send(data)
2626
print('<-- send data:')
2727
print(data)
2828

29-
#接收数据
29+
# Receive the data
3030
print('--> recv data:')
3131
while True:
3232
try:
3333
data = sock.recv(1024)
3434
print(data)
3535
except:
36-
# 数据接收完毕,连接断开
36+
# Connection ends until the data is fully received
3737
print('tcp disconnected.')
3838
sock.close()
3939
break
4040

4141
if __name__ == '__main__':
4242
stage, state = checkNet.waitNetworkReady(30)
43-
if stage == 3 and state == 1: # 网络状态正常
43+
if stage == 3 and state == 1: # Network connection is normal
4444
print('Network connection successful.')
45-
tcp_client('www.baidu.com', 80) # 启动客户端功能
45+
tcp_client('www.baidu.com', 80) # Start the client
4646
else:
4747
print('Network connection failed, stage={}, state={}'.format(stage, state))

network-comm/net-protocols/tcp-udp/example_tcp_client_without_dns.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,42 @@
22
import checkNet
33

44
def tcp_client(address, port):
5-
# 创建socket对象
5+
# Create a socket object
66
sock = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM, usocket.IPPROTO_TCP)
77
print('socket object created.')
88

9-
# 连接tcp服务器
9+
# Connect to the TCP server
1010
sock.connect((address, port))
1111
print('tcp link established: %s, %s' % (address, port))
1212

13-
# 打包用户数据
13+
# Package user data
1414
data = 'GET / HTTP/1.1\r\n'
1515
data += 'Host: ' + address + ':' + str(port) + '\r\n'
1616
data += 'Connection: close\r\n'
1717
data += '\r\n'
1818
data = data.encode()
1919

20-
# 发送数据
20+
# Send the data
2121
sock.send(data)
2222
print('<-- send data:')
2323
print(data)
2424

25-
#接收数据
25+
# Receive the data
2626
print('--> recv data:')
2727
while True:
2828
try:
2929
data = sock.recv(1024)
3030
print(data)
3131
except:
32-
# 数据接收完毕,连接断开
32+
# Connection ends until the data is fully received
3333
print('tcp disconnected.')
3434
sock.close()
3535
break
3636

3737
if __name__ == '__main__':
3838
stage, state = checkNet.waitNetworkReady(30)
39-
if stage == 3 and state == 1: # 网络状态正常
39+
if stage == 3 and state == 1: # Network connection is normal
4040
print('Network connection successful.')
41-
tcp_client('36.152.44.95', 80) # 启动客户端功能
41+
tcp_client('36.152.44.95', 80) # Start the client
4242
else:
4343
print('Network connection failed, stage={}, state={}'.format(stage, state))

0 commit comments

Comments
 (0)