adafruit_wiznet5k

Pure-Python interface for WIZNET 5k ethernet modules.

  • Author(s): WIZnet, Arduino LLC, Bjoern Hartmann, Paul Stoffregen, Brent Rubell

Implementation Notes

Software and Dependencies:

class adafruit_wiznet5k.adafruit_wiznet5k.WIZNET5K(spi_bus, cs, reset=None, is_dhcp=True, mac=(222, 173, 190, 239, 254, 237), hostname=None, dhcp_timeout=3, debug=False)

Interface for WIZNET5K module. :param ~busio.SPI spi_bus: The SPI bus the Wiznet module is connected to. :param ~digitalio.DigitalInOut cs: Chip select pin. :param ~digitalio.DigitalInOut rst: Optional reset pin. :param bool is_dhcp: Whether to start DHCP automatically or not. :param list mac: The Wiznet’s MAC Address. :param str hostname: The desired hostname, with optional {} to fill in MAC. :param int dhcp_timeout: Timeout in seconds for DHCP response. :param bool debug: Enable debugging output.

chip

Returns the chip type.

detect_w5500()

Detects W5500 chip.

get_host_by_name(hostname)

Convert a hostname to a packed 4-byte IP Address. Returns a 4 bytearray.

get_socket(sockets)

Requests, allocates and returns a socket from the W5k chip. Returned socket number may not exceed max_sockets. :parm int socket_num: Desired socket number

ifconfig

Returns the network configuration as a tuple.

ip_address

Returns the configured IP address.

“Returns if the PHY is connected.

mac_address

Returns the hardware’s MAC address.

max_sockets

Returns max number of sockets supported by chip.

pretty_ip(ip)

Converts a bytearray IP address to a dotted-quad string for printing

pretty_mac(mac)

Converts a bytearray MAC address to a dotted-quad string for printing

read(addr, callback, length=1, buffer=None)

Reads data from a register address. :param int addr: Register address.

read_udp(socket_num, length)

Read UDP socket’s remaining bytes.

remote_ip(socket_num)

Returns the IP address of the host who sent the current incoming packet. :param int socket num: Desired socket.

remote_port

Returns the port of the host who sent the current incoming packet.

set_dhcp(hostname=None, response_timeout=3)

Initializes the DHCP client and attempts to retrieve and set network configuration from the DHCP server. Returns True if DHCP configured, False otherwise. :param str hostname: The desired hostname, with optional {} to fill in MAC. :param int response_timeout: Time to wait for server to return packet, in seconds.

socket_available(socket_num, sock_type=33)

Returns the amount of bytes to be read from the socket.

Parameters:
  • socket_num (int) – Desired socket to return bytes from.
  • sock_type (int) – Socket type, defaults to TCP.
socket_close(socket_num)

Closes a socket.

socket_connect(socket_num, dest, port, conn_mode=33)

Open and verify we’ve connected a socket to a dest IP address or hostname. By default, we use ‘conn_mode’= SNMR_TCP but we may also use SNMR_UDP.

socket_disconnect(socket_num)

Disconnect a TCP connection.

socket_open(socket_num, conn_mode=33)

Opens a TCP or UDP socket. By default, we use ‘conn_mode’=SNMR_TCP but we may also use SNMR_UDP.

socket_read(socket_num, length)

Reads data from a socket into a buffer. Returns buffer.

socket_status(socket_num)

Returns the socket connection status. Can be: SNSR_SOCK_CLOSED, SNSR_SOCK_INIT, SNSR_SOCK_LISTEN, SNSR_SOCK_SYNSENT, SNSR_SOCK_SYNRECV, SNSR_SYN_SOCK_ESTABLISHED, SNSR_SOCK_FIN_WAIT, SNSR_SOCK_CLOSING, SNSR_SOCK_TIME_WAIT, SNSR_SOCK_CLOSE_WAIT, SNSR_LAST_ACK, SNSR_SOCK_UDP, SNSR_SOCK_IPRAW, SNSR_SOCK_MACRAW, SNSR_SOCK_PPOE.

