This project provides two applications for setting up a Wifi Direct connection between a Raspberry Pi 3b and an android
phone.
Contains config scripts as well code for setting up a connection, setting up a TCP socket, and exchanging data
on both the android and the pi.
To establish a P2P connection between the raspberry pi and an android phone two steps are required:
- Setup the Raspberry Pi and start the P2P server on the Raspberry Pi
- connect to the raspberry pi using Wi-Fi direct from the raspberry pi
To be able to establish a P2P connection between a Raspberry Pi and an android phone a few packages need to be installed
some configurations must be changed. For that reason the repository contains the installation script raspberry-config.sh
.
After running this script the Raspberry Pi will lose the current Wi-Fi connection. It's still possible to communicate
with the Raspberry Pi using a wired connection.
To start the P2P connector run this command:
python3 pi_server/p2p_connector/wifi_direct_connetor.py [target_device_name]
The Raspberry Pi is now waiting for an incoming connection from the device with the device name 'target_device_name'.
After receiving a connection request from the android phone, the Raspberry Pi will establish a connection automatically.
Now you can continue with the step Connect to the Raspberry Pi.
python3 pi_server/src/wifi_direct_connetor.py --remove-group
python3 pi_server/src/wifi_direct_connetor.py -h
The documentation of the python code is hosted as Github Page.
After the P2P server on the Raspberry Pi was started it's possible to connect to it using Wi-Fi direct. There are two options for establishing a connection:
-> settings -> Wi-Fi -> open the dropdown menu (three vertical dots icon) -> Wi-Fi Direct -> choose the device name
which was set in the raspberry-config.sh
file
After the android phone is connected to the Raspberry Pi it is possible to send data using TCP sockets. On the Raspberry Pi a server socket should to be started. After that it's possible to connect to this socket from an android app. The Android-RasPi-WifiP2P App which is provided by this project can has already implemented a TCPSocket class and an example Activity which shows how a TCP connection could be established. The App is a good entrypoint for developing a Android P2P app using Wi-Fi direct.
links:
https://raspberrypi.stackexchange.com/questions/117150/issue-connecting-raspberry-pi-to-android-via-wifi-p2p
https://raspberrypi.stackexchange.com/questions/117718/how-to-connect-an-android-phone-and-a-raspberry-pi-through-wifi-direct-programma
https://github.com/CatalinPrata/funcodetuts/blob/master/AndroidTCPClient