Good day. There is a task. Receive / send data from Arduino MC to computer. There is a bunch of comp (Windows) -> routers with OpenWrt -> and an Arduino connected to it via USB.

Access to the router from a computer via SSH. I checked using putty:

echo 123 > /dev/ttyACM0 // отправить строку cat /dev/ttyACM0 // получить ответ 

Everything works fine. But I need to get to do this in my application written in C # WPF. Now I understand the connection via SSH to the router. Tell me how to do this? Tried to use the Tamir.SharpSsh library , but with

 SshStream ssh = new SshStream(host, user, pass); 

hangs and does not react.

Tell me how to implement it or at least in which direction to dig?!

Thank.

    2 answers 2

    Just stumbled upon SSH.NET Library and simple code

     var client = new SshClient( host, login, pass ); client.Connect( ); var testValue = "123"; var command = client.RunCommand( string.Format( "echo {0} > /dev/ttyACM0", testValue ) ); var result = command.Result; //result = result.Substring( 0, result.Length - 1 ); // Remove \n character returned by command List.Items.Add( result ); client.Disconnect( ); 

    without dancing with a tambourine, the LED on my ARDUINO came to life) I will now understand how to lure the data) If anyone knows, please reply)

      Well, it’s not a good idea to run the same putty with parameters and catch what he did not do there through the answer.

       static void Main(string[] args) { Process cmd = new Process(); cmd.StartInfo.FileName = @"C:\Program Files (x86)\PuTTY\plink.exe"; cmd.StartInfo.UseShellExecute = false; cmd.StartInfo.RedirectStandardInput = true; cmd.StartInfo.RedirectStandardOutput = true; cmd.StartInfo.Arguments = "-ssh mahi@192.168.37.129 22 -pw mahi"; cmd.Start(); cmd.StandardInput.WriteLine("./myscript.sh"); cmd.StandardInput.WriteLine("exit"); string output = cmd.StandardOutput.ReadToEnd(); } 

      Took from here https://stackoverflow.com/questions/27592329/run-unix-commands-using-putty-in-c-sharp