|
1 try: |
|
2 import wiznet_config |
|
3 |
|
4 def connectLan(): |
|
5 import network |
|
6 import time |
|
7 from machine import Pin, SPI |
|
8 |
|
9 spi = SPI(0, 2_000_000, mosi=Pin(19), miso=Pin(16), sck=Pin(18)) |
|
10 nic = network.WIZNET5K(spi, Pin(17), Pin(20)) |
|
11 |
|
12 nic.active(False) |
|
13 nic.active(True) |
|
14 nic.ifconfig(wiznet_config.ifconfig) |
|
15 max_wait = 140 |
|
16 while max_wait: |
|
17 if nic.isconnected(): |
|
18 break |
|
19 max_wait -= 1 |
|
20 time.sleep(0.1) |
|
21 |
|
22 if nic.isconnected(): |
|
23 print("Connected to LAN:", nic.ifconfig()) |
|
24 else: |
|
25 print("Connection to LAN failed.") |
|
26 |
|
27 return nic |
|
28 |
|
29 except ImportError: |
|
30 print( |
|
31 "The network configuration is kept in 'wiznet_config.py'. Please add it there." |
|
32 ) |
|
33 def connectLan(): |
|
34 return None |