socket_write(socket_num, buffer)

Writes a bytearray to a provided socket.

sw_reset()

Performs a soft-reset on a Wiznet chip by writing to its MR register reset bit.

udp_remaining()

Returns amount of bytes remaining in a udp socket.

unpretty_ip(ip)

Converts a dotted-quad string to a bytearray IP address

write(addr, callback, data)

Write data to a register address. :param int addr: Destination address. :param int callback: Callback reference. :param int data: Data to write, as an integer. :param bytearray data: Data to write, as a bytearray.

adafruit_wiznet5k_socket

A socket compatible interface with the Wiznet5k module.

  • Author(s): ladyada, Brent Rubell
adafruit_wiznet5k.adafruit_wiznet5k_socket.getaddrinfo(host, port, family=0, socktype=0, proto=0, flags=0)

Translate the host/port argument into a sequence of 5-tuples that contain all the necessary arguments for creating a socket connected to that service.

adafruit_wiznet5k.adafruit_wiznet5k_socket.gethostbyname(hostname)

Translate a host name to IPv4 address format. The IPv4 address is returned as a string. :param str hostname: Desired hostname.

adafruit_wiznet5k.adafruit_wiznet5k_socket.htonl(x)

Convert 32-bit positive integers from host to network byte order.

adafruit_wiznet5k.adafruit_wiznet5k_socket.htons(x)

Convert 16-bit positive integers from host to network byte order.

adafruit_wiznet5k.adafruit_wiznet5k_socket.set_interface(iface)

Helper to set the global internet interface.

class adafruit_wiznet5k.adafruit_wiznet5k_socket.socket(family=3, type=33, proto=0, fileno=None, socknum=None)

A simplified implementation of the Python ‘socket’ class for connecting to a Wiznet5k module. :param int family: Socket address (and protocol) family. :param int type: Socket type.

available()

Returns how many bytes of data are available to be read from the socket.

close()

Closes the socket.

connect(address, conntype=None)

Connect to a remote socket at address. (The format of address depends on the address family — see above.) :param tuple address: Remote socket as a (host, port) tuple.

connected

Returns whether or not we are connected to the socket.

disconnect()

Disconnects a TCP socket.

getpeername()

Return the remote address to which the socket is connected.

gettimeout()

Return the timeout in seconds (float) associated with socket operations, or None if no timeout is set.

inet_aton(ip_string)

Convert an IPv4 address from dotted-quad string format. :param str ip_string: IP Address, as a dotted-quad string.

readline()

Attempt to return as many bytes as we can up to but not including ‘ ‘.

recv(bufsize=0)

Reads some bytes from the connected remote address. :param int bufsize: Maximum number of bytes to receive.

send(data)

Send data to the socket. The socket must be connected to a remote socket. :param bytearray data: Desired data to send to the socket.

settimeout(value)

Sets socket read timeout. :param int value: Socket read timeout, in seconds.

socknum

Returns the socket object’s socket number.

adafruit_wiznet5k_dhcp

Pure-Python implementation of Jordan Terrell’s DHCP library v0.3

  • Author(s): Jordan Terrell, Brent Rubell
class adafruit_wiznet5k.adafruit_wiznet5k_dhcp.DHCP(eth, mac_address, hostname=None, response_timeout=3, debug=False)

W5k DHCP Client implementation. :param eth: Wiznet 5k object :param list mac_address: Hardware MAC. :param str hostname: The desired hostname, with optional {} to fill in MAC. :param int response_timeout: DHCP Response timeout. :param bool debug: Enable debugging output.

parse_dhcp_response(response_timeout)

Parse DHCP response from DHCP server. Returns DHCP packet type.

Parameters:response_timeout (int) – Time to wait for server to return packet, in seconds.
request_dhcp_lease()

Request to renew or acquire a DHCP lease.

send_dhcp_message(state, time_elapsed)

Assemble and send a DHCP message packet to a socket. :param int state: DHCP Message state. :param float time_elapsed: Number of seconds elapsed since renewal.