Skip to content

Raspberry Pi Pico W AP Mode: Host a Web Server | ShillehTek

October 23, 2023

Video Tutorial (Optional)

Watch first if you want to follow the full AP mode setup and web server test in real time.

Project Overview

Raspberry Pi Pico W AP mode web server: In this project, you use a Raspberry Pi Pico W in AP mode (access point mode) to create your own WiFi network and host a simple MicroPython web server that serves a “Hello World” page to connected devices.

AP mode means the Pico W creates its own wireless network that other devices (phone or computer) can connect to. This can be used for hosting a local web server, controlling other devices, sharing files, or creating a temporary network for testing.

Subscribe and support links from the original post:

  • Time: 15 to 30 minutes
  • Skill level: Beginner
  • What you will build: A Pico W hosted WiFi network (AP mode) with a basic socket web server that returns an HTML page

Parts List

From ShillehTek

External

  • Raspberry Pi Pico W - the WiFi microcontroller running the AP and web server
  • USB cable - for power and programming
  • Computer with MicroPython IDE (example: Thonny) - to edit and run the script
  • Phone or computer with WiFi - to connect to the Pico W network and open the web page

Note: This tutorial binds the server to port 80 and prints the Pico W IP address to the console. Your device connects directly to the Pico W network, not the internet.

Step-by-Step Guide

Step 1 - Load and run the MicroPython AP mode web server code

Goal: Put the Pico W into AP mode and start a simple socket-based web server that returns an HTML page.

What to do: In your MicroPython environment (example: Thonny), copy the code below to your Pico W and run it.

Set the SSID and password at the bottom of the script (replace NAME and PASSWORD).

Code:

import network
import time
import socket


def web_page():
  html = """<html><head><meta name="viewport" content="width=device-width, initial-scale=1"></head>
            <body><h1>Hello World</h1></body></html>
         """
  return html

# if you do not see the network you may have to power cycle
# unplug your pico w for 10 seconds and plug it in again
def ap_mode(ssid, password):
    """
        Description: This is a function to activate AP mode

        Parameters:

        ssid[str]: The name of your internet connection
        password[str]: Password for your internet connection

        Returns: Nada
    """
    # Just making our internet connection
    ap = network.WLAN(network.AP_IF)
    ap.config(essid=ssid, password=password)
    ap.active(True)

    while ap.active() == False:
        pass
    print('AP Mode Is Active, You can Now Connect')
    print('IP Address To Connect to:: ' + ap.ifconfig()[0])

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)   #creating socket object
    s.bind(('', 80))
    s.listen(5)

    while True:
      conn, addr = s.accept()
      print('Got a connection from %s' % str(addr))
      request = conn.recv(1024)
      print('Content = %s' % str(request))
      response = web_page()
      conn.send(response)
      conn.close()

ap_mode('NAME',
        'PASSWORD')

Expected result: The Pico W console prints that AP mode is active and shows the IP address to connect to.

Step 2 - Connect to the Pico W WiFi network from a device

Goal: Join the WiFi network created by the Pico W.

What to do: On your computer or phone, open WiFi settings and find the SSID you configured in the code. Connect using the password you set.

If the network does not appear, power cycle the Pico W: unplug it for 10 seconds, plug it back in, and rerun the code.

Phone or computer WiFi settings showing the Raspberry Pi Pico W access point (AP mode) network SSID available to connect
Example of the Pico W AP mode network showing up in a device’s WiFi list.

Expected result: Your device connects to the Pico W network successfully.

Step 3 - Open the web page from a browser using the Pico W IP

Goal: Verify the Pico W web server responds over the AP mode network.

What to do: Open a web browser on the connected device and navigate to the IP address printed in the Pico W console (your IP will likely be different).

Web browser address bar showing the Raspberry Pi Pico W AP mode IP address used to open the local web server
Navigate to the Pico W IP address shown in the console output.
Browser page displaying Hello World served by the Raspberry Pi Pico W MicroPython web server while in AP mode
The Pico W serves a simple “Hello World” HTML page to connected clients.

Expected result: The browser displays the “Hello World” page, and the Pico W console logs incoming connections and requests.

Conclusion

You set up a Raspberry Pi Pico W in AP mode and hosted a simple MicroPython web server that serves an HTML page to any device connected to the Pico W WiFi network. This is a useful foundation for local device control pages, offline dashboards, and direct device-to-device communication.

Want the exact parts used in this build? Grab what you need from ShillehTek.com. If you want help customizing this project or building something similar for your product, check out our consulting: https://shillehtek.com/pages/iot-consulting.