mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Merge pull request #1983 from kwagyeman/kwabena/mjpeg_update
scripts: Improve OpenMV Boards MJPEG Examples.
This commit is contained in:
commit
1ba74580b7
@ -29,6 +29,7 @@ print(wlan.ifconfig())
|
||||
|
||||
# Create server socket
|
||||
s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
|
||||
s.setsockopt(usocket.SOL_SOCKET, usocket.SO_REUSEADDR, True)
|
||||
|
||||
# Bind and listen
|
||||
s.bind([HOST, PORT])
|
||||
@ -50,7 +51,7 @@ def start_streaming(s):
|
||||
# Should parse client request here
|
||||
|
||||
# Send multipart header
|
||||
client.send(
|
||||
client.sendall(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Server: OpenMV\r\n"
|
||||
"Content-Type: multipart/x-mixed-replace;boundary=openmv\r\n"
|
||||
@ -72,8 +73,8 @@ def start_streaming(s):
|
||||
"Content-Type: image/jpeg\r\n"
|
||||
"Content-Length:" + str(cframe.size()) + "\r\n\r\n"
|
||||
)
|
||||
client.send(header)
|
||||
client.send(cframe)
|
||||
client.sendall(header)
|
||||
client.sendall(cframe)
|
||||
print(clock.fps())
|
||||
|
||||
|
||||
|
||||
@ -62,18 +62,21 @@ def start_streaming(s):
|
||||
"Content-Type: image/jpeg\r\n"
|
||||
"Content-Length:" + str(cframe.size()) + "\r\n\r\n"
|
||||
)
|
||||
client.send(header)
|
||||
client.send(cframe)
|
||||
client.sendall(header)
|
||||
client.sendall(cframe)
|
||||
print(clock.fps())
|
||||
|
||||
|
||||
while True:
|
||||
# Create server socket
|
||||
s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
|
||||
s.setsockopt(usocket.SOL_SOCKET, usocket.SO_REUSEADDR, True)
|
||||
try:
|
||||
# Bind and listen
|
||||
s.bind([HOST, PORT])
|
||||
s.listen(5)
|
||||
# Set server socket to blocking
|
||||
s.setblocking(True)
|
||||
|
||||
# Set server socket timeout
|
||||
# NOTE: Due to a WINC FW bug, the server socket must be closed and reopened if
|
||||
|
||||
@ -37,6 +37,9 @@ s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
|
||||
s.bind((HOST, PORT))
|
||||
s.listen(5)
|
||||
|
||||
# Set server socket to blocking
|
||||
s.setblocking(True)
|
||||
|
||||
# Set timeout to 1s
|
||||
s.settimeout(1.0)
|
||||
|
||||
@ -78,11 +81,11 @@ while True:
|
||||
image.draw_string(0, 16, "To max: %0.2f" % to_max, color=(0xFF, 0x00, 0x00))
|
||||
|
||||
cimage = image.compressed(quality=90)
|
||||
client.send(
|
||||
client.sendall(
|
||||
"\r\n--openmv\r\n"
|
||||
"Content-Type: image/jpeg\r\n"
|
||||
"Content-Length:" + str(cimage.size()) + "\r\n\r\n"
|
||||
)
|
||||
client.send(cimage)
|
||||
client.sendall(cimage)
|
||||
|
||||
client.close()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user