Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an autonomous GO for Wifi Direct in Android with dedicated ssid and passphrase?

Tags:

android

wifi

I am trying to create a WI-FI Direct network with say 3 tablet PCs. I want to run WiFi-Direct as background service, with one device set as autonomous GO. Could someone please tell me how can this be done in Android? Also someone please tell me how we can set dedicated SSID and passphrase so that any time new devices are added to this network, they can search for a specific ssid and passphrase for connection establishment during the application initiation ?

I am using Android API Level 18 for my development ...

Thanks in advance ...

like image 981
user2644440 Avatar asked Dec 26 '22 20:12

user2644440


2 Answers

This is how an autonomous Group Owner is created i.e. using the following code you can deliberately set a device in Wifi direct Network as a Group Owner

manager.createGroup(channel,new WifiP2pManager.ActionListener()
{
    @Override
    public void onSuccess()
    {
        Toast.makeText(WiFiDirectActivity.this, "Group Created",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onFailure(int reason)
    {}              
}); 

You can use this code on any event like Button click etc.

like image 71
pioneerBhawna Avatar answered Dec 31 '22 12:12

pioneerBhawna


Bluemoon10 was almost right. I can't comment yet because I need 50 reputation :/. The config.groupOwnerIntent ranges from 1-15 with 15 being the highest intent to be group owner. If 2 devices try to connect with both GO intents == 15, the connect call will fail. If there is a GO intent tie lower than 15, the devices agree on a tie breaker bit and will succeed. So if you want one device to be group owner, you have to make sure that it is the only one trying to be. You can do this with Service Discovery, i.e. if there is a service running set your GO intent to 15 on the device with the service and 1 on the connecting device. Only one device needs to call connect to initiate connection.

Link to Service Discovery tutorial: http://developer.android.com/training/connect-devices-wirelessly/nsd-wifi-direct.html

like image 38
Bill G Avatar answered Dec 31 '22 12:12

Bill G