OpenMV官方扩展板采用ATWINC1500模组,可以传输图像。
详细资料:http://singtown.cc/product/openmv-wifi扩展板/
如果想使用ESP8266,使用串口通信就可以。
wifi扫描
无线传输图像
无线传输小球坐标
import sensor
import time
import network
import socket
import json
SSID ='OPENMV_AP' # Network SSID
KEY ='1234567890' # Network key (must be 10 chars)
HOST = '' # Use first available interface
PORT = 8080 # Arbitrary non-privileged port
green_threshold = ( 0, 80, -70, -10, -0, 30)
# Reset sensor
sensor.reset()
sensor.set_framesize(sensor.QQVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
# Init wlan module in AP mode.
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]))
# You can block waiting for client to connect
# print(wlan.wait_for_sta(100000))
def response(client):
# 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: application/json\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.
img = sensor.snapshot()
blobs = img.find_blobs([green_threshold])
if blobs:
for b in blobs:
img.draw_rectangle(b[0:4]) # rect
img.draw_cross(b[5], b[6]) # cx, cy
client.send(json.dumps(blobs))
client.close()
server = None
while True:
if server is None:
# Create server socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
# Bind and listen
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:
# set client socket timeout to 2s
client.settimeout(5.0)
print("Connected to " + addr[0] + ":" + str(addr[1]))
response(client)
except OSError as e:
client.close()
print("client socket error:", e)
# sys.print_exception(e)
与传输图像类似,浏览器输入IP:PORT, IP在终端可以看到。 如果是Wi-Fi扩展板:192.168.1.1:8080 如果是OpenMV RT: 192.168.4.1:8080 就可以获得json数据
如果想在自己的代码中获得数据,只需要GET网址, 就会获得JSON。
例如python:
import requests
r = requests.get('192.168.1.1:8080')
只传输一张图片
import sensor
import time
import network
import socket
import json
SSID ='OPENMV_AP' # Network SSID
KEY ='1234567890' # Network key (must be 10 chars)
HOST = '' # Use first available interface
PORT = 8080 # Arbitrary non-privileged port
green_threshold = ( 0, 80, -70, -10, -0, 30)
# Reset sensor
sensor.reset()
sensor.set_framesize(sensor.QQVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
# Init wlan module in AP mode.
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]))
# You can block waiting for client to connect
# print(wlan.wait_for_sta(100000))
def response(client):
# Read request from client
data = client.recv(1024)
# Should parse client request here
# Send jpeg header
client.send("HTTP/1.1 200 OK\r\n" \
"Server: OpenMV\r\n" \
"Content-Type: image/jpeg\r\n\r\n")
frame = sensor.snapshot()
cframe = frame.compressed(quality=35)
client.send(cframe)
client.close()
server = None
while True:
if server is None:
# Create server socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
# Bind and listen
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:
# set client socket timeout to 2s
client.settimeout(5.0)
print("Connected to " + addr[0] + ":" + str(addr[1]))
response(client)
except OSError as e:
client.close()
print("client socket error:", e)
# sys.print_exception(e)
如果是Wi-Fi扩展板:浏览器输入192.168.1.1:8080 如果是OpenMV RT:浏览器输入192.168.4.1:8080 ,即可查看一张图片。