ElEscalador
Posts: 856
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

How...C/C++ code that SSHs into another Pi to run a program?

Sat Oct 22, 2016 10:32 pm

I've got several pis doing different things on command (think, opening garage door..curtains, etc). I'd like to start teaching one to make decisions to control the rest, so the "boss" would essentially need to do what I do with an App on my phone - ssh in to various other Pis and run an executable on that remote Pi. How does a smart person do this?
Robotics tips, hacks, book extras https://youtube.com/practicalrobotics

ejolson
Posts: 6011
Joined: Tue Mar 18, 2014 11:47 am

Re: How...C/C++ code that SSHs into another Pi to run a prog

Sat Oct 22, 2016 10:47 pm

ElEscalador wrote:I've got several pis doing different things on command (think, opening garage door..curtains, etc). I'd like to start teaching one to make decisions to control the rest, so the "boss" would essentially need to do what I do with an App on my phone - ssh in to various other Pis and run an executable on that remote Pi. How does a smart person do this?
Maybe something like this

$ ssh remote-pi "command-to-run"

If that is not enough and you are trying to automate interactive processes you could try using expect

$ sudo apt-get expect expect-dev
$ man expect

If you just want buttons labeled open door, open window and so forth on your phone, that sounds like something for a web app. Maybe someone else who has experience with such things can fill in enough details to get started.

ElEscalador
Posts: 856
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

Elescalador

Sun Oct 23, 2016 1:00 am

Thanks, I'll look into those since I'm not familiar with them and may be able to use them with a system () call from inside an autonomously running program - is that what you are suggesting? I do have an app I use on my phone, but I want things to start happening automagically from a Pi that runs without user input.
Robotics tips, hacks, book extras https://youtube.com/practicalrobotics

tpylkko
Posts: 410
Joined: Tue Oct 14, 2014 5:21 pm

Re: How...C/C++ code that SSHs into another Pi to run a prog

Sun Oct 23, 2016 1:49 am

Probably a better idea to use mqtt/js/websockers/node red or something than make a c app that commands other machines over ssh. Then you can diplay a webpage that can control things or set up automated "if this then that" kind of things

http://hackaday.com/2016/05/27/minimal- ... d-clients/
https://www.toptal.com/nodejs/programmi ... h-node-red

ElEscalador
Posts: 856
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

Elescalador

Sun Oct 23, 2016 4:46 pm

Thanks, those are interesting and, while I'd use them if that's the only way I can figure out, my entire Raspberry Pi career has been dedicated to learning c/c++. If it's possible I'll do it the hard way to learn new tricks with these.
Robotics tips, hacks, book extras https://youtube.com/practicalrobotics

mutley
Posts: 61
Joined: Sat Jan 02, 2016 8:06 pm

Re: Elescalador

Tue Oct 25, 2016 9:47 pm

ElEscalador wrote:Thanks, those are interesting and, while I'd use them if that's the only way I can figure out, my entire Raspberry Pi career has been dedicated to learning c/c++. If it's possible I'll do it the hard way to learn new tricks with these.
Then I would highly recommend you take a look at writing a basic webserver using mongoose library.
https://docs.cesanta.com/mongoose/master/
Web services are designed to do exactly what you want, ssh can do it, but it's a kind-a hack. It seems I have a similar setup/problem to you. But I wrote my own daemon in C that does all the GPIO, USB & Serial communication and will listen and publish information using the mongoose library to the network, this daemon is deployed on each PI. Then the "server" simply posts commands to the URL's of each of the clients and receives the results.

ejolson
Posts: 6011
Joined: Tue Mar 18, 2014 11:47 am

Re: Elescalador

Wed Oct 26, 2016 10:03 pm

ElEscalador wrote:may be able to use them with a system () call from inside an autonomously running program - is that what you are suggesting?
Yes, ssh will work fine called using "system" in a C program. First set up your public and private keys so no password is needed to login. Then it should just work. While not as fancy as some of the other solutions presented here, ssh has the advantage of being callable with only one line of code and having built-in public key encryption for security.

ElEscalador
Posts: 856
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

Re: How...C/C++ code that SSHs into another Pi to run a prog

Sat Mar 25, 2017 2:47 pm

Bumping because I am finally back to actually implementing and listening for any additional solutions.
Robotics tips, hacks, book extras https://youtube.com/practicalrobotics

zmillerUCDavis
Posts: 11
Joined: Mon Mar 20, 2017 5:19 pm
Location: Davis, CA
Contact: Website

Re: How...C/C++ code that SSHs into another Pi to run a prog

Fri Mar 31, 2017 4:56 pm

It sounds like a very interesting project.

You may try Mobile-C,
http://www.mobilec.org/ an IEEE FIPA (Foundation for Intelligent Physical Agents) standard compliant multi-agent platform for supporting C/C++ mobile agents in networked intelligent mechatronic and embedded systems. It enables you to migrate and execute C/C++ code and its output from one machine to other machines.

Mobile-C is now included in C-STEMbian for Raspberry Pi
http://c-stem.ucdavis.edu/c-stembian/

plugwash
Forum Moderator
Forum Moderator
Posts: 3695
Joined: Wed Dec 28, 2011 11:45 pm

Re: How...C/C++ code that SSHs into another Pi to run a prog

Wed Apr 05, 2017 11:48 am

There is a library called libssh2 (apt-get install libssh2-1-dev), never actually used it though so I dunno how difficult it is to work with.

Return to “C/C++”