Merge pull request #1983 from kwagyeman/kwabena/mjpeg_update

scripts: Improve OpenMV Boards MJPEG Examples.
This commit is contained in:
Ibrahim Abdelkader 2023-10-22 14:35:49 +03:00 committed by GitHub
commit 1ba74580b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 7 deletions

View File

@ -29,6 +29,7 @@ print(wlan.ifconfig())
# Create server socket # Create server socket
s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM) s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
s.setsockopt(usocket.SOL_SOCKET, usocket.SO_REUSEADDR, True)
# Bind and listen # Bind and listen
s.bind([HOST, PORT]) s.bind([HOST, PORT])
@ -50,7 +51,7 @@ def start_streaming(s):
# Should parse client request here # Should parse client request here
# Send multipart header # Send multipart header
client.send( client.sendall(
"HTTP/1.1 200 OK\r\n" "HTTP/1.1 200 OK\r\n"
"Server: OpenMV\r\n" "Server: OpenMV\r\n"
"Content-Type: multipart/x-mixed-replace;boundary=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-Type: image/jpeg\r\n"
"Content-Length:" + str(cframe.size()) + "\r\n\r\n" "Content-Length:" + str(cframe.size()) + "\r\n\r\n"
) )
client.send(header) client.sendall(header)
client.send(cframe) client.sendall(cframe)
print(clock.fps()) print(clock.fps())

View File

@ -62,18 +62,21 @@ def start_streaming(s):
"Content-Type: image/jpeg\r\n" "Content-Type: image/jpeg\r\n"
"Content-Length:" + str(cframe.size()) + "\r\n\r\n" "Content-Length:" + str(cframe.size()) + "\r\n\r\n"
) )
client.send(header) client.sendall(header)
client.send(cframe) client.sendall(cframe)
print(clock.fps()) print(clock.fps())
while True: while True:
# Create server socket # Create server socket
s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM) s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
s.setsockopt(usocket.SOL_SOCKET, usocket.SO_REUSEADDR, True)
try: try:
# Bind and listen # Bind and listen
s.bind([HOST, PORT]) s.bind([HOST, PORT])
s.listen(5) s.listen(5)
# Set server socket to blocking
s.setblocking(True)
# Set server socket timeout # Set server socket timeout
# NOTE: Due to a WINC FW bug, the server socket must be closed and reopened if # NOTE: Due to a WINC FW bug, the server socket must be closed and reopened if

View File

@ -37,6 +37,9 @@ s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
s.bind((HOST, PORT)) s.bind((HOST, PORT))
s.listen(5) s.listen(5)
# Set server socket to blocking
s.setblocking(True)
# Set timeout to 1s # Set timeout to 1s
s.settimeout(1.0) 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)) image.draw_string(0, 16, "To max: %0.2f" % to_max, color=(0xFF, 0x00, 0x00))
cimage = image.compressed(quality=90) cimage = image.compressed(quality=90)
client.send( client.sendall(
"\r\n--openmv\r\n" "\r\n--openmv\r\n"
"Content-Type: image/jpeg\r\n" "Content-Type: image/jpeg\r\n"
"Content-Length:" + str(cimage.size()) + "\r\n\r\n" "Content-Length:" + str(cimage.size()) + "\r\n\r\n"
) )
client.send(cimage) client.sendall(cimage)
client.close() client.close()