Skip to content

Commit e0b2ba9

Browse files
authored
Merge pull request #59 from FoamyGuy/ethernet_example
adding ethernet example
2 parents e989afe + 072c406 commit e0b2ba9

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# SPDX-FileCopyrightText: 2023 Tim C for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
import board
5+
import digitalio
6+
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
7+
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
8+
from adafruit_httpserver import Server, Request, Response
9+
10+
print("Wiznet5k HTTPServer Test")
11+
12+
# For Adafruit Ethernet FeatherWing
13+
cs = digitalio.DigitalInOut(board.D10)
14+
# For Particle Ethernet FeatherWing
15+
# cs = digitalio.DigitalInOut(board.D5)
16+
spi_bus = board.SPI()
17+
18+
# Initialize ethernet interface with DHCP
19+
eth = WIZNET5K(spi_bus, cs)
20+
21+
# set the interface on the socket source
22+
socket.set_interface(eth)
23+
24+
# initialize the server
25+
server = Server(socket, "/static", debug=True)
26+
27+
28+
@server.route("/")
29+
def base(request: Request):
30+
"""
31+
Serve a default static plain text message.
32+
"""
33+
return Response(request, "Hello from the CircuitPython HTTP Server!")
34+
35+
36+
server.serve_forever(str(eth.pretty_ip(eth.ip_address)))

0 commit comments

Comments
 (0)