Connect with us

W600-pico webserver

Discussion in 'Microcontrollers, Programming and IoT' started by Harald Kapp, Mar 23, 2020.

Scroll to continue with content
  1. Harald Kapp

    Harald Kapp Moderator Moderator

    Nov 17, 2011
    Just got me a pair of W600-pico modules with built-in micropython interpreter.
    These modules are relatively recent and documentation is scarce.
    Using REPL via terminal and accessing the filesystem via ftpserver works like a charm.

    Where I'm stuck is this: Could anyone point me to info how to create a webserver in mircopython for these modules so I can read input and control outputs via a HTML page?
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    Nov 17, 2011
    I found out how to do it by cobbling together info from several websites and tutorials:
    # based mainly on
    from machine import Pin
    import network, gc
    import easyw600, w600
    # setup garbage collection
    print("Connecting to local WiFi") #debugging
    # connect to local WiFi network
    ssid = "My_Dark_Home_Network"
    password = "HartToTell"
    easyw600.connect(ssid, password)
    print("Connection successful")
    # setup the webserver
        import usocket as socket
        import socket
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # create new socket, address family type = AF_INET, socket type = SOCK_STREAM
    s.bind(('', 80))
    s.listen(5) # accept connections. backlog = 5 = max. number of unaccepted connections before refusing new connections
    # interact with the hardware
    led = Pin(Pin.PA_00, Pin.OUT, Pin.PULL_FLOATING)
    led_off = 1 # inverted logic
    led_on = 0
    # web page data
    def web_page():
        file = open("index.html", "r")
        page =
        return page
    # this is the main loop to handle requests
    while True:
        conn, addr = s.accept() # accept connection with a new socket object "conn" to remote address "addr"
        request = conn.recv(1024) # receive from connected socket "conn" using 1024 byte buffer
        print(request) # for debugging only
        if "GET /?led=on" in request:
        if "GET /?led=off" in request:
    #    led_status = ("ON", "OFF") led.value() ==1 # this should be valid python code, too, but I prefer the better readable form below.
        if led.value == 1: # same as before but imho better readable
            led_status = "ON"
            led_status = "OFF"
        response = web_page() % led_status # insert the actual status into the web page
        print(response) # debug
        conn.send("HTTP/1.1 200 OK\n")
        conn.send("Content-type: text /html\n")
        conn.send("Connection: close\n\n")
    You need the index.html file, too:
        <h1>Hello - This is my micropython webserver's index.html</h1>
        <p>LED Status: <strong>%s</strong></p>
        <p><button onclick="window.location.href = '/?led=on'">ON</button></p>
        <p><button onclick="window.location.href = '/?led=off'">OFF</button> </p> 
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
Electronics Point Logo
Continue to site
Quote of the day