Open shaunaa126 opened 1 year ago
Hey! Nice to hear that you are taking interest in my code
So something about the way I did this that I'm realizing I did not make super clear except in the second readme, is that I am actually using the ble to get the wifi direct connection. Something about the wifi direct protocol is that it is designed specifically to have some kind of user input involved in the connection. I was looking for an automated solution where I wouldn't have to require any user input on the raspberry pi side. What I do is I use the ble connection to tell the pi to start connecting to the android phone
So what I am doing is I have an Arduino Nano 33 BLE sense connected to my raspberry pi zero via usb. Then I have arduino code included in this repo that connects with the android phone and listens for the android to tell it to connect. Then it tells the pi over serial.
So unfortunately my code won't work for you as is unless you include the arduino portion, but I can maybe give you some help/ direction to help you do what you want to do. Do you care if the user has to interact with the pi in order to make the connection work? If not you can tweak my code and have it working pretty easily. Another thing you can do that would require a little bit more work is implement the ble service on the raspberry pi and hook it up to my code. But if your project allows, grabbing a cheap ble enabled arduino would be the easiest solution.
You can also experiment with other ways to create a second communication channel, like perhaps nfc or sound or something like that, and you could also attempt to do some wifi direct research and try and take this farther than I was able to. I wasn't able to get the connection to work without a second channel, but it could be possible.
Hope this is helpful, and feel free to hit me up with follow up questions I am always happy to help!
Hey, thank you for the code. It would be great if you could have an interactive version, for my use case (https://github.com/elioscordo/hoverdroid) I would like to get images from android cameras and send back serial commands. and I don't mind the interaction.
@MrStashley
Thank you so much for uploading your bash script. That alone is going to save me HOURS of yelling at ChatGPT and looking up documentation.
I'm trying to implement WiFi Direct in a project of mine involving a Pi Zero 2 W (without need for the BLE features). I don't want to make any promises, but I'll be working on modifying the Python script to just take an argument for the device name, no BLE business
EDIT: Finished updating it. Haven't had a chance to test it yet though. Will create PR when tested and validated
Hello @MrStashley, first of all thank you so much for sharing with the community your code and how to establish using Bluetooth and WifiDirect connectivity to Android.
I am trouble following the directions to get my setup working, I was hoping you have some time to help. For now I am skipping the Bluetooth initiation, I am just trying to get my Raspberry PI Zero 2 W working with WifiDirect so that the android app you have can connect to it. Here is what I have done so far:
[zero-w-config.sh](https://github.com/MrStashley/Android-RasPi-WifiP2P-Communication/blob/main/zero-w-config.sh)
script on Raspberry Pi 2 Zero successfullypython WifiDirectConnector.py 3 mydevicename
), but I am stuck here as I am not sure what commands that I need to run. I tried to run theATTEMPT TO CONNECT
on the Android app but it is not picking up anything on the scans, even when I updated the DEVICE_NAME in the android code to match what I provided. Here is the code for the python script:BLE_INIT_FAILED = "0"; BLE_INIT_SUCCESS = "1"; CENTRAL_CONNECTED = "2"; DEVICE_NAME = "3"; START_CONNECT = "4"; CENTRAL_DISCONNECTED = "5"; DISCONNECT_WFD = "7"; START_SOCKET = "8";
P2P_FIND_COMMAND = "wpa_cli -i p2p-dev-wlan0 p2p_find"; GET_P2P_PEERS_COMMAND = "for i in $( wpa_cli -i p2p-dev-wlan0 p2p_peers ); do echo -n \"$i \n\"; wpa_cli -i p2p-dev-wlan0 p2p_peer $i | grep -E \"device_name=\"; done"; P2P_GROUP_REMOVE_COMMAND = "wpa_cli -ip2p-dev-wlan0 p2p_group_remove $(ip -br link | grep -Po 'p2p-wlan0-\d+')" ;
def P2P_CONNECT_COMMAND(macd):
python macro B-). idk if this is a thing that is done in standard python style but idc i'm doin it
class WifiDirectConnector:
if name == "main": wifi_direct_conn = WifiDirectConnector();