RICOH THETA Mobile App Dev with JavaScript


#1

After having fun building a desktop application for the THETA with Electron, I decided to build a simple mobile application with JavaScript using Cordova/PhoneGap.

The process is going smoothly. I have the application working on Android with these features:

  • Get info
  • Start session
  • Set to THETA API v2.1
  • Take Picture

It’s easy to add additional functionality. After the 4th of July holiday, I’ll try and enable image viewing, which should hopefully be fairly easy to implement since the Electron app with Google VR. In the Electron app, I used node-rest-client for the HTTP requests.

In the Cordova App, I’m using jQuery. I’ll put together a tutorial next week. The main code to talk to the THETA is below, both GET and POST examples.

function getInfo() {
    $(document).ready(function() {
        console.log("ready");
        var url = "http://192.168.1.1/osc/info";
        $.get(url, function(data, status){
            alert(JSON.stringify(data));
        });
    });    
}

function startSession() {
jQuery.ajax({
    url: 'http://192.168.1.1:80/osc/commands/execute',
    dataType: 'binary',
    type: 'POST',
    data: JSON.stringify({
      "name": "camera.startSession",
      "parameters": {}
    }),
    complete: function (data) {
      alert('complete' + JSON.stringify(data));
    },
    success: function(data){
      alert('success' + JSON.stringify(data));
    }
  });
}

function takePicture() {
jQuery.ajax({
    url: 'http://192.168.1.1:80/osc/commands/execute',
    dataType: 'binary',
    type: 'POST',
    data: JSON.stringify({
      "name": "camera.takePicture",
      "parameters": {}
    }),
    complete: function (data) {
      alert('complete' + JSON.stringify(data));
    },
    success: function(data){
      alert('success' + JSON.stringify(data));
    }
  });
}

#2

Really cool using Cordova to build an app that accesses the THETA!


#3

Here’s an action shot from field testing the app with a THETA.

Hoping to see a range of apps in the future that do image processing for different industries.


#4

Man, that’s exciting!


#5

I’ve been looking at Crosswalk as a way to get better support of 360 images with Cordova.

In particular, there is this tutorial on getting A-Frame applications onto Android phones.


#6

I used Crosswalk to get A-Frame working inside of an Android hybrid application.

I also added a custom icon for the app.

Why Develop a Hybrid App Instead of Browser-based App?

Compared to A-Frame in a web browser on a mobile phone, these are the advantages of building a hybrid app for business (liked used car sales) or industrial applications (like factory line optimization):

  • Use THETA API to control camera (take picture and view in same application)
  • Access other mobile device features like GPS and save to file
  • Auto-edit image (apply filters, reduce size of image for archiving)
  • Push to your own server for custom workflow

Warning About Crosswalk Project

The Crosswalk Project is now an orphan. I’m using it for testing because there was a tutorial to use A-Frame with Crosswalk. This is also helping me to learn more about the Android SDK and toolchain. The longer-term solution is to use plain Cordova and the built-in Android Webview. For desktop applications, Electron still looks promising with an active community.


Proper steps for working on Theta API v2.1
#7

I’m continuing to plug away with Cordova, PhoneGap and Crosswalk.

I can get a THETA image to work as an embedded view in Crosswalk, but I can’t get the buttons to work.

In the above example, I am using A-Frame and Crosswalk.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <script src="aframe-master.js"></script>
    <script src="jquery-mobile-1.4.5.min.js"></script>
    
    <style>
    #aframebox {
      height: 200px;
      width: 100%;
    }

    .ButtonBasic {
      text-align: center;
    }
    </style>
</head>
<body>
  <a-scene embedded id="aframebox" vr-mode-ui="enabled: false">
    <a-sky src="museum.jpg" rotation="0 -130 0"></a-sky>
  </a-scene>
  <div class="ButtonBasic">
    <button onclick="getInfo()">Get Info</button>
    </div>

Unfortunately, the buttons don’t work.

I’m getting this error:

XMLHttpRequest cannot load http://192.168.1.1/osc/info. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'app://guide.theta.aframe' is therefore not allowed access.

Using Cordova, I can get the buttons to work, but can’t get the 360 image to display with navigation. The equirectangular image is fine.

I’ve tested it with Android 7, 7.1, and 8.

As there are limited phones running 7, 7.1, and 8, I’m thinking of going back to focus on crosswalk.

If anyone has a working app they want to share, please share it.

Watching this video now.

As of July 26, 2017, this is the state of WebVR support in iOS (it doesn’t exist)

After watching the video above, I was inspired to get WebVR working with Cordova.

I now need to figure out how to map the equirectangular image to a sphere and then work on the buttons.