4

I am trying to get two Raspberry Pi 3s to simultaneously run the same python script after running it from a single terminal window. I believe that the two devices are paired via bluetooth but I don't know if there is a line I can write or another way to get the script to run on both at once.

Any help will be appreciated.

Toner
  • 63
  • 7
  • 2
    If you're running it from another computer, you could create a script that connects with ssh and runs a single command on both Pis – clubby789 Dec 03 '19 at 14:34

1 Answers1

0

It all depends on your definition of "simultaneously". In reality, the best we can do is get to "nearly simultaneous" due to physics constraints and how schedulers work on network interfaces. There's two ways you can do this:

The first, you could run ntpdate -b [HOST] on one of the RPis with [HOST] being the hostname or IP address of the other RPi on the network; this will time-sync the devices within tolerance of the NTP protocol (very accurate when on the same local network, increasingly inaccurate across the network). Then you could set up a chrontab job on both devices scheduled for some known time in the future calling that python script. You can make more sophisticated variants of this method (e.g., setting up master-slave, etc.) that will include elements of the next solution.

The second solution you could use is screens and secure shell execution. Here, screens runs parallel terminal sessions that can automatically invoke a script and/or command. The command you're interested in would be the python script you're referring to: ssh [USER1]@[HOST1] [PYSCRIPT] for the first screen and ssh [USER1]@[HOST1] [PYSCRIPT] on the second. This will only execute simulteneously within tollerance of both your processor's scheduler and the network interface adapter schedulers (likely to be several milliseconds off).

As mentioned before, you can mix the first solution with the second, automating time-sync and updating chrontab to have the scripts execute nearly after timesync is complete. This takes some work and tuning, but is a frequent solution in many distributed processing problems.

jhill515
  • 894
  • 8
  • 26