买了WiFi模块,用IDE自带例程没问题,根据文档可以用非阻塞链接,并推荐用select的Poll类,我的代码:
# MJPEG Streaming
#
# This example shows off how to do MJPEG streaming to a FIREFOX webrowser
# Chrome, Firefox and MJpegViewer App on Android have been tested.
# Connect to the IP address/port printed out from ifconfig to view the stream.
import sensor, image, time, network, usocket, sys
import select
SSID ='ZhaoBao' # Network SSID
KEY ='19431121' # Network key
HOST ='192.168.1.30' # Use first available interface
PORT = 8080 # Arbitrary non-privileged port
# Reset sensor
sensor.reset()
sensor.set_framesize(sensor.QQVGA)
sensor.set_pixformat(sensor.RGB565)
gs = []
# Init wlan module and connect to network
print("Trying to connect... (may take a while)...")
wlan = network.WINC()
wlan.ifconfig(('192.168.1.30', '255.255.255.0', '192.168.1.1', '192.168.1.1'))
wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK)
# We should have a valid IP now via DHCP
print(wlan.ifconfig())
# Create server socket
s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
# Bind and listen
s.bind([HOST, PORT])
gs.append(s)
s.listen(5)
# Set server socket to blocking
s.setblocking(False)
p = select.poll()
p.register(s)
while (True):
try:
events = p.poll(900)
if (len(events) > 0):
print(events)
for fd,event in events:
if fd in gs:
c,addr = s.accept()
print('got connection from',addr)
p.register(c,select.POLLIN)
gs[0] = c
elif event & select.POLLIN:
data = c.recv[1024]
if not data:
print(c.getpeername,'disconnected')
p.unregister(c)
del gs[0]
else:
print (data)
except OSError as e:
print("poll error:",e)
continue
但是执行到”events = p.poll(900)“都出错[Error 5] EIO,是不是系统不支持呀?
请教哪位老师帮助检查一下问题出错在哪里呢?谢谢了!