Skip to content

Instantly share code, notes, and snippets.

@humboldt
Forked from GOROman/GoProControl.rb
Created October 7, 2018 22:03
Show Gist options
  • Save humboldt/559ff8fd1919a184e2d46202b15b1574 to your computer and use it in GitHub Desktop.
Save humboldt/559ff8fd1919a184e2d46202b15b1574 to your computer and use it in GitHub Desktop.

Revisions

  1. @GOROman GOROman created this gist Jan 25, 2015.
    45 changes: 45 additions & 0 deletions GoProControl.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    #!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