1

Please note that I have seen this post and I am using RPI Model 3B+

The question is: How to wirelessly connect 2 PIs which are NOT on the same network and can I do this without any external parts? Would I need to write separate protocol and if yes can you please direct me as to where to start searching?

  • 1
    Wireless without extra parts would mean Wi-Fi or Bluetooth. Where to start searching? Google. – Mark Smith Mar 25 at 17:40
  • Thanks! Can you give a clue for WiFi? What could I search for when I want to connect 2 devices to each other and not to a router? – AGoranov Mar 25 at 17:41
  • 2
    Search for "set up raspberry pi as an access point". One Pi would be the access point, the other a client. – Mark Smith Mar 25 at 17:43
  • Great thank you a lot for your feedback! But is this the only way to do this? I mean if let's say I do it this way then how can I guarantee that it's secure? I understand that the question is out of scope but would there be a way to identify that the device connecting to the first PI is actually the second? – AGoranov Mar 26 at 14:30
  • Only way? Probably not. It's the best way I can think of. If someone has a better suggestion, go with that. For security it depends on how you decide to move the data around. Ssh or https would be possibilities, both of which work with certificates which can guarantee you are talking to who you think you are. – Mark Smith Mar 26 at 15:06
1

It is the nature of a IPv4 network with subneting that you need an interface to connect to a specific subnet. If you have two different subnets, you need two interfaces to connect to each subnet. Interconnecting different subnets is usually done by router with as much interfaces as subnets they connect. You can also use two interfaces on a RasPi.

The Raspberry Pi 3B+ can make two interfaces: one with the on-board WiFi device and one with the wired ethernet port. I understand your question that each RasPi is connected to its own hotspot as client and you do not want to make one RasPi an access point. If you want one RasPi to connect to the hotspot the other RasPi is connected to, it must have an additional WiFi device. This can only be done with an additional USB/WiFi dongle. This way the RasPi can stay in its own subnet and it can connect to the second RasPi and vice versa.

If you are using only managed mode connections to hotspots you need either an additional USB/WiFi dongle or a router. So you cannot connect two RasPis living on different subnets, without any external parts.

Fortunately the RasPi is able to use WiFi Direct mode simultanously so we can use it to connect the two RasPis direct. First configure one RasPi as autonomous group owner and make it persistent. How to do it you can look at p2p_group_add setting own password and ssid. Then connect to it from the other RasPi for example with

wpa_cli p2p_connect xx:xx:xx:xx:xx:xx pbc join

With WiFi Direct clients get member of a group. Each group is defined by a group owner. Normally the group owner is negotiated by the clients. If you define a static autonomous group owner then it acts more like an access point. Group owner cannot connect together because they are on different groups. If you want to connect more than one RasPi it should not be a problem. Just define only one autonomous group owner and connect the other RasPis to it. If you want more flexible groups let negotiate them. But this is a bit more complicated and out of scope here.

You can also make each RasPi a hotspot and simultaneously connect as client to another remote access point. How to do it you can look at Access point as WiFi repeater, optional with bridge. If you like to spend additional hardware with an USB/WiFi dongle you can simplify the setup but it isn't essential. How to setup this you can look at Access point as WiFi repeater with additional WiFi-dongle.

  • What about if I have 3 or more RPIs? Let's say each of them acts as autonomous group owners or let's say none of them are. In such a case what would happen? – AGoranov Mar 27 at 13:03
  • @AGoranov I have updated the answer with the last paragraph. – Ingo Mar 27 at 19:44
  • If I have an extra Wi-Fi module could I have a hotspot and connect to a Wi-Fi network at the same time? In this way each device would have own hotspot but could also connect to another? – AGoranov Apr 2 at 7:11
  • @AGoranov I have updated the answer again with the last paragraph. – Ingo Apr 2 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.