Last active
December 18, 2015 12:09
-
-
Save yoggy/5780885 to your computer and use it in GitHub Desktop.
sample program for Sony NEX-6 (Smart Remocon App)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# | |
# nex6-capture.rb - sample program for Sony NEX-6 (Smart Remocon App) | |
# | |
require "socket" | |
require 'json' | |
require "pp" | |
require "open-uri" | |
$host = "192.168.122.1" | |
$port = 8080 | |
# enable preview | |
s = TCPSocket.open($host, $port) | |
s.print("POST /sony/camera HTTP/1.1\r\nContent-Length: 60\r\n\r\n{\"method\":\"startRecMode\",\"params\":[],\"id\":5,\"version\":\"1.0\"}") | |
s.flush | |
body = s.read.split(/\r\n\r\n/)[1] | |
p JSON.parse(body) | |
s.close | |
# waiting for starting preview...? | |
sleep 7 | |
# take picture | |
s = TCPSocket.open($host, $port) | |
s.print("POST /sony/camera HTTP/1.1\r\nContent-Length: 63\r\n\r\n{\"method\":\"actTakePicture\",\"params\":[],\"id\":10,\"version\":\"1.0\"}") | |
s.flush | |
body = s.read.split(/\r\n\r\n/)[1] | |
doc = JSON.parse(body) | |
s.close | |
# {"id":10,"result":[["http://192.168.122.1:8080/postview/pict20130614_175010_0.JPG"]]} | |
result_url = doc["result"][0][0] | |
result_filename = File.split(result_url)[1] | |
# download picture | |
jpeg = open(result_url).read | |
open(result_filename, "wb"){|f|f.write(jpeg)} | |
puts "capture image=#{result_filename}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment