例程讲解14-WiFi-Shield->mjpeg_streamer_ap 热点
import sensor, image, time, network, usocket, sys
SSID ='OPENMV_AP'
KEY ='1234567890'
HOST = ''
PORT = 8080
sensor.reset()
sensor.set_contrast(1)
sensor.set_brightness(1)
sensor.set_saturation(1)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.QQVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
wlan = network.WINC(mode=network.WINC.MODE_AP)
wlan.start_ap(SSID, key=KEY, security=wlan.WEP, channel=2)
def start_streaming(s):
print ('Waiting for connections..')
client, addr = s.accept()
client.settimeout(2.0)
print ('Connected to ' + addr[0] + ':' + str(addr[1]))
data = client.recv(1024)
client.send("HTTP/1.1 200 OK\r\n" \
"Server: OpenMV\r\n" \
"Content-Type: multipart/x-mixed-replace;boundary=openmv\r\n" \
"Cache-Control: no-cache\r\n" \
"Pragma: no-cache\r\n\r\n")
clock = time.clock()
while (True):
clock.tick()
frame = sensor.snapshot()
cframe = frame.compressed(quality=35)
header = "\r\n--openmv\r\n" \
"Content-Type: image/jpeg\r\n"\
"Content-Length:"+str(cframe.size())+"\r\n\r\n"
client.send(header)
client.send(cframe)
print(clock.fps())
while (True):
s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
try:
s.bind([HOST, PORT])
s.listen(5)
s.settimeout(3)
start_streaming(s)
except OSError as e:
s.close()
print("socket error: ", e)
星瞳科技OpenMV官方中文文档函数讲解:
星瞳科技OpenMV官方中文文档函数讲解: