W55RP20-EVB-PICO https example
Secure HTTPS Client Example Using WIZnet W5x00 Ethernet Module on MicroPython

Wiznet - WIZnet-ioNIC-micropython
x 1
Source Code Explanation
Imports:
- socket, ussl: Used for establishing TCP connections and wrapping them in SSL/TLS for secure HTTPS communication.
- network: Handles network interface configuration.
- time: Provides timing functionalities for delays or timeouts.
- w5x00_init: Initializes the WIZnet W5x00 Ethernet module, setting up the network hardware.
Connection Settings:
- host: Defines the target HTTPS server domain (e.g., “api.github.com” or similar).
- port: Set to 443, the standard port for HTTPS communication.
- The server’s IP address is resolved using socket.getaddrinfo() based on the provided host and port.
https_client():
- Initializes the Ethernet interface by calling w5x00_init(), which configures the WIZnet module and retrieves the board’s IP address.
- Resolves the server’s address via socket.getaddrinfo() to obtain the connection endpoint.
- Creates a TCP socket and connects to the resolved server address.
- Wraps the connected socket with SSL using ussl.wrap_socket(), establishing a secure (encrypted) channel.
- Constructs an HTTP GET request (including the appropriate Host header) targeting the root path (“/“).
- Sends the HTTP request over the SSL-wrapped socket.
- Receives the response (likely the HTTP response headers and body) from the HTTPS server and prints it.
- Closes the socket to clean up the connection.
Execution Flow:
- The script runs as the main module.
- Upon execution, the https_client() function is invoked, performing the following steps:
- Ethernet initialization via w5x00_init().
- Server address resolution and secure TCP connection establishment.
- Sending of an HTTP GET request and receiving the server’s response.
- Closing of the connection post data exchange.
▶ How to Run
Prepare Hardware:
- Connect the WIZnet W5x00 Ethernet module to the MicroPython board.
- Ensure the board is connected to a network (via Ethernet).
Deploy Code:
- Upload HTTPS_Client.py to the MicroPython board.
- Execute the script via the REPL or configure it to run on boot.
Execution Result:
- On Success:
• The board initializes its Ethernet interface.
• Establishes a secure connection to the HTTPS server.
• Sends an HTTP GET request and prints the received HTTP response. - On Failure:
• Error messages (e.g., network connection issues or SSL handshake failures) are displayed.