Toggle Navigation
Hatchery
Eggs
TeXT server
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
import wifi, system, display, usocket as socket, time wifi.connect() display.drawFill(0xFFFFFF) display.drawText(0,0,"Connecting to WiFi...") display.flush() if not wifi.wait(): display.drawFill(0xFFFFFF) display.drawText(0,0,"Unable to connect to WiFi!") display.flush() time.sleep(2) system.launcher() display.drawFill(0xFFFFFF) display.flush() CONTENT = """\ HTTP/1.0 200 OK Hello #{} from MicroPython! """ curIP = wifi._STA_IF.ifconfig()[0] ai = socket.getaddrinfo(curIP,8080) addr = ai[0][4] s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(addr) s.listen(5) counter=0 print('Listening on ', curIP, ':8080') display.drawFill(0xFFFFFF) display.drawText(0,0,curIP + ':8080/text',0x000000,"PermanentMarker22") display.flush() while True: res = s.accept() client_s = res[0] client_addr = res[1] print("Client address:", client_addr) req = client_s.recv(4096) client_s.send(bytes(CONTENT.format(counter), "ascii")) client_s.close() parts = req.decode('ascii').split(' ') parts[1] = parts[1][1:] if parts[1] == 'exit': break if parts[1] != 'favicon.ico': print('data:', parts[1]) display.drawFill(0xFFFFFF) display.drawText(0,0,parts[1],0x000000,"PermanentMarker22") display.flush() counter += 1