tweak
This commit is contained in:
parent
dd8a95b9fc
commit
fa9fd15fae
1 changed files with 23 additions and 4 deletions
|
|
@ -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,11 +33,22 @@ 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():
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue