Osc/state take a long time for SC2?

I’m using xamarin forms to create mobile app and I would like to know if there is a way or if I made a mistake to POST state. I followed this guide : RICOH THETA SC2 Developer Information but response to POST http://192.168.1.1/osc/state take 1 min 20 s, it’s too long for my clients. In the others device like theta V or Z1, it’s faster. so maybe I should make some modifications in my code.

public static async Task POSTStateCamera()
{
   try
   {
      // MakeRequest uses HttpClient.PostAsync() to make request to http://192.168.1.1/<endpoint>
      var response = await MakeRequest<object>("POST", "osc/state", null, 10);
      _stateCamera = JsonConvert.DeserializeObject<StateCameraResponse>(await response.Content.ReadAsStringAsync());
     _isCameraConnected = true;
   }
   catch (Exception ex)
   {
     _isCameraConnected = false;
   }
}

When I add a breakpoint to _stateCamera line I wait 1 min 20 s, why ? Can I update something to POST faster.

Thank you in advance.

What command are you giving immediately before getting the camera state?

If you are taking a picture, try using /osc/commands/status

Commands_status

The SC2 has slightly different behavior than the Z1/V to check the “status” of the camera. The /osc/commands/status will not work with “startCapture” on the SC2. However, it does work with “takePicture”

Please post the sequence of commands you are giving as we can try and replicate it.

It should not take 1 min 20s. That is unexpected behavior.

Example of sequence:

If options, indicate if you are putting all the options as a single set or running setOption for each option one at a time. There are some problems with multiple options (rare bug for only some combinations).

  1. setOption captureMode image
  2. setOption exposureProgram 1
  3. setOption shutterSpeed 0.004 (list data type used)
  4. camera.takePicture
  5. check status (list technique, osc/commands/status or osc/state)

I use an interface to manage options and make capture. Before going to this interface I made 2 requests

  • GET 192.168.1.1/osc/info
  • POST 192.168.1.1/osc/state
    If I’m able to make the two requests I make user going to the next page to make capture etc.

So with your explanation, can you confirm to me that I should execute /osc/commands/status for SC2 and osc/state for V and Z1 ? How I should be sure that I’m connected to ricoh, should I execute /osc/commands/status and osc/state before startCapture or getLivepreview ?

Is the SC2 taking over a minute to return the state in the 2nd step below?

  1. GET 192.168.1.1/osc/info
  2. 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';
}

Thank you for the explanation, I need to have a live preview and user has a button to save a single capture so I should use take_capture. I thought I should execute /osc/info and /osc/state to check if the camera is online. So I can remove 2nd step that is useless however here is header for /osc/state request

“Accept”: “application/json”

As you can see I don’t send “content-type”: “application/json;charset=utf-8”. Maybe it work’s better.
I will try it and tell you back the result.

The header for Content-Type is required, but may depend on your http library. Better to put it in.

It will often fail in my tests if I don’t specify the header Content-Type on a POST with body.

From the official RICOH API documentation:

Overview

image

The response to /osc/state from the SC2 should take less than a second.

Report back if you still have a problem.

Hello @craig and sorry for the late reply, I had set up “Content-Type” but nothing change. I made some tests. I made API call using insomnia (tools like postman), I noticed when I make request it takes a lot of time. For example, for the osc/commands/status it takes 20 s as you can see

takeCapture

status

get infos

Do you have any idea ?

Do you have a log of both the request and response headers?

Can you test your application on a different Wi-Fi card? For example, try it with another USB Wi-Fi adapter if you have one available.

I’ll take a look at Insomnia and see if I can replicate the problem.

Are you on Mac or Windows? We have an API tester that I’m going to compile into binary format so you can try it.

On the side of the SC2, press and hold the power button for longer than 10 seconds until the camera shuts down. The camera has two power state, sleep and power off. Try power it off and then power it on again.

My test using Insomnia take less than 1 second.

takePicture - executes immediately

image

Possible Problems

Possible Problem test or fix
camera is stuck with background process completely shutdown camera by pressing and holding power button
Wi-Fi interference or incompatibility with SC2 chipset change Wi-Fi adapter or run on physical device iPhone or Android phone
camera too far away from computer place camera within 30cm of Wii-Fi adapter on computer
camera Wi-Fi chipset defective does the same camera work with the official RICOH THETA mobile app on a physical phone?

I found the issue, it was the firmware, I just updated it and it work’s well. Now my requests are faster, thank you a lot @craig :slight_smile:

2 Likes

Thanks for the report back on the success and behavior of the camera.

This type of detailed behavior report and solution helps other people.

@jcasman and I are in the process of documenting differences with the SC2 API compared to the V/Z1 based on updated testing with the newest firmwares.