-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh_web.rb
More file actions
39 lines (30 loc) · 1.16 KB
/
Copy pathssh_web.rb
File metadata and controls
39 lines (30 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# This script is to be called by the web app
require 'net/ssh'
if !ARGV.any?
raise "Empty address!"
end
host = "#{ARGV.first}"
# Will PROBABLY always be pi
user = 'pi'
password = 'sfsfsfsf'
puts "Starting connection to #{host} with user #{user}"
Net::SSH.start(host, user, port:2210, password: password) do |ssh|
channel = ssh.open_channel do |ch|
# For now using usb by serial - testing purposes
ch.exec "source ~/drone-comms/pyenv-path.sh; echo $PATH; python ~/drone-comms/drone/status.py /dev/serial/by-id/usb-3D_Robotics_PX4_FMU_v2.x_0-if00 --drone_id 2" do |ch, success|
raise "could not execute command" unless success
# "on_data" is called when the process writes something to stdout
ch.on_data do |c, data|
puts "got stdout: #{data}"
# $stdout.print data
end
# "on_extended_data" is called when the process writes something to stderr
ch.on_extended_data do |c, type, data|
puts "got error: #{data}"
# $stderr.print data
end
ch.on_close { puts "done!" }
end
end
ssh.loop
end