- Setting up Wifi direct (wifi p2p) and DHCP server
- 1 Answer 1
- Saved searches
- Use saved searches to filter your results more quickly
- License
- jancelin/rpi_wifi_direct
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- Connect to Raspberry PI 3 over Wi-Fi direct
Setting up Wifi direct (wifi p2p) and DHCP server
So I have a fresh pi zero w up and running raspbian stretch lite. How can I enable Wifi direct/p2p where the Pi is GO and where it has a static ip i can connect to, and install/configure a DHCP server on the pi that when a client device connects to the pi over WiFi direct it get assigned an ip address? Any idea how to do it? has anybody managed to get a similar scenario working? where to start or what resources I could use, its not my first attempt I have been scratching my head around this a lot for the past couple of weeks, and its driving me crazy, it’s definitely not an easy task, I messed a lot with the previous installed OS trying to get it working so I had to re-flash a new image. /etc/wpa_supplicant.conf:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=LB ap_scan=1 device_name=raspberry device_type=1-0050F204-1 driver_param=use_p2p_group_interface=1 p2p_go_intent=15 p2p_go_ht40=1 p2p_listen_reg_class=81 p2p_listen_channel=1 p2p_oper_reg_class=81 p2p_oper_channel=1
As stated in my answer to your similar but less specific question dhcpcd.conf setting static ip not working! I’m just looking at WiFi Direct connections. So could you please paste your /etc/wpa_supplicant/wpa_supplicant.conf into your question?
I added the contents of my wpa_supplicant.conf, as I have messed up my previous attempt by running lots of commands, so I wanted to start on a clean installation, also the pi had already other stuff that aren’t needed anymore so i thought it’s better to start from scratch anyways.
1 Answer 1
UPDATE:
I have made a more detailed answer at Connect Android smartphone with Wi-Fi Direct to a Raspberry Pi. Please look there. This answer here isn’t updated anymore.
I have tested this with a smart phone using android 6.0 and with Raspberry Pi OS (32-bit) Lite 2020-08-20 based on Debian Buster, updated with sudo bash -c ‘apt update && apt full-upgrade && reboot’ . WiFi Direct uses Wi-Fi Protected Setup (WPS) for authentication that knows mainly two modes: Push Button Control (PBC) and Pin Code. For this example I will only use PBC because it is a bit simpler without fiddling with a pin code.
We want to have a DHCP server running. WiFi Direct is organized in groups and every group has one group owner (GO). Only the group owner is allowed to run a DHCP server because we have to ensure that only one DHCP server is present in the group. The group owner can change and it seems that there are protocol datagrams to negotiate DHCP. I have seen a hint about this at Wi-Fi Direct vs Ad-hoc mode, section 6) Frame exchange sequence:
After that we can exchange data frames in the group, but usually the DHCP protocol will be used first to provide the client with an IP address.
But I haven’t found further information how it works so for this setup I will set the RasPi to the group owner. To ensure that a device is always negotiated to a group owner we use the option p2p_go_intent=[0..15] . 0 means the RasPi becomes a client, 15 means the RasPi becomes a group owner. 7 means a chance of 50 % to become a group owner.
I prefer to use systemd-networkd because it has all in one and is able to manage dynamically changing interfaces. WiFi Direct groups are represented by virtual wifi interfaces with increasing numbers, e.g. p2p-wlan0-0 , p2p-wlan0-1 and so on.
Just follow to Use systemd-networkd for general networking. You can use section «♦ Quick Step». Then come back here.
To configure wpa_supplicant create this file with your settings for country= and device_name= . By specification, the device name should always start with DIRECT-. You can just copy and paste this in one block to your command line beginning with cat and including EOF (delimiter EOF will not get part of the file):
rpi ~# cat > /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
To give the group interface a static ip address and enable a DHCP server on it, create this file:
rpi ~# cat > /etc/systemd/network/12-p2p-wlan0.network
To manage devices with wpa_cli we have to specify the control interface wpa_cli -ip2p-dev-wlan0 . In wpa_supplicant.conf we have specified where to find the names of the control interfaces:
rpi ~$ ls -1 /var/run/wpa_supplicant/ p2p-dev-wlan0 wlan0
Then on the RasPi I start finding devices:
rpi ~$ wpa_cli -ip2p-dev-wlan0 p2p_find
Now I go to the WiFi Direct page on my smartphone
System settings -> Networks -> WiFi -> tick bar in upper right corner -> Advanced WiFi -> Wi-Fi Direct
Now I could look with wpa_cli -ip2p-dev-wlan0 p2p_peers what mac addresses of found devices are available. Then I have to show the details for every mac address with wpa_cli -ip2p-dev-wlan0 p2p_peer what name it has to find my smartphone. I do it with this one liner, for example:
rpi ~$ for i in $( wpa_cli -ip2p-dev-wlan0 p2p_peers ); do echo -n "$i "; wpa_cli -ip2p-dev-wlan0 p2p_peer $i | grep device_name=; done a2:91:69:b2:91:a9 device_name=LG Leon 4G LTE 4e:ef:c0:a7:05:82 device_name=Fire TV stick 9a:0c:82:ba:7a:aa device_name=Android_58eb 32:cd:a7:f2:ee:5c device_name=DIRECT-1KC48x Series
and find a2:91:69:b2:91:a9 for my LG Leon 4G LTE . Now I only work with this mac address (p2p_dev_addr) and connect to it:
rpi ~$ wpa_cli -ip2p-dev-wlan0 p2p_connect a2:91:69:b2:91:a9 pbc go_intent=15
Note that we use pbc (push button control) and go_intent=15 to make the RasPi the group owner (see above).
On the smartphone tick SEARCH
In the popped up window I just confirm the connection by ticking ACCEPT (push button).
Under Advanced I find the ip address of the device, e.g. 192.168.4.102:
and just ping it from the RasPi to confirm that the smartphone is connected.
rpi ~$ ping -c3 192.168.4.102 PING 192.168.4.102 (192.168.4.102) 56(84) bytes of data. 64 bytes from 192.168.4.102: icmp_seq=1 ttl=64 time=6.90 ms 64 bytes from 192.168.4.102: icmp_seq=2 ttl=64 time=3.46 ms 64 bytes from 192.168.4.102: icmp_seq=3 ttl=64 time=3.14 ms --- 192.168.4.102 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 3.149/4.505/6.904/1.701 ms rpi ~$
To finish the connection we need the group identifier. You can find it with:
rpi ~$ ip -br link | grep -Po 'p2p-wlan0-\d+' p2p-wlan0-12
And with this we finish the connection with p2p_group_remove :
rpi ~$ wpa_cli -ip2p-dev-wlan0 p2p_group_remove p2p-wlan0-12
rpi ~$ wpa_cli -ip2p-dev-wlan0 P2p_group_remove $(ip -br link | grep -Po 'p2p-wlan0-\d+')
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
create a autonomous wifi hotspot on a Raspberry pi
License
jancelin/rpi_wifi_direct
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Hotspot Wifi direct Raspberry Pi 3
Working with Debian Hypriot OS (include Docker): https://downloads.hypriot.com
sudo -s wget -P /home/pirate https://raw.githubusercontent.com/jancelin/rpi_wifi_direct/master/raspberry_pi3/install_wifi_direct_rpi3.sh; chmod +x /home/pirate/install_wifi_direct_rpi3.sh; bash -x /home/pirate/install_wifi_direct_rpi3.sh
- reboot
- enjoy
- After reboot, connect your pc, phone. to the hotspot wifi "GeoPoppy_Pi3"
- password: geopoppy
- ip of raspberry pi wifi : 172.24.1.1
- hotplug ethernet
- hotspot wifi
Full project "GéoPoppy" a nano-server GIS at
Connect to Raspberry PI 3 over Wi-Fi direct
I want to connect from an android phone to a RPI 3 over Wi-Fi direct. I want to do it over Wi-Fi direct because the RPI will be a controller for one or more movable devices that will be used in buildings as well as out in the nature. In buildings, it could just connect to the existing Wi-Fi, but in the nature there is no Wi-Fi. Therefore, the RPI would need to be its own AP, but then the phone controlling it could not be connected to the building's Wi-Fi at the same time. Also, it would get complicated with multiple RPIs, one would need to be the AP and the others would need to connect to it. It would be cool if I just could power up the RPIs, withouth doing any configuration every time their setup changes, and connect to it regardless from where it's used. So with Wi-FI direct being a requirement: How can I do this? Can someone provide me with an example (or a Link to an example)? Basically any hint that brings me closer to the target will help. what i have so far I've installed Arch Linux ARM on the PI using this guide:https://archlinuxarm.org/platforms/armv8/broadcom/raspberry-pi-3 Then I've installed wpa_supplicant using "pacman -S wpa_supplicant" Then I've created a small configuration for it under "/etc/wpa_supplicant/p2p.conf" that contains:
ctrl_interface=/var/run/wpa_supplicant device_name=PI update_config=1
then I've started wpa_supplicant using wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/p2p.conf Then I've tested Wi-Fi direct using wpa_cli and then p2p_find which found my phone. So I assum driver-wise, everything's good. I just need to figure out how to use wpa_supplicant to register a server-program running on my PI, and how find & connect to it from android. Any ideas?
@VanCoding Did you post your update anywhere? I have got to the same point as you - Android and Pi 3 can see eachother, but need to link it to an application.
@LC1983 no. Unfortunately, i programmed directly on the PI via sftp, which is in use as a whirlpool controller now. I forgot to copy over the files, before giving it away. I'm still waiting to get my hands on the code again 🙁