Skip to content

Commit d71944e

Browse files
authored
add ethernet example (#9)
* feat (wifi): add esp8266 function code - WLAN.py 固件版本: N/A 是否需要文案翻译: 否 * example (ethernet): add ethernet example 固件版本: N/A 是否需要文案翻译: 否
1 parent 2e9f948 commit d71944e

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import dataCall
2+
import ethernet
3+
4+
nic = None
5+
6+
def netStatusCallback(args):
7+
pdp = args[0]
8+
datacallState = args[1]
9+
if datacallState == 0:
10+
print('modem network {} disconnected.'.format(pdp))
11+
elif datacallState == 1:
12+
print('modem network {} connected.'.format(pdp))
13+
if nic != None:
14+
lte=dataCall.getInfo(1, 0)
15+
print(lte)
16+
nic.set_default_NIC(lte[2][2])
17+
18+
def eth_init():
19+
lte=dataCall.getInfo(1, 0)
20+
print('modem net config: {}'.format(lte))
21+
workMode=1
22+
global nic
23+
print('eth init start')
24+
nic = ethernet.W5500(b'\x12\x34\x56\x78\x9a\xbc','192.168.1.1','','',-1,-1,-1,-1, workMode)
25+
if lte != -1 and lte[2][0] == 1:
26+
print('eth set default nic {}'.format(lte[2][2]))
27+
nic.set_default_NIC(lte[2][2])
28+
nic.set_dns('8.8.8.8', '114.114.114.114')
29+
print('eth net config: {}'.format(nic.ipconfig()))
30+
nic.set_up()
31+
print('eth startup success')
32+
33+
dataCall.setCallback(netStatusCallback)
34+
eth_init()
35+
36+
37+
38+
39+
40+
41+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import ethernet
2+
3+
nic = None
4+
5+
def eth_init():
6+
print('eth init start')
7+
nic = ethernet.W5500(b'\x12\x34\x56\x78\x9a\xbc','','','',-1,-1,-1,-1)
8+
nic_info = nic.ipconfig()
9+
print('nic net config before: {}'.format(nic_info))
10+
# dhcp ip config
11+
nic.dhcp()
12+
# static ip config
13+
nic.set_addr('192.168.1.99', '255.255.255.0','192.168.1.1')
14+
nic.set_dns('8.8.8.8', '114.114.114.114')
15+
nic_info = nic.ipconfig()
16+
print('nic net config after: {}'.format(nic_info))
17+
nic.set_default_NIC(nic_info[1][1])
18+
nic.set_up()
19+
print('eth startup success')
20+
21+
eth_init()
22+
23+
# now, you can connect server by ethernet interface
24+
25+
26+
27+
28+
29+
30+
31+

0 commit comments

Comments
 (0)