mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Update MJPEG streaming examples.
This commit is contained in:
parent
0d19f693c0
commit
fab730aeeb
@ -1,53 +1,45 @@
|
|||||||
'''
|
'''
|
||||||
Simple MJPEG streaming server
|
Simple MJPEG streaming server
|
||||||
'''
|
'''
|
||||||
import wlan, socket
|
import time, sensor, pyb, network, usocket
|
||||||
import led,time,sensor
|
|
||||||
|
|
||||||
SSID='' # Network SSID
|
SSID='' # Network SSID
|
||||||
KEY='' # Network key
|
KEY='' # Network key
|
||||||
HOST = '' # Use first available interface
|
HOST = '' # Use first available interface
|
||||||
PORT = 8000 # Arbitrary non-privileged port
|
PORT = 8000 # Arbitrary non-privileged port
|
||||||
|
|
||||||
led.off(led.RED)
|
led_r = pyb.LED(1)
|
||||||
led.off(led.BLUE)
|
led_b = pyb.LED(2)
|
||||||
led.on(led.GREEN)
|
led_g = pyb.LED(3)
|
||||||
|
|
||||||
# Init sensor and set sensor parameters
|
# Reset sensor
|
||||||
sensor.reset()
|
sensor.reset()
|
||||||
sensor.set_brightness(-2)
|
|
||||||
|
# Set sensor settings
|
||||||
sensor.set_contrast(1)
|
sensor.set_contrast(1)
|
||||||
|
sensor.set_brightness(1)
|
||||||
|
sensor.set_saturation(1)
|
||||||
|
sensor.set_gainceiling(16)
|
||||||
sensor.set_framesize(sensor.QVGA)
|
sensor.set_framesize(sensor.QVGA)
|
||||||
sensor.set_pixformat(sensor.JPEG)
|
sensor.set_pixformat(sensor.RGB565)
|
||||||
|
|
||||||
# Init wlan module and connect to network
|
# Init wlan module and connect to network
|
||||||
wlan.init()
|
wlan = network.WINC()
|
||||||
wlan.connect(SSID, sec=wlan.WPA2, key=KEY)
|
wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK)
|
||||||
led.off(led.GREEN)
|
|
||||||
|
|
||||||
# Wait for connection to be established
|
|
||||||
while (True):
|
|
||||||
led.toggle(led.BLUE)
|
|
||||||
time.sleep(250)
|
|
||||||
led.toggle(led.BLUE)
|
|
||||||
time.sleep(250)
|
|
||||||
if wlan.connected():
|
|
||||||
led.on(led.BLUE)
|
|
||||||
break;
|
|
||||||
|
|
||||||
# We should have a valid IP now via DHCP
|
# We should have a valid IP now via DHCP
|
||||||
wlan.ifconfig()
|
print(wlan.ifconfig())
|
||||||
|
|
||||||
# Create server socket
|
# Create server socket
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
|
s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
|
||||||
|
|
||||||
# Set socket in blocking mode
|
|
||||||
s.setblocking(True)
|
|
||||||
|
|
||||||
# Bind and listen
|
# Bind and listen
|
||||||
s.bind((HOST, PORT))
|
s.bind((HOST, PORT))
|
||||||
s.listen(5)
|
s.listen(5)
|
||||||
|
|
||||||
|
# Set timeout to 1s
|
||||||
|
s.settimeout(1.0)
|
||||||
|
|
||||||
print ('Waiting for connections..')
|
print ('Waiting for connections..')
|
||||||
client, addr = s.accept()
|
client, addr = s.accept()
|
||||||
print ('Connected to ' + addr[0] + ':' + str(addr[1]))
|
print ('Connected to ' + addr[0] + ':' + str(addr[1]))
|
||||||
@ -70,7 +62,7 @@ while (True):
|
|||||||
client.send("\r\n--openmv\r\n" \
|
client.send("\r\n--openmv\r\n" \
|
||||||
"Content-Type: image/jpeg\r\n"\
|
"Content-Type: image/jpeg\r\n"\
|
||||||
"Content-Length:"+str(frame.size())+"\r\n\r\n")
|
"Content-Length:"+str(frame.size())+"\r\n\r\n")
|
||||||
client.send(frame)
|
client.send(frame.compress(50))
|
||||||
time.sleep(30)
|
time.sleep(10)
|
||||||
|
|
||||||
client.close()
|
client.close()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user