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){
Particle.publish(arguments);
Process proc = Process::run(arguments);
proc.wait();
while (!proc.exited()) {
delay(1000);
}
Particle.publish(String("exit_code ")+String(proc.exitCode()));
delay(1000);
}
void stdoutEventHandler(const char *event, const char *data){
//Particle.publish("pi received a tv event");
String arguments {data};
String command {"/home/userone/scripts/remote_tv_command.sh "};
String command_and_arguments{command +arguments};
//Particle.publish(command_and_arguments);
doCall(command_and_arguments);
}
void setup() {
Particle.subscribe("homeTvEvent", stdoutEventHandler);
Particle.publish("Alive!");
}
void loop() {
}
First Pi, trigger script /home/userone/scripts/remote_tv_command.sh:
#!/bin/bash
command="sshpass -p 'UserTwoPassword' ssh -oStrictHostKeyChecking=no usertwo@192.168.0.101 'cd ~/scripts/flirc && ./tv_command.sh $1'"
eval $command
Second pi, tv_command.sh:
#!/bin/bash
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.