Is the SC2 taking over a minute to return the state in the 2nd step below?
- GET 192.168.1.1/osc/info
- POST 192.168.1.1/osc/state
Is so, share your http header that you are using, the content-type as application/json;charset=utf-8.
There are different API commands to take a picture depending on whether you are taking a sequence or a single still image.
For a single still image, use this:
Camera.take_picture
For a sequence, use this (only if you are taking brackets, interval shooting):
Camera.start_capture
If you are using camera.takePicture for a single still image, you can use /osc/commands/status for the SC2, V, and Z1.
This works for me with the SC2, V, Z1. Note that this is Dart, not JavaScript, but it should be similar.
Make sure you pass the Content-Type header in your HTTP request.
You can check if the camera is online with /osc/info as it is a simple GET. If /osc/info works, /osc/state should work.
Future<http.Response> status(id) async {
var url = 'http://192.168.1.1/osc/commands/status';
Map data = {'id': id};
//encode Map to JSON
var body = jsonEncode(data);
var response = await http.post(url,
headers: {"Content-Type": "application/json;charset=utf-8"}, body: body);
print("The HTTP response code is: ${response.statusCode}");
print("The HTTP response from status is:");
prettyPrint("${response.body}");
return response;
}
Code above used in example loop.
Future<String> isDone(String id) async {
var url = 'http://192.168.1.1/osc/commands/status';
var data = {'id': id};
var payload = jsonEncode(data);
var response = await http.post(url,
headers: {'Content-Type': 'application/json;charset=utf-8'},
body: payload);
Map<String, dynamic> status = jsonDecode(response.body);
String state = status['state'];
return state;
}
Future<String> downloadReady() async {
print(
'Test of taking picture and then checking to see if picture is ready for download');
print('---');
var takePictureResponse = await ThetaRun.takePicture();
String id = takePictureResponse['id'];
print('The status ID is $id');
var keepGoing = true;
var elapsedSeconds = 0;
while (keepGoing) {
var currentStatus = await isDone(id);
// print(currentStatus);
await Future.delayed(const Duration(seconds: 1));
print('Elapsed time: $elapsedSeconds seconds. State: $currentStatus');
elapsedSeconds++;
if (currentStatus == 'done') {
keepGoing = false;
}
}
var fileUrl = await getLastImageUrl();
print('picture ready for download at $fileUrl');
return 'ready';
}