comunicación wifi
Vídeo tutorial 12 - Transmisión de imágenes inalámbrica WIFI: https://singtown.com/learn/50005/
Tutoriel vidéo 39 - Programmation WIFI pour le débogage à distance OpenMV : https://singtown.com/learn/50899/
Vídeo tutorial 30 - Placa de expansión de transmisión de imágenes por cable: https://singtown.com/learn/50521/
Vídeo tutorial 31 - Placa de expansión de transmisión de imágenes inalámbrica: https://singtown.com/learn/50535/
La placa de expansión oficial de OpenMV utiliza el módulo ATWINC1500, que puede transmitir imágenes.
Información detallada: http://singtown.cc/product/openmv-wifi expansion board/\ Si desea utilizar ESP8266, simplemente utilice la comunicación en serie.
escaneo wifi
Transfiera imágenes de forma inalámbrica
Transmisión inalámbrica de coordenadas de pelota
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)
De manera similar a transferir imágenes, ingrese IP: PUERTO en el navegador y la IP se podrá ver en el terminal. Si es una placa de expansión Wi-Fi: 192.168.1.1:8080 Si es OpenMV RT: 192.168.4.1:8080 puedes obtener los datos json
Si desea obtener los datos en su propio código, simplemente OBTÉN la URL y obtendrá JSON.
Por ejemplo pitón:
import requests
r = requests.get('192.168.1.1:8080')
Solo transfiere una imagen
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)
Si es una placa de expansión Wi-Fi: ingrese 192.168.1.1:8080 en el navegador. Si es OpenMV RT: ingrese 192.168.4.1:8080 en el navegador para ver una imagen.