Toggle Navigation
Hatchery
Eggs
TCPText
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
import uinterface, gc, rgb, usocket, uselect, wifi, utime uinterface.connect_wifi() wifi.wait() tekst = "" finished = True def showchar(c): global tekst global finished if finished: print("Ready for new input") rgb.clear() tekst = "" finished = False for char in c: if (ord(char) < 126 ) and (ord(char) > 31 ): tekst += char if ord(char) == 10: finished = True print("Text received: " + tekst) rgb.scrolltext(tekst,(255,255,255),(0,0)) sta = wifi._STA_IF ip = sta.ifconfig()[0] print("IP: " + ip) addr = usocket.getaddrinfo("0.0.0.0",1234)[0][-1] sock = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM, usocket.IPPROTO_TCP) sock.bind(addr) sock.listen(1) sock.settimeout(None) poll = uselect.poll() rgb.clear() rgb.scrolltext("Connect to: "+ip+":1234",(0,255,192),(0,0)) while True: client, remote_addr = sock.accept() client.settimeout(None) poll.register(client, uselect.POLLIN) try: while True: utime.sleep(0.001) res = poll.poll(750) if res: data = client.read(1).decode("utf-8") if len(data) <= 0: break showchar(data) gc.collect() except Exception as err: print(err) finally: poll.unregister(client) client.close() client = None sock.close()