AymanSaleh23 / VehiclesTransparent

Graduation Project 2022-2023 supported by Valeo co. mentorship program
4 stars 1 forks source link

Wi-Fi direct communication #33

Open mmagdiab opened 1 year ago

mmagdiab commented 1 year ago

As https://www.wi-fi.org/discover-wi-fi/wi-fi-direct states, we connect 2 devices using Wi-Fi direct capability without the need of access point. I highly recommend using Wi-Fi direct in our implementation. Please, reply ASAP @AymanSaleh23

AymanSaleh23 commented 1 year ago

This is actually a good idea, I will keep that in mind to next step and I will study how to implement that approach

AymanSaleh23 commented 1 year ago

Wi-Fi Direct is a wireless communication protocol that allows two devices to connect to each other without the need for a traditional wireless access point or router. It was first introduced in 2009 by the Wi-Fi Alliance as a way to simplify the process of connecting devices to each other.

Unlike traditional Wi-Fi networks, which require a wireless access point or router to mediate communication between devices, Wi-Fi Direct allows two devices to connect directly to each other. This can be useful in situations where no wireless access point or router is available, such as in remote areas or during outdoor activities.

Wi-Fi Direct is based on the IEEE 802.11 standard, which is also used for traditional Wi-Fi networks. It uses the same radio frequencies and channels as traditional Wi-Fi networks, but operates in a different mode that allows two devices to connect directly to each other.

To use Wi-Fi Direct, both devices must support the protocol. Once the devices are connected, they can communicate with each other using standard network protocols, such as TCP/IP or HTTP.

Wi-Fi Direct has several advantages over traditional Wi-Fi networks, including:

Easy setup: Wi-Fi Direct does not require a separate wireless access point or router, making it easy to set up and use.

Direct connection: Wi-Fi Direct allows two devices to connect directly to each other, without the need for an intermediate device.

Security: Wi-Fi Direct supports a variety of security protocols, including WPA2 and AES encryption, to protect data transmitted between devices.

Low power consumption: Wi-Fi Direct uses less power than traditional Wi-Fi networks, making it suitable for use in battery-powered devices.

High speed: Wi-Fi Direct supports high-speed data transfer rates, making it suitable for transferring large files or streaming video.

Wi-Fi Direct has a wide range of applications, including file sharing, printing, media streaming, gaming, and device mirroring. It is supported by a wide range of devices, including smartphones, tablets, laptops, and smart TVs.

AymanSaleh23 commented 1 year ago

Sending video streaming between two machines using WiFi Direct and socket programming in Python can be achieved by following these general steps:

Capture video frames from a camera on one machine. Convert each frame to a byte stream format for transmission. Establish a WiFi Direct connection between the two machines. Establish a socket connection between the two machines. Send the video frames over the socket connection. Reconstruct the frames on the receiving machine and display the video stream.

AymanSaleh23 commented 1 year ago

Here's an example code that demonstrates how to send video streaming between two machines using WiFi Direct and socket programming in Python:

import cv2
import numpy as np
import socket
from wifi_direct import WifiDirectGroup

# Set up the video capture
cap = cv2.VideoCapture(0)

# Create a WiFi Direct group
group = WifiDirectGroup.create_group()

# Discover nearby devices
devices = group.discover()

# Connect to the first device found
device = devices[0]
device.connect()

# Set up the socket connection
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = (device.ip_address, 12345)
sock.bind(server_address)
sock.listen(1)
connection, client_address = sock.accept()

# Send the video frames
while True:
    ret, frame = cap.read()

    # Convert the frame to a byte stream
    data = cv2.imencode('.jpg', frame)[1].tostring()

    # Send the data over the socket connection
    connection.sendall(data)

# Clean up
cap.release()
connection.close()
sock.close()
device.close()
AymanSaleh23 commented 1 year ago

On the receiving machine, you would use a similar code to establish a WiFi Direct connection and socket connection, and receive the video frames:

import cv2
import numpy as np
import socket
from wifi_direct import WifiDirectGroup

# Create a WiFi Direct group
group = WifiDirectGroup.create_group()

# Discover nearby devices
devices = group.discover()

# Connect to the first device found
device = devices[0]
device.connect()

# Set up the socket connection
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = (device.ip_address, 12345)
sock.connect(server_address)

# Receive and display the video frames
while True:
    data = b''
    while True:
        chunk = sock.recv(1024)
        if not chunk:
            break
        data += chunk

    # Convert the byte stream to a frame
    frame = cv2.imdecode(np.fromstring(data, dtype=np.uint8), cv2.IMREAD_COLOR)

    # Display the frame
    cv2.imshow('Video Stream', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# Clean up
cv2.destroyAllWindows()
sock.close()
device.close()