@@ -108,70 +108,6 @@ wifitest.adafruit.com.
108
108
109
109
print (" Done!" )
110
110
111
- This example demonstrates a simple web server that allows setting the Neopixel color.
112
-
113
- .. code-block :: python
114
-
115
- import board
116
- import busio
117
- import digitalio
118
- import neopixel
119
-
120
- from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
121
- import adafruit_wiznet5k.adafruit_wiznet5k_wsgiserver as server
122
- from adafruit_wsgi.wsgi_app import WSGIApp
123
-
124
- print (" Wiznet5k Web Server Test" )
125
-
126
- # Status LED
127
- led = neopixel.NeoPixel(board.NEOPIXEL , 1 )
128
- led.brightness = 0.3
129
- led[0 ] = (0 , 0 , 255 )
130
-
131
- # W5500 connections
132
- cs = digitalio.DigitalInOut(board.D10)
133
- spi_bus = busio.SPI(board.SCK , MOSI = board.MOSI , MISO = board.MISO )
134
-
135
- # Initialize Ethernet interface with DHCP
136
- eth = WIZNET5K(spi_bus, cs)
137
-
138
- # Here we create our application, registering the
139
- # following functions to be called on specific HTTP GET requests routes
140
-
141
- web_app = WSGIApp()
142
-
143
- @web_app.route (" /led/<r>/<g>/<b>" )
144
- def led_on (request , r , g , b ):
145
- print (" LED handler" )
146
- led.fill((int (r), int (g), int (b)))
147
- return (" 200 OK" , [], [" LED set!" ])
148
-
149
- @web_app.route (" /" )
150
- def root (request ):
151
- print (" Root handler" )
152
- return (" 200 OK" , [], [" Root document" ])
153
-
154
- @web_app.route (" /large" )
155
- def large (request ):
156
- print (" Large pattern handler" )
157
- return (" 200 OK" , [], [" *-.-" * 2000 ])
158
-
159
-
160
- # Here we setup our server, passing in our web_app as the application
161
- server.set_interface(eth)
162
- wsgiServer = server.WSGIServer(80 , application = web_app)
163
-
164
- print (" Open this IP in your browser: " , eth.pretty_ip(eth.ip_address))
165
-
166
- # Start the server
167
- wsgiServer.start()
168
- while True :
169
- # Our main loop where we have the server poll for incoming requests
170
- wsgiServer.update_poll()
171
- # Maintain DHCP lease
172
- eth.maintain_dhcp_lease()
173
- # Could do any other background tasks here, like reading sensors
174
-
175
111
Documentation
176
112
=============
177
113
0 commit comments