I am using a robot that is connected to a remote pc using localhost. I have used the Paramiko library to send commands from remote pc to my robot. I want to publish a number on /activate topic like this:
rostopic pub /activate std_msgs/Int16 "data: 1"
The problem is not my connection because the above command works using PuTTY or SSH.
I have written the following code:
import paramiko
host = "xxx.xxx.x.x"
port = 22
username = "robot"
password = "xxx"
command = "rostopic pub /activate std_msgs/Int16 'data: 1'"
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port, username, password)
stdin, stdout, stderr = ssh.exec_command(command)
But using this code, I see no results in my robot. Can anyone help?
If you have problems with executing commands, you need to read their (error) output to see any error messages.
Also your current code does not even complete the command. And reading the command output is the actually easiest way in Paramiko to actually get your command completed.
For another common problem, see Some Unix commands fail with "<command> not found", when executed using Python Paramiko exec_command