comunicazione Wi-Fi

Tutorial video 12 - Trasmissione di immagini wireless Wi-Fi: https://singtown.com/learn/50005/

Tutorial video 39 - Programmazione Wi-Fi per il debug remoto di OpenMV: https://singtown.com/learn/50899/

Tutorial video 30 - Scheda di espansione trasmissione immagini via cavo: https://singtown.com/learn/50521/

Tutorial video 31 - Scheda di espansione per la trasmissione wireless di immagini: https://singtown.com/learn/50535/

La scheda di espansione ufficiale OpenMV utilizza il modulo ATWINC1500, che può trasmettere immagini.

Informazioni dettagliate: http://singtown.cc/product/openmv-wifi scheda di espansione/\ Se desideri utilizzare ESP8266, utilizza semplicemente la comunicazione seriale.

scansione Wi-Fi

Trasferisci le immagini in modalità wireless

Trasmissione wireless delle coordinate della palla

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)

Similmente al trasferimento delle immagini, inserisci IP:PORT nel browser e l'IP potrà essere visualizzato nel terminale.Se è una scheda di espansione Wi-Fi: 192.168.1.1:8080 Se è OpenMV RT: 192.168.4.1:8080 puoi ottenere i dati json

Se desideri ottenere i dati nel tuo codice, OTTIENI semplicemente l'URL e otterrai JSON.

Ad esempio pitone:

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

Trasferisci solo una foto

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)

Se si tratta di una scheda di espansione Wi-Fi: immettere 192.168.1.1:8080 nel browser Se si tratta di OpenMV RT: immettere 192.168.4.1:8080 nel browser per visualizzare un'immagine.

results matching ""

    No results matching ""