How do I access a serial port from an SSH remote server with PHP?

Asked

Viewed 220 times

1

I found about SSH and socket connections to remote servers and also about connections to local serial ports, but I still can’t find out how to put things together.

Scenario: I need to access the /dev/ttyACM0 port of a TX modem (which I connect via SSH) p/ send commands.

OBS.: I tested in a terminal bash Ubuntu and it worked normally, however in the terminal of the modem did not work.

Follow the excerpt from the PHP script I’ve been using so far:

<?php
 //(...) // definição das variáveis,etc.

 $connection = ssh2_connect($server, $port);
 if (ssh2_auth_password($connection, $username, $password)) {

 // aqui coloco o comando que envio p/ o modem
 $cmd = 'network command '. $param1 .' svlan '. $param2 . ' ' . $param3; 

 $stream = ssh2_exec($connection, $cmd); // Executa o comando
 $errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);

 // Habilita streams bloqueantes
 stream_set_blocking($errorStream, true);
 stream_set_blocking($stream, true);

 // Saída
 echo "Output: " . stream_get_contents($stream);
 echo "<br><br>Error: " . stream_get_contents($errorStream);

 // Fecha streams
 fclose($errorStream);
 fclose($stream);
}
 else
{
   die('Authentication Failed...');
}

?>
  • Have you tried with that tutorial/examples?

  • Yes...Thanks... I’m actually testing some commands here... In a linux terminal bash with SSH itself I have already managed to run with the commands ssh2_connect and ssh2_exec, but I am not able to communicate with the serial port of the remote modem mentioned... I don’t know yet if the problem is with the modem terminal that is different... or if it is problem with the socket...

  • I authenticated the question and includes the code I am using p/ facilitate the description/understanding...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.