I am developing a web application to send G-Code to the 3dprinter. This 3dprinter has a Linux stack. I could make it in Ubuntu application on Win by using the following command
ssh root@ip
password
python3 /usr/share/griffin/command_util.py
sendgcode G28
after typing python3 /usr/share/griffin/command_util.py
,
it will retun(Cmd) type command here
I tried to use ssh2 in PHP, connection and authentication parts work. Besides,list
,cd \usr\share\griffin && list
also return the same result as what I get in windows cmd. But in the following code, after running the py file in linux stack, it only returns (Cmd)
. Nothing happened with sendgcode G28
.
<?php
set_include_path('C:/xampp/htdocs/phpseclib1.0.15');
include('Net/SSH2.php');
$ssh = new Net_SSH2('ip');
if (!$ssh->login('root', 'password')) {
exit('Login Failed');
}
echo $ssh->exec('python3 /usr/share/griffin/command_util.py && sendgcode G28');
?>
The following code in Python wouldn't receive any retun value
#
import paramiko
# realize transport
trans = paramiko.Transport(('ip', 22))
# connection
trans.connect(username='root', password='ultimaker')
# Specify the transport of the sshclient object as the above trans
ssh = paramiko.SSHClient()
ssh._transport = trans
# execute command
stdin, stdout, stderr = ssh.exec_command('python3 /usr/share/griffin/command_util.py \n sendgcode G28')
print(stdout.read().decode())
# close connection
trans.close()
The Linux stack shows that sendgcode command is undocumented. I don't understand why I could use it in Windows cmd but not in PHP or Python. Any help would be super appreciated!