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

1

I found out about SSH and socket connections to remote servers and also connections to local serial ports, but I still have not found out how to put things together.

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

NOTE: I tested on a ubuntu bash terminal and it worked normally, but the modem's picocom terminal did not work.

Here's the snippet of the PHP script I'm 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...');
}

?>
    
asked by anonymous 16.08.2017 / 03:44

0 answers