Remote execution of a script trigged by Particle cloud event

I am using two Raspberry Pis : one gets triggered from the particle cloud, connects to the second over ssh and executes a bash script on it. I got it running using the following code:

First Pi, firmware:

#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

#include "Particle.h"

void doCall(String arguments){
  Process proc = Process::run(arguments);
    while (!proc.exited()) {

    Particle.publish(String("exit_code ")+String(proc.exitCode()));

void stdoutEventHandler(const char *event, const char *data){
    //Particle.publish("pi received a tv event");
    String arguments {data}; 
    String command {"/home/userone/scripts/ "};
    String command_and_arguments{command +arguments};

void setup() {
    Particle.subscribe("homeTvEvent", stdoutEventHandler);

void loop() {

First Pi, trigger script /home/userone/scripts/


command="sshpass -p 'UserTwoPassword' ssh -oStrictHostKeyChecking=no usertwo@ 'cd ~/scripts/flirc && ./ $1'"
eval $command

Second pi,


echo $1 # to be used later
sudo ./flirc_util send_ir_raw 0,9170,4365,617,472,618,472,617,1600,617,473,617,472,617,473,617,472,617,473,617,1600,613,1604,613,477,613,1604,613,1601,617,1600,618,1600,617,1606,637,447,617,472,617,473,643,1574,617,472,617,473,617,489,601,472,617,1600,629,1588,618,1600,617,472,617,1601,617,1600,617,1600,587,1630,613

I would like to have a solution where I don’t type the password for usertwo in cleartext. I have therefore generated a ssh fingerprint as described here. SSH-ing manually from the first to the second pi requires no password, but when I call it from the firmware, it doesn’t get through. Can anyone please help with the matter?

Many thanks in advance.

I think when the Pi calls the script through the firmware it does it as root. You should check if the ssh fingerprint works with root/sudo.

can a maintainer please try to reproduce? I see no reason why a normal ssh fingerprint should not work. If what @nrobinson2000 says is true, and the firmware runs a Process::run as root, it should at least have an overload specifying the user one would like to run as.

This thread might help you:

1 Like

Ashamed I didn’t think about it earlier. Thank you loads, @nrobinson2000! It works now.

1 Like