openmv可以通过使用乐鑫的esp8266连接阿里云吗
-
openmv可以通过使用乐鑫的esp8266连接阿里云吗
-
可以,用串口传输数据就行。
-
有没有实例代码?
import sensor
import time
import network
import socketSSID = "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)
可以从这个代码里改吗,怎么改呢?
-
@kidswong999 有没有示例代码?
-
@b4a5 我目前也正在研究这个openmv跟阿里云进行连接?可以跟你交流一下么?