1

I have two active RPi's. They both have the script:adxl345test.py

This script collects data from an accelerometer. I usually start the script on one RPi and then start the script on the other RPi. However now I want to start the scripts at the same time. So...

  • Is it possible to run the scripts from both RPi's on one RPi?

So that one RPi starts running both its own script and an external script from the other RPi.

I trigger the scripts on each RPi by writing sudo python adxl345test.py in the console and then pressing Enter. The clocks are synced with PTPd. What I'm looking for is to trigger the scripts by writing a single command in the console of one RPi. Precision isn't that important at the moment.

The RPi's are networked.


I found a way to run both script through one command. Here it is:

pi@Sensor1:~ $ sudo python adxl345test.py & ssh pi@ip sudo python adxl345test.py

However since I use ssh the second RPi requires a password before it runs the script. So...

  • Is there a way to skip the password?
  • Can you write the password directly in the abovementioned command?

Using sshpass (sudo apt-get install sshpass) I managed to type the password directly into the command. The command is:

pi@Sensor1:~ $ sudo python adxl345test.py & sshpass -p 'password' ssh pi@ip sudo python adxl345test.py

I can now start collecting data with only one command however they still don't start at the same time (around 1s off).

  • Is it possible to make them start even closer to eachother timewise (0,1s or less)?
  • Also how do I stop recording data? Normally I would use Ctrl+c but that only works when running a single script on one RPi.
  • 1
    How do you trigger the scripts? Locally or from a network? How precise does "the same time" need to be? Are the clocks in sync? – Sparhawk Nov 20 '17 at 09:29
  • I trigger the scripts on each RPi by writing "sudo python adxl345test.py" in the console and then pressing Enter. The clocks are synced with PTPd. What I'm looking for is to trigger the scripts by writing a single command in the console of one RPi. Precision isn't that important at the moment. – user75374 Nov 20 '17 at 09:46
  • Looks like there's already an answer, but the next question would have been "are they networked?" – Sparhawk Nov 20 '17 at 11:19
  • Yes they are networked – user75374 Nov 20 '17 at 11:36
  • 1
    @user75374 Welcome to U&L , you can edit here to include more information to your question. some information look important on your comments. – GAD3R Nov 20 '17 at 14:48

1 Answers1

3

If the two RPi can talk to each other, make a small shell script on one that starts the remote script with a SSH command and then starts the local script.

If you do a specific SSH setup for this, create a SSH key pair for this purpose, because leaving a sensitive private key on a RPi would be dangerous.

xenoid
  • 8,888