Example explanation 14-WiFi-Shield->mjpeg_streamer_ap hotspot

Video tutorial 12 - WIFI wireless image transmission: https://singtown.com/learn/50005/
Video Tutorial 39 - WIFI Programming for OpenMV Remote Debugging: https://singtown.com/learn/50899/

WINC1500 WIFI Expansion Board Use this URL: http://192.168.1.1:8080 to view the stream.

OpenMV RT uses this URL: http://192.168.4.1:8080 to view the stream.

# MJPEG Streaming AP.
#
# 这个例子展示了如何在AccessPoint模式下进行MJPEG流式传输。
# Android上的Chrome,Firefox和MJpegViewer App已经过测试。
# 连接到OPENMV_AP,
# WINC1500 WIFI扩展板 使用此URL:http://192.168.1.1:8080查看流。
# OpenMV RT 使用此URL:http://192.168.4.1:8080查看流。

import sensor
import time
import network
import socket

SSID = "OPENMV_AP"  # Network SSID
KEY = "1234567890"  # wifi密码(必须为10字符)
HOST = ""           # 使用第一个可用的端口
PORT = 8080         # 任意非特权端口

# 重置感光元件
sensor.reset()
sensor.set_framesize(sensor.QQVGA)
sensor.set_pixformat(sensor.GRAYSCALE)

# 在AP模式下启动wlan模块。
wlan = network.WLAN(network.AP_IF)
wlan.config(ssid=SSID, key=KEY, channel=2)
wlan.active(True)

print("AP mode started. SSID: {} IP: {}".format(SSID, wlan.ifconfig()[0]))

# 您可以阻止等待客户端连接
# print(wlan.wait_for_sta(100000))


def start_streaming(client):
    # 从客户端读取请求
    data = client.recv(1024)
    # 应该在这里解析客户端请求

    # 发送多部分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()

    # 开始流媒体图像
    # 注:禁用IDE预览以增加流式帧率。
    while True:
        clock.tick()  # 跟踪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.sendall(header)
        client.sendall(cframe)
        print(clock.fps())


server = None

while True:
    if server is None:
        # 创建服务器套接字
        server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
        # 绑定和监听
        server.bind([HOST, PORT])
        server.listen(5)
        # Set server socket to blocking
        server.setblocking(True)

    try:
        print("Waiting for connections..")
        client, addr = server.accept()
    except OSError as e:
        server.close()
        server = None
        print("server socket error:", e)
        continue

    try:
        # 将客户端套接字超时设置为5秒
        client.settimeout(5.0)
        print("Connected to " + addr[0] + ":" + str(addr[1]))
        start_streaming(client)
    except OSError as e:
        client.close()
        print("client socket error:", e)
        # sys.print_exception(e)

results matching ""

    No results matching ""