Help i'cant execute startSession

I can’t execute camera.startSession of a theta z1
{
“fingerprint”: “FIG_0002”,
“state”:{
“_apiVersion”: 2,
“batteryLevel”: 0.5,
“_batteryState”: “disconnect”,
“_cameraError”:[],
“_captureStatus”: “idle”,
“_capturedPictures”: 0,
“_compositeShootingElapsedTime”: 0,
“_function”: “normal”,
“_latestFileUrl”: “”,
“_mySettingChanged”: false,
“_pluginRunning”: false,
“_pluginWebServer”: true,
“_recordableTime”: 0,
“_recordedTime”: 0,
“storageUri”: “http://192.168.1.1/files/90014a68423861503e030e2b811c8500/
}
}

You don’t need startSession for the Z1.

The start session is only required for the SC.

The API for the Z1 is largely the same as the SC2 for basic commands.

There re many examples here:

https://theta360.guide/special/sc2/

Post again if you continue to have problems.

1 Like

I already managed to takePicture, now I don’t know how to save that image on the computer, I’m working in Javascript
Help Please

1 Like
/// This example uses osc/commands/status to get the state of takePicture,
/// then it uses osc/state to get the URL of the file for download.
/// The full process is:
/// 1. takePicture
/// 2. check on status of take picture and make sure state is done
/// 3. if the status does not show state as done, then loop back to the check
/// 4. if the status shows state as done, then get the URL of the last image with state
/// 5. download file and save to disk.  This only works on the command line
import 'dart:io';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:apitest/download_ready.dart';
import 'package:apitest/firmware_version.dart';

Future<String> takeAndDownload() async {

  firmwareVersion();

  String readyStatus = await downloadReady();

  if (readyStatus == "ready") {
  var url ='http://192.168.1.1/osc/state';


  var response = await http.post(url,
      headers: {"Content-Type": "application/json;charset=utf-8"}
  );

  Map<String, dynamic> thetaState = jsonDecode(response.body);


  // print(thetaState);
  String imageFileUrl = thetaState['state']['_latestFileUrl'];
  print("Writing file from the following URL");
  print(imageFileUrl);

  String imageFileName = imageFileUrl.split("/")[6];
  
    await File(imageFileName).writeAsBytes(await http.readBytes(imageFileUrl));
    print("download complete");
    return "success";
  } else {
    print("download failed");
    return "fail";
  }
}

Check That File Is Ready to Download

import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:apitest/commands/take_picture.dart';


Future<String> isDone(String id) async {
  var url ='http://192.168.1.1/osc/commands/status';
  Map 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 takePicture();
  // print(takePictureResponse);
  Map<String, dynamic> pictureInfo = jsonDecode(takePictureResponse.body);
  String id = pictureInfo['id'];
  print('The status ID is $id');

  bool keepGoing = true;
  int elapsedSeconds = 0;  

  while (keepGoing) {
    var currentStatus = await isDone(id);
    // print(currentStatus);

    await new Future.delayed(const Duration(seconds: 1));
    print("Elapsed time: $elapsedSeconds seconds. State: $currentStatus");
    elapsedSeconds++;
    if (currentStatus == "done") {
      keepGoing = false;
    }
  }

  // String fileUrl = await getLastImageUrl();
  print("picture ready for download");
  return 'ready';
}
1 Like

would this command line apply to flutter?

The example above only shows the THETA-specific functions. Once you have the image in your mobile app, you need to use one of the numerous packages to save the file to either Android/iOS.

For example, to save to local storage, you would need to extend for iOS/Android file system support with something like this:

https://pub.dev/packages/path_provider
https://pub.dev/packages/path

I’m assuming that your main issue is how to check to make sure the image is ready to download after you take a picture. The fileUri on the camera can be pulled with an HTTP GET. Once you have the THETA image in system memory on your app, then save it to file. The method to save the file to local storage is dependent on the underlying OS (Android, iOS, Linux, Windows).

1 Like

Hello Craig.

What about camera._start_capture for Z1? How I can starting capture, if this command need parameter session ID, and this parameter should return after camera.startSession command.

Unfortunately, documentation is not transparently.
P.S. Where I can get command list only for Z1?
Regards

use api version 2.1

The Z1 does not use session ID with startCapture. Refer to API version 2.1

Overview

https://api.ricoh/docs/theta-web-api-v2.1/commands/camera.start_capture/

OLD Version - Do not use version 2.0

Overview

Supporting older cameras

If you need to support the SC and S in addition to he Z1, use state to get the apiVersion and identify if if is is using API 2 (V, Z1) or API 1 (SC, S).

Getting_started