Forum

How to use wifi/p2p?

Could you give me a guide how to make p2p communication on webos service?

@Seenabro97

Please follow below steps to connect p2p connection.

Prepare target device (RPI4)

  • Connect target device with Ethernet, it has internet access
  • Android phone - Must support WiFi Direct connection.
  • Prepare 3 SSH terminals

[Terminal 1]
Check WiFi service current status

luna-send -n 1 -f luna://com.webos.service.wifi/getstatus {}

Response of getstatus call
Observe the status field value

{
    "subscribed": false,
    "returnValue": true,
    "status": "serviceDisabled",
    "wakeOnWlan": "disabled",
    "tetheringEnabled": false
}

If status field valued is serviceDisabled then WiFi service is disabled.

If status field valued is serviceEnabled then WiFi service is enabled.

If WiFi service is disabled then Enable it by

luna-send -n 1 -f luna://com.webos.service.wifi/setstate '{"state": "enabled"}'

Response of setstate call

{
    "returnValue": true
}

[Terminal 1]
Check P2P current status by

luna-send -n 1 -f luna://com.webos.service.wifi/p2p/getstate '{}'

Response of p2p/getstate
Observe the P2P field value

{
    "subscribed": false,
    "returnValue": true,
    "persistentMode": "disabled",
    "P2P": "disabled",
    "listenState": "disabled"
}

If P2P field valued is disabled then P2P is disabled.

If status field valued is enabled then P2P is enabled.

If P2P is disabled, enable the P2P by

luna-send -n 1 -f luna://com.webos.service.wifi/p2p/setstate '{"P2P": "enabled", "listenState": "enabled", "persistentMode": "enabled"}'

Response of p2p/setstate

{
    "returnValue": true
}

[Terminal 1]
Subscribe for incoming P2P requests by

luna-send -i -f palm://com.webos.service.wifi/p2p/getp2prequests '{"subscribe":true}'

Response of p2p/getp2prequests

{
    "subscribed": true,
    "returnValue": true
}

Let it be running

[Terminal 2]
Subscribe for P2P Groups by

luna-send -i -f luna://com.webos.service.wifi/p2p/getgroups '{"subscribe" :true}'

Response of p2p/getgroups

{
    "subscribed": true,
    "returnValue": true,
    "groups": [
    ]
}

Let it be running

[In Phone]
Request for connection

  1. Enter Wi-Fi Direct menu on Phone
  2. Enter "Setting -> Network -> WiFi Direct menu"
  3. Push the target device name

Note: RPI4 default name is webOS Open Source Edition
[In Phone]
Connecting text will appear under target device name
and
[Terminal 1]
New response will be updated with requesting peer device info

{
    "returnValue": true,
    "deviceName": "G8S ThinQ",
    "subscribed": true,
    "deviceType": "phone",
    "deviceAddress": "66:c2:de:24:21:25",
    "wpsType": "pbc",
    "wfdInfo": {
    },
    "signalName": "P2PGONegRequested"
}

Note: If Peer devices gets connected automatically, no need to execute connect command step.

[Terminal 3]
Connect to the Peer device by

luna-send -n 1 -f luna://com.webos.service.wifi/p2p/connect '{"peerAddress": "66:c2:de:24:21:25","wpsInfo":{"wps":true}}'

[Terminal 3]
Response of p2p/connect

{
    "returnValue": true
}

[In Phone]
Connected text will appear under target device name

[Terminal 2]
New response will be updated for created P2P group


{
    "subscribed": true,
    "returnValue": true,
    "groups": [
        {
            "groupInfo": {
                "persistent": true,
                "owner": true,
                "tethering": false,
                "frequency": 5180,
                "ssid": "DIRECT-Ub-raspberrypi4"
            }
        }
    ]
}

[Terminal 3]
Check the P2P group peers by passing ssid value from [Terminal 2] response

luna-send -n 1 -f luna://com.webos.service.wifi/p2p/getgrouppeers '{"ssid": "DIRECT-Ub-raspberrypi4"}'

[Terminal 3]
Response of p2p/getgrouppeers

{
    "returnValue": true,
    "peers": [
        {
            "peerInfo": {
                "deviceName": "G8S ThinQ",
                "peerIp": "192.168.49.2",
                "connected": true,
                "configMethod": 4488,
                "deviceAddress": "66:c2:de:24:21:25",
                "signalLevel": 100,
                "groupOwner": false,
                "deviceType": "phone"
            }
        }
    ]
}

[Terminal 3]
Disconnect the P2P group by passing ssid value from [Terminal 2] response

luna-send -n 1 -f luna://com.webos.service.wifi/p2p/disconnectgroup '{"ssid": "DIRECT-Ub-raspberrypi4"}'

[Terminal 3]
Response of p2p/disconnectgroup

{
    "returnValue": true
}

[Terminal 2]
New response will be updated for P2P group

{
    "subscribed": true,
    "returnValue": true,
    "groups": [
    ]
}

[In Phone]
Connected text will disappear
and only target device name will appear.
Note: It varies phone to phone, some phones take long time to update the status.
So mainly [Terminal 2] response should be considered.

you can get more information about each api in com.webos.service.wifi | webOS Open Source Edition

Can we use this p2p service in WebOS-WebOS connection?

Yes we can use, but rpi4 does not supporting getting list of scanned p2p devices. When you use rpi4 - rpi4 you can't get the scanned p2p peer list.
Here we are initiating connection from mobile so, at the time rpi4 has mobile requesting information and we are connecting.

Could this p2p service be used for WebOS-WebOS connections?