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.

The RPi's are networked via their own WiFy (wireless). No internet connection. And at the moment the latency doesn't matter. Just want to type one command on one RPi.

Each RPi has an accelerometer attached. If I only have one RPi I will miss out on the data 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.


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.
  • Search for how to synchronize photos on multiple Pi. – joan Nov 20 '17 at 8:26
  • Why do you need 2 RPis for this? Just start both scripts at the same time on the same RPi. – st2000 Nov 20 '17 at 9:03
  • Each RPi has an accelerometer attached. If I only have one RPi I will miss out on the data from the other RPi. – user75374 Nov 20 '17 at 9:10
  • 2
    What do you mean by "the same time?" Exactly the same time? Within X ms of each other? Don't care about latency but only want to type one command on one Pi? Those are all very different questions. – Brick Nov 20 '17 at 14:32
  • The answer might change if the Pis can communicate (e.g. via a network connection) or not. One obvious method would be to have the two devices in a master/slave arrangement. – Edward Nov 20 '17 at 18:06
1

My answer refers only to your SSH related sub-question:

Is there a way to skip the password?

Yes: for many reasons (esp. for security and convenience) it's highly recommended to use SSH keys instead of clear text passwords. There are many guides covering this topic and I'd like to recommend these two:

I've tested them today (2018-05-02) and confirm both are valid for Raspbian Stretch, too.

The process is, generalised speaking, as follows:

  1. generate on your PC a keypair with ssh-keygen (optional, recommended in most cases but not wanted in your use-case: protect the key with a strong passphrase)
  2. copy your public key to the RPi with ssh-copy-id
  3. login using the key (i.e. ssh -i id.pub USER@HOST) and make sure it's working
  4. on the RPi edit /etc/ssh/sshd_config and set PasswordAuthentication no, then restart ssh

For more details on each step please read the above mentioned guides, the manpages or drop me a comment.

| improve this answer | |
0

sshpass is useful for non-interactive login in ssh.

From the interwebz:

sshpass is a utility designed for running ssh using the mode referred to as “keyboard-interactive” password authentication, but in non-interactive mode.

usage: sshpass -p 'Passw0rd' ssh host@ip

| improve this answer | |
0

If the times of the two Pi's are synchronized, put a small routine at the start of the script that starts them at a specific time. You could make this an option:

python -t 14:25 adxl345test &

You'd have to type in the same time on both Pi's, but at least they'd be fairly synchronized.

If this were written in Java I could easily show you some example code that would do this, but my python skills are sadly out-of-date.

| improve this answer | |
-1

from a command line , as two processes in background. for each one type: python adxl345test.py &

or if you need it via IDE just run it twice

| improve this answer | |
  • Note that the OP wants to run them on two Pis. – Ghanima Nov 20 '17 at 21:06

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.