module SonyCameraRemoteAPI::Scripts
Helper module for connecting to camera by wi-fi.
Public Instance Methods
Connects to camera by Wi-Fi. This method does nothing if already connected, which is judged by ifconfig command. @param [String] interface Interface name, e.g. wlan0 @param [String] ssid SSID of the camera to connect @param [String] pass Password of the camera to connect @return [Boolean] true
if succeeded, false
otherwise.
# File lib/sony_camera_remote_api/scripts.rb, line 15 def connect(ssid, pass, interface) run_external_command "sudo bash #{connection_script} #{ssid} #{pass} #{interface}" end
Full path of connection script
# File lib/sony_camera_remote_api/scripts.rb, line 60 def connection_script File.join path, 'connect.sh' end
Path where scripts are located
# File lib/sony_camera_remote_api/scripts.rb, line 55 def path File.join root, 'scripts' end
Restart the interface and connect to camera by Wi-Fi. @param [String] interface Interface name, e.g. wlan0 @param [String] ssid SSID of the camera to connect @param [String] pass Password of the camera to connect @return [Boolean] true
if succeeded, false
otherwise.
# File lib/sony_camera_remote_api/scripts.rb, line 25 def restart_and_connect(ssid, pass, interface) run_external_command "sudo bash #{connection_script} -r #{ssid} #{pass} #{interface}" end
Get gem root path (not smart)
# File lib/sony_camera_remote_api/scripts.rb, line 50 def root File.expand_path '../../..', __FILE__ end
Run shell command. Command output are written to stdout witout buffering. @param [String] command Command to execute @return [Boolean] true
if succeeded, false
otherwise.
# File lib/sony_camera_remote_api/scripts.rb, line 34 def run_external_command(command) puts command Open3.popen2e(command) do |_i, oe, w| oe.each do |line| puts line end # Return code if w.value != 0 return false else return true end end end