#!ruby -Ku # Wifi接続したGoProをRubyから制御するサンプル # by GOROman require 'net/http' class GoProControl def initialize( host ) @http = Net::HTTP.new( host ) @password = get_password() end def get_password res = control( "bacpac", "sd" ) res.unpack("CCa*")[2] end def control( type, command, param = nil ) str = "/#{type}/#{command}" str += "?t=#{@password}" if @password str += "&p=%#{param}" if param res = @http.get( str ) res.body end def shutter control( "bacpac", "SH", "01" ) end def mode( param ) control( "camera", "CM", param ) end end IP = "10.5.5.9" camera = GoProControl.new( IP ) # 01:写真撮影モード camera.mode( "01" ) # シャッターを切る camera.shutter