Search code examples
pythoncommandrouterparamikoat-command

Unable to send AT commands trough Paramiko SSH


I'm working on a GPS position retrieval project, I have to connect in SSH on routers, then launch commands to retrieve latitude and longitude. I recently received new routers, when we connect to this router, we receive an "OK" signal when we are connected to ensure proper operation, then we run the command we want, and we get the data as in this example below, always followed by the "OK" message indicating that the command worked well :

AT*GNSSSTATUS?
Location Fix=1
Number of satellites = 14
Latitude=+49.17081
Longitude=-123.06970
Date=2016/02/29
Time= 18:55:28
TTFF=9449 milliSeconds

OK

When I connect in SSH with the help of PUTTY, it works, but when I use my code that sends the same command as mentioned above (AT*GNSSSTATUS?) through my Python script and the Paramiko library, the result is just "OK" which indicates that the connection is just active. It's like the command line opened by the script doesn't take the "ENTER" that should come next. To test this, I tried to put a command returning "ERROR" in case I use PUTTY, but even in this case the Python script returns "OK". To try to fix this I tried different options by adding :

stdin, stdout, stderr = client.exec_command('AT*GNSSSTATUS? \r\n')

or

stdin, stdout, stderr = client.exec_command('AT*GNSSSTATUS? <CR>')

But in no case does this change the result. My data list contains only one string marked "OK". For the connection part on the router everything works.

Anyone have any ideas?

Thanks a lot! Sorry if there are spelling mistakes ahah.


Solution

  • Thanks Martin Prikryl !

    So I looked at the link you sent me and it worked: Executing command using Paramiko exec_channel on device is not working.

    So I changed my code to use a shell and send my commands through it. Here is my code

    shell = client.invoke_shell()  
    shell.send('AT*GNSSSTATUS? \r')
    

    Thank you very much and have a nice day