SSH Command to call a remote (Raspberry Pi) Python script using Matlab
Show older comments
Hello, I've been trying to run and get the output of a remote Python file that is on a Raspberry Pi.
The original file captures signals, but I just created a simple python file to see if it can work.
The python file is:
L = 1 + 5
print(L)
The Matlab file looks like this:
clc
close all
clear
% Define the SSH command to run the Python script on the Raspberry Pi
sshCommand = 'ssh id@ipaddress "python3.11 /home/mcc128/Desktop/RaspTest"';
% Execute the SSH command and capture the output
[status, cmdout] = system(sshCommand);
(I used the correct id and ip address. Omitted them for the sake of anonymity.)
When I run the file, matlab just gets stuck running the execution line forever. I don't get any error messages, just that it loads forever. Since it is a relatively simple task, it shouldn't take this long to run it. I think there's a mistake somewhere (in the code or that this function is just not supported etc.), but I can't figure it out. If there's a better way of doing it, then please do let me know. Any help would be appreciated. Thank you.
Accepted Answer
More Answers (1)
Animesh
on 18 Jun 2024
Hi Navina,
As per your provided description and files, I feel the potential causes for such issue can be:
- Path Issues: The script or the Python executable might not have the appropriate permissions, or there could be a typo in the path to the Python file. To resolve thisVerify the path to your Python script (/home/mcc128/Desktop/RaspTest) is correct and that the file has executable permissions. You can set executable permissions using “chmod +x /path/to/your/script.py” on the Raspberry Pi. Also, ensure that the user you're SSHing as (id in your placeholder) has the necessary permissions to access and execute the script.
- Network Issues:If there's a network issue or the IP address or hostname of the Raspberry Pi is incorrect, the SSH command might attempt to connect indefinitely. To resolve this: Double-check the Raspberry Pi's IP address and ensure that your network allows SSH connections to it. Also, ensure that the Raspberry Pi's SSH server is running and accessible.
- if everything else seems correct, consider testing the SSH command outside MATLAB (e.g., in a terminal or command prompt) to ensure it works as expected. To test SSH Command Outside MATLAB: Open a terminal or command prompt on your machine and run the SSH command directly,
ssh id@ipaddress "python3.11 /home/mcc128/Desktop/RaspTest"
Replace id and ipaddress with your actual username and IP. This can help isolate whether the issue is with the SSH setup or how MATLAB executes the command.
By reviewing each of these potential issues, you should be able to identify and resolve the problem causing MATLAB to hang when trying to execute your Python script on the Raspberry Pi remotely.
I hope this helps!
Animesh
1 Comment
Navina Rajoo
on 20 Jun 2024
Categories
Find more on MATLAB Support Package for Raspberry Pi Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!