logo

mjpeg_streamer.py运行不成功

2022-11-10 19:57
W
gu45

显示Type "help()" for more information.

>>> Trying to connect... (may take a while)...

Traceback (most recent call last):

File "<stdin>", line 22, in <module>

Exception: IDE interrupt

MicroPython: v1.18-omv-r13 OpenMV: v4.3.2 HAL: v1.9.0 BOARD: OPENMV4-STM32H743

Type "help()" for more information.

>>>

Trying to connect... (may take a while)...

然后就阻塞没有反应了。相应代码如下:

# 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

SSID ='xyzbalabala'     # Network SSID
KEY  ='12345678'     # Network key
HOST =''     # Use first available interface
PORT = 8080  # Arbitrary non-privileged port

# Reset sensor
sensor.reset()
sensor.set_framesize(sensor.QQVGA)
sensor.set_pixformat(sensor.GRAYSCALE)

# Init wlan module and connect to network
print("Trying to connect... (may take a while)...")
wlan = network.WINC()
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])
s.listen(5)

# Set server socket to blocking
s.setblocking(True)

def start_streaming(s):
    print ('Waiting for connections..')
    client, addr = s.accept()
    # set client socket timeout to 2s
    client.settimeout(2.0)
    print ('Connected to ' + addr[0] + ':' + str(addr[1]))

    # Read request from client
    data = client.recv(1024)
    # Should parse client request here

    # Send multipart header
    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")

    # FPS clock
    clock = time.clock()

    # Start streaming images
    # NOTE: Disable IDE preview to increase streaming FPS.
    while (True):
        clock.tick() # Track elapsed milliseconds between snapshots().
        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):
    try:
        start_streaming(s)
    except OSError as e:
        print("socket error: ", e)
        #sys.print_exception(e

)

2022-11-10 20:39
W
gu45

我把print(wlan.ifconfig())注释掉了后,程序能运行到print ('Waiting for connections..') 串口打印出了信息,然后又block了

2022-11-14 15:06
I
网红小智智 星瞳科技

看上去没连接上路由器的WiFi。确认密码对,和加密方式是WPA_PSK。