/ README.rst
README.rst
  1  Introduction
  2  ============
  3  
  4  .. image:: https://readthedocs.org/projects/adafruit-circuitpython-wiznet5k/badge/?version=latest
  5      :target: https://circuitpython.readthedocs.io/projects/wiznet5k/en/latest/
  6      :alt: Documentation Status
  7  
  8  .. image:: https://img.shields.io/discord/327254708534116352.svg
  9      :target: https://adafru.it/discord
 10      :alt: Discord
 11  
 12  .. image:: https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k/workflows/Build%20CI/badge.svg
 13      :target: https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k/actions
 14      :alt: Build Status
 15  
 16  Pure-Python interface for WIZNET 5k ethernet modules.
 17  
 18  Dependencies
 19  =============
 20  This driver depends on:
 21  
 22  * `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
 23  * `Bus Device <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_
 24  
 25  Please ensure all dependencies are available on the CircuitPython filesystem.
 26  This is easily achieved by downloading
 27  `the Adafruit library and driver bundle <https://circuitpython.org/libraries>`_.
 28  
 29  Installing from PyPI
 30  =====================
 31  On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
 32  PyPI <https://pypi.org/project/adafruit-circuitpython-wiznet5k/>`_. To install for current user:
 33  
 34  .. code-block:: shell
 35  
 36      pip3 install adafruit-circuitpython-wiznet5k
 37  
 38  To install system-wide (this may be required in some cases):
 39  
 40  .. code-block:: shell
 41  
 42      sudo pip3 install adafruit-circuitpython-wiznet5k
 43  
 44  To install in a virtual environment in your current project:
 45  
 46  .. code-block:: shell
 47  
 48      mkdir project-name && cd project-name
 49      python3 -m venv .env
 50      source .env/bin/activate
 51      pip3 install adafruit-circuitpython-wiznet5k
 52  
 53  Usage Example
 54  =============
 55  This example demonstrates making a HTTP GET request to
 56  wifitest.adafruit.com.
 57  
 58  .. code-block:: python
 59  
 60      import board
 61      import busio
 62      import digitalio
 63      import adafruit_requests as requests
 64      from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
 65      import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
 66  
 67      print("Wiznet5k WebClient Test")
 68  
 69      TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
 70      JSON_URL = "http://api.coindesk.com/v1/bpi/currentprice/USD.json"
 71  
 72      cs = digitalio.DigitalInOut(board.D10)
 73      spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
 74  
 75      # Initialize ethernet interface with DHCP
 76      eth = WIZNET5K(spi_bus, cs)
 77  
 78      # Initialize a requests object with a socket and ethernet interface
 79      requests.set_socket(socket, eth)
 80  
 81      print("Chip Version:", eth.chip)
 82      print("MAC Address:", [hex(i) for i in eth.mac_address])
 83      print("My IP address is:", eth.pretty_ip(eth.ip_address))
 84      print("IP lookup adafruit.com: %s" %eth.pretty_ip(eth.get_host_by_name("adafruit.com")))
 85  
 86  
 87      #eth._debug = True
 88      print("Fetching text from", TEXT_URL)
 89      r = requests.get(TEXT_URL)
 90      print('-'*40)
 91      print(r.text)
 92      print('-'*40)
 93      r.close()
 94  
 95      print()
 96      print("Fetching json from", JSON_URL)
 97      r = requests.get(JSON_URL)
 98      print('-'*40)
 99      print(r.json())
100      print('-'*40)
101      r.close()
102  
103      print("Done!")
104  
105  Contributing
106  ============
107  
108  Contributions are welcome! Please read our `Code of Conduct
109  <https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k/blob/master/CODE_OF_CONDUCT.md>`_
110  before contributing to help this project stay welcoming.
111  
112  Documentation
113  =============
114  
115  For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.
116  
117  License
118  =============
119  
120  This library was written by `Arduino LLC <https://github.com/arduino-libraries/Ethernet/blob/master/AUTHORS>`_. We've converted it to work
121  with `CircuitPython <https://circuitpython.org/>`_ and made changes so it works similarly to `CircuitPython's WIZNET5k wrapper for the WIZnet
122  5500 Ethernet interface <https://circuitpython.readthedocs.io/en/latest/shared-bindings/wiznet/wiznet5k.html>`_ and CPython's `Socket low-level
123  networking interface module <https://docs.python.org/3.8/library/socket.html>`_.
124  
125  This open source code is licensed under the LGPL license (see LICENSE for details).