This commit is contained in:
Tassilo Schweyer 2025-12-29 20:02:30 +01:00
parent dd8a95b9fc
commit fa9fd15fae

View file

@ -4,6 +4,7 @@ import socket
import select
import neopixel
from machine import Pin
import errno
def do_connect(tries=0):
if tries > 3:
@ -32,12 +33,23 @@ def do_connect(tries=0):
def do_ap():
ap_if = network.WLAN(network.WLAN.IF_AP)
ap_if.active(True)
ap_if.config(ssid='My AP123', channel=11, key='asdf1234')
ap_if.config(ssid='My AP123', channel=13, key='asdf1234')
ap_if.ifconfig(('192.168.0.4', '255.255.255.0', '192.168.0.1', '8.8.8.8'))
print(ap_if.config('ssid'))
print(ap_if.config('channel'))
print('AP ready.')
# wait for someone to connect
for i in range(30):
if ap_if.isconnected():
print('Client connected')
return
time.sleep(1)
# reset device
print('Timeout waiting for client. Resetting device..')
machine.reset()
def setup_listener():
addr = socket.getaddrinfo('0.0.0.0', 1337)[0][-1]
@ -144,9 +156,16 @@ def mainloop(l):
if debug:
print('RCV: ', a)
y.write(a)
except OSError:
# timeout
a = b'x'
except OSError as e:
if e.errno == errno.EWOULDBLOCK or e.errno == errno.EAGAIN:
# timeout
a = b'x'
else:
# socket error
if debug:
print('Socket error: ', e)
y.close()
mainloop(l)
if a == b'':
# EOF
y.close()