Reputation: 73
Working on a project that should share data among 4+ devices offline. Using Google Nearby connection, we are able to establish a connection between devices via P2P-STAR topology. But what we really need is to have all devices receive and send data to all connected devices(M-N Connection).
After doing a research, Google Nearby API doesn't support mesh network so we have to build one on top of that API. But we are not able to find a good example to start with.
Any suggestion that can point us to that would be appreciated.
Upvotes: 4
Views: 5348
Reputation: 111
WiFi direct can be used for Mesh networking because each node can act both as an WiFi access point for others and as a WiFi station (client) itself. The tricky part is that each device as a group owner will be assigned the IP 192.168.49.1, so you get an IP address conflict. The workaround is to use the IPv6 link local addresses to transfer data:
val ssid = group?.networkName
val passphrase = group?.passphrase
val interfaceName = group?.`interface`
val linkInterface = NetworkInterface.getNetworkInterfaces().toList()
.firstOrNull {
it.name == interfaceName
}
val linkLocalAddr = linkInterface?.inetAddresses?.toList()
?.firstOrNull { it.isLinkLocalAddress && it is Inet6Address } as? Inet6Address
Each node can then relay data to/from other nodes over multiple hops.
The device connecting would need to know the LinkLocal IP address of the other node before connecting to the access point; this can be done via QR code and/or Bluetooth Low Energy advertising.
Some Android 12+ devices support Access Point-Station Concurrency. On those devices it is possible to run a Local-only Hotspot and simultaneously connect to another access point as a station (client). The IP range of the Local-only Hotspot is randomized, so it is unlikely that two neighbor nodes will have an IP address conflict.
There is now an open-source library with an initial implementation of a Mesh Network over WiFi (disclaimer: I am the author of that library):
https://www.github.com/UstadMobile/Meshrabiya
Upvotes: 1
Reputation: 76569
There is Bluetooth mesh, but this is rather for BLE beacons.
There's also Wi-Fi Direct, which is not mesh networking.
Upvotes: 1