Change the API version once at the beginning of the session. You don’t need to have this in the same command as takePicture.
You can use info or state to check to see the camera is still connected. info uses GET and may be easier.
Set API Version
setApiV2 = function() {
var args = {
data: { "name": "camera.setOptions",
"parameters":{
"sessionId": "SID_0001",
"options": {
"clientVersion": 2
}
}
},
headers: { "Content-Type": "application/json" }
};
client.post("http://192.168.1.1:80/osc/commands/execute", args, function (data, response) {
console.log(data);
var thetaResponse = document.getElementById('thetaResponse');
thetaResponse.innerHTML = JSON.stringify(data);
});
}
Take Picture
takePicture = function() {
var args = {
data: { "name": "camera.takePicture"},
headers: { "Content-Type": "application/json" }
};
client.post("http://192.168.1.1:80/osc/commands/execute", args, function (data, response) {
console.log(data);
var thetaResponse = document.getElementById('thetaResponse');
thetaResponse.innerHTML = JSON.stringify(data);
});
}
Get File
getImage = function() {
var lastImageUrl;
var args = {
data: {
"name": "camera.listFiles",
"parameters": {
"fileType": "image",
"entryCount": 1,
"maxThumbSize": 0
}
},
headers: {"Content-Type": "application/json"}
}
client.post("http://192.168.1.1/osc/commands/execute", args, function (data, response) {
lastImageUrl = data.results.entries[0].fileUrl;
var download = function(uri, filename, callback){
request.head(uri, function(err, res, body){
console.log('content-type:', res.headers['content-type']);
console.log('content-length:', res.headers['content-length']);
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
});
};
console.log(lastImageUrl);
// download('http://192.168.1.1/files/744a605553442020024b0202cb00f201/100RICOH/R0012006.JPG', '360_images/lastFile.jpg', function(){
download(lastImageUrl, '360_images/lastFile.jpg', function(){
});
});
}
I have not tried this in over a year. The problems described may be resolved now.