Package: adafruit-circuitpython-wiznet5k
IntroductionPure-Python interface for WIZNET 5k ethernet modules.DependenciesThis driver depends on:Adafruit CircuitPythonBus DevicePlease ensure all dependencies are available on the CircuitPython filesystem.
This is easily achieved by downloadingthe Adafruit library and driver bundle.Installing from PyPIOn supported GNU/Linux systems like the Raspberry Pi, you can install the driver locallyfrom
PyPI. To install for current user:pip3installadafruit-circuitpython-wiznet5kTo install system-wide (this may be required in some cases):sudopip3installadafruit-circuitpython-wiznet5kTo install in a virtual environment in your current project:mkdirproject-name&&cdproject-namepython3-mvenv.venvsource.venv/bin/activatepip3installadafruit-circuitpython-wiznet5kUsage ExampleThis example demonstrates making a HTTP GET request to
wifitest.adafruit.com.importboardimportbusioimportdigitalioimportadafruit_requestsasrequestsfromadafruit_wiznet5k.adafruit_wiznet5kimportWIZNET5Kimportadafruit_wiznet5k.adafruit_wiznet5k_socketassocketprint("Wiznet5k WebClient Test")TEXT_URL="http://wifitest.adafruit.com/testwifi/index.html"JSON_URL="http://api.coindesk.com/v1/bpi/currentprice/USD.json"cs=digitalio.DigitalInOut(board.D10)spi_bus=busio.SPI(board.SCK,MOSI=board.MOSI,MISO=board.MISO)# Initialize ethernet interface with DHCPeth=WIZNET5K(spi_bus,cs)# Initialize a requests object with a socket and ethernet interfacerequests.set_socket(socket,eth)print("Chip Version:",eth.chip)print("MAC Address:",[hex(i)foriineth.mac_address])print("My IP address is:",eth.pretty_ip(eth.ip_address))print("IP lookup adafruit.com:%s"%eth.pretty_ip(eth.get_host_by_name("adafruit.com")))#eth._debug = Trueprint("Fetching text from",TEXT_URL)r=requests.get(TEXT_URL)print('-'*40)print(r.text)print('-'*40)r.close()print()print("Fetching json from",JSON_URL)r=requests.get(JSON_URL)print('-'*40)print(r.json())print('-'*40)r.close()print("Done!")This example demonstrates a simple web server that allows setting the Neopixel color.importboardimportbusioimportdigitalioimportneopixelfromadafruit_wiznet5k.adafruit_wiznet5kimportWIZNET5Kimportadafruit_wiznet5k.adafruit_wiznet5k_wsgiserverasserverfromadafruit_wsgi.wsgi_appimportWSGIAppprint("Wiznet5k Web Server Test")# Status LEDled=neopixel.NeoPixel(board.NEOPIXEL,1)led.brightness=0.3led[0]=(0,0,255)# W5500 connectionscs=digitalio.DigitalInOut(board.D10)spi_bus=busio.SPI(board.SCK,MOSI=board.MOSI,MISO=board.MISO)# Initialize Ethernet interface with DHCPeth=WIZNET5K(spi_bus,cs)# Here we create our application, registering the# following functions to be called on specific HTTP GET requests routesweb_app=WSGIApp()@web_app.route("/led/<r>/<g>/<b>")defled_on(request,r,g,b):print("LED handler")led.fill((int(r),int(g),int(b)))return("200 OK",[],["LED set!"])@web_app.route("/")defroot(request):print("Root handler")return("200 OK",[],["Root document"])@web_app.route("/large")deflarge(request):print("Large pattern handler")return("200 OK",[],["*-.-"*2000])# Here we setup our server, passing in our web_app as the applicationserver.set_interface(eth)wsgiServer=server.WSGIServer(80,application=web_app)print("Open this IP in your browser: ",eth.pretty_ip(eth.ip_address))# Start the serverwsgiServer.start()whileTrue:# Our main loop where we have the server poll for incoming requestswsgiServer.update_poll()# Maintain DHCP leaseeth.maintain_dhcp_lease()# Could do any other background tasks here, like reading sensorsDocumentationAPI documentation for this library can be found onRead the Docs.For information on building library documentation, please check outthis guide.ContributingContributions are welcome! Please read ourCode of Conductbefore contributing to help this project stay welcoming.LicenseThis library was written byArduino LLC. We’ve converted it to work
withCircuitPythonand made changes so it works similarly toCircuitPython’s WIZNET5k wrapper for the WIZnet
5500 Ethernet interfaceand CPython’sSocket low-level
networking interface module.This open source code is licensed under the LGPL license (see LICENSE for details).