communication Wi-Fi

Tutoriel vidéo 12 - Transmission d'images sans fil WIFI : https://singtown.com/learn/50005/

Tutoriel vidéo 39 - Programmation WIFI pour le débogage à distance OpenMV : https://singtown.com/learn/50899/

Tutoriel vidéo 30 - Carte d'extension de transmission d'image filaire : https://singtown.com/learn/50521/

Tutoriel vidéo 31 - Carte d'extension de transmission d'images sans fil : https://singtown.com/learn/50535/

La carte d'extension officielle OpenMV utilise le module ATWINC1500, qui peut transmettre des images.

Informations détaillées : http://singtown.cc/product/openmv-wifi expansion board/\ Si vous souhaitez utiliser ESP8266, utilisez simplement la communication série.

analyse Wi-Fi

Transférer des images sans fil

Transmission sans fil des coordonnées du ballon

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)

Semblable au transfert d'images, entrez IP:PORT dans le navigateur et l'adresse IP sera visible dans le terminal. S'il s'agit d'une carte d'extension Wi-Fi : 192.168.1.1:8080 S'il s'agit d'OpenMV RT : 192.168.4.1:8080, vous pouvez obtenir les données json

Si vous souhaitez obtenir les données dans votre propre code, OBTENEZ simplement l'URL et vous obtiendrez JSON.

Par exemple python :

import requests
r = requests.get('192.168.1.1:8080')

Transférer une seule photo

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)

S'il s'agit d'une carte d'extension Wi-Fi : saisissez 192.168.1.1:8080 dans le navigateur. S'il s'agit d'OpenMV RT : saisissez 192.168.4.1:8080 dans le navigateur pour afficher une image.

results matching ""

    No results matching ""