Sun, 16 Mar 2025 12:53:12 +0100
Added the Adafruit Feather nRF52840 to the list of known NRF52 boards and changed the list of known CircuitPython boards to be more explicit with respect to Adafruit boards (i.e. VID 0x239A).
9878 | 1 | try: |
2 | import wiznet_config | |
3 | ||
9890
66a6d3f131cc
Changed the MCU script to a pythonic naming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9878
diff
changeset
|
4 | def connect_lan(): |
9878 | 5 | import network |
6 | import time | |
7 | from machine import Pin, SPI | |
8 | ||
9890
66a6d3f131cc
Changed the MCU script to a pythonic naming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9878
diff
changeset
|
9 | try: |
66a6d3f131cc
Changed the MCU script to a pythonic naming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9878
diff
changeset
|
10 | ifconfig = wiznet_config.ifconfig |
10153 | 11 | hostname = wiznet_config.hostname |
9890
66a6d3f131cc
Changed the MCU script to a pythonic naming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9878
diff
changeset
|
12 | except AttributeError: |
66a6d3f131cc
Changed the MCU script to a pythonic naming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9878
diff
changeset
|
13 | print("The network configuration in 'wiznet_config.py' is invalid.") |
66a6d3f131cc
Changed the MCU script to a pythonic naming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9878
diff
changeset
|
14 | return None |
66a6d3f131cc
Changed the MCU script to a pythonic naming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9878
diff
changeset
|
15 | |
10153 | 16 | if hostname: |
17 | try: | |
18 | network.hostname(hostname) | |
19 | except AttributeError: | |
20 | pass | |
21 | ||
9878 | 22 | spi = SPI(0, 2_000_000, mosi=Pin(19), miso=Pin(16), sck=Pin(18)) |
23 | nic = network.WIZNET5K(spi, Pin(17), Pin(20)) | |
24 | ||
25 | nic.active(False) | |
26 | nic.active(True) | |
9890
66a6d3f131cc
Changed the MCU script to a pythonic naming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9878
diff
changeset
|
27 | nic.ifconfig(ifconfig) |
9878 | 28 | max_wait = 140 |
29 | while max_wait: | |
30 | if nic.isconnected(): | |
31 | break | |
32 | max_wait -= 1 | |
33 | time.sleep(0.1) | |
34 | ||
35 | if nic.isconnected(): | |
36 | print("Connected to LAN:", nic.ifconfig()) | |
37 | else: | |
38 | print("Connection to LAN failed.") | |
39 | ||
40 | return nic | |
41 | ||
42 | except ImportError: | |
43 | print( | |
44 | "The network configuration is kept in 'wiznet_config.py'. Please add it there." | |
45 | ) | |
9890
66a6d3f131cc
Changed the MCU script to a pythonic naming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9878
diff
changeset
|
46 | def connect_lan(): |
9878 | 47 | return None |