How To Set Up a Linux Environment in the THETA to Control the Camera With Bash, Ruby, Python

There is a great article in Japanese by KA-2 about running a Linux environment inside the THETA.

The RICOH THETA V and RICOH THETA Z1 use Android as the OS. You can also customize THETA as if you were making an Android application. The customization function is called “plug-in” (see the end of this article for details).

Register Your THETA V or Z1 to Unlock Developer Capability

You can install an Android app that uses adb shell inside the THETA. This provides a Linux user experience with standard tools like ssh, apt, git, wget, etc. Multilingual development is possible. No root is required. It is easy to switch between the two environments, enabling THETA computing. It’s much quicker to go from idea to prototyping. This makes the THETA suitable for hackathons.

See the video below:

In this example, we’ll use an application called Termux to provide a simple Linux environment deployed in the sandbox (application-specific area where the system is kept safe). All you have to do is use the environment with CUI.
The Termux development community has released the official apk not only on Google Play but also on F-Droid (the most secure aspect). Thanks to this, “if you put your THETA in developer mode, you can use it”.

Those who have experience with Linux computers, including the Raspberry Pi, but are hesitant about messing with the THETA because they feel that they “don’t know the Android application development environment” will now be able to program the THETA! The RICOH THETA itself looks like a Raspberry Pi. You will be able to gain experience with the Android mechanism little by little from the environment you are used to and create THETA plug-ins and Android apps.

If you’ve already begun to use the Android application development environment with theTHETA plug-in, you’ll gain a deeper understanding of THETA-specific mechanisms and Android. You can understand the mechanism of the THETA Plug-in SDK, which has been made into a model, and you can experience various things without depending on the THETA plug-in library.

Requirements

  1. After registering as a developer, set THETA to developer mode
  2. Install Android Studio. Download and install from here. We want to use the adb command for several things.
  3. Set up Vysor

Termux Installation

Grab Termux from F-Droid. Make sure you get the apk.

https://f-droid.org/repository/browse/?fdid=com.termux

The file name is “com.termux_82.apk” (as of mid-November 2019). The number is the release version number. Larger numbers are more up-to-date.
Once downloaded, use the Android Studio Terminal or Windows command prompt to install the apk with adb.

adb install -r FILE_PATH\com.termux_82.apk

Termux initial setup

It’s often more convenient for development to log in to your THETA via wireless LAN and use Wi-Fi instead of connecting the cable to THETA and a PC. It’s a common practice on Linux board computers such as the Raspberry Pi. The main task is to prepare the environment.

Enter this adb command to make the THETA wifi usable even if the THETA is connected to the PC with a USB cable.

$ adb shell settings put global usb_debug true

Once implemented, this setting is maintained until you issue a command with the parameter set to false or return to the factory default settings.

Set THETA wireless LAN client mode (CL mode). Since it is necessary to install in Termux environment, connect THETA to an access point that can be connected to an external network.

You can connect it to your home router, or you can tether the smartphone and connect it to the smartphone from THETA (note the communication charges). You can remember multiple destinations.

Make the keyboard usable in Vysor environment.

Initially, the keyboard input is not received from Vysor, so enter this adb command to enable keyboard input in the Vysor environment.

$ adb shell am force-stop com.theta360.receptor 

What this command is doing is to pause the “Shooting app (com.theta360.receptor)” . To resume, press and hold the shutter button, the command described in the document, and power on after complete power off.

Enable developer options

If you don’t see the developer option in THETA V, you need to go to About phone and tap the Build number seven times to enable the developer option.

Start Termux from Vysor.

When Termux is started, a screen like the one on the right side of the image below is displayed, and it is ready for soft keyboard input and PC keyboard input.

Using apt

You can install necessary packages from outside. This is a big advantage of using Termux environment over adb shell. The package management software is apt. This is the work to update the apt management information to the latest status.

apt update
apt upgrade

pkg can also be used. Pkg in the Termux environment is a wrapper for apt and the contents are the same.

Installing a text editor

Even those who do not write programs need to edit the configuration files (text files).
You can use the vi editor with Termux installed, but you can also install and use vim, Emacs, and nano.
For example, when installing nano

apt install nano

It is convenient to install it according to your preference and edit the settings file of the editor itself. (I write the set number in ~ /.vimrc in vim and display the line number. In the case of nano, set linenumbers in /etc/nanorc is the same.)

Give access to storage

At this point, Termux has read / write permissions only in its own application area (THETA is limited to a maximum of 2GB including other application areas). Therefore, give read / write permission to the area where the shot image is saved (under /storage/emulated/0/DCIM in the adb shell).
You can always do it, but let’s do it when you can use the Vysor screen.

First, give Storage access permission to Termux from Vysor screen Settings → Apps → Termux.

image

image

termux-setup-storage

Then you can create a symbolic link under ~ / storage as well as read/write permission.
You can check it by typing

ls -al ./storage

"~ / Storage/dicm is equivalent to /storage/emulated/0/DCIM

(As an aside, /sdcard/DCIM is a symbolic link of /storage/emulated/0/DCIM

If you enter this command without giving permission for storage access, a dialog will be displayed. Answer “ALWAYS” and then enter the same command again.

SSH server

You can use OpenSSH with Termux.
Follow the steps below for installation and setup.

  1. Install OpenSSH (just hit apt install openssh)
  2. Generation of private key & public key pair (In the THETA initial setting, it is recommended to generate with an external device)
  3. Put public key in ~ / .ssh / authorized_keys (direct copy and paste recommended)
  4. Create ~ / .bashrc and write only one line “sshd”
    (.bashrc seems to be fine without shebang)

About 2.
It is easier to understand if you use something other than Termux. It can be generated with an SSH-compatible client application. At this point, if you want to use the key generated by Termux in THETA, you can extract the file generated by this application.
About 3.
At this stage, it is difficult to copy the public key file created on the external device to an area where Termux can refer. However, since the public key is a text file that contains only one line of text, I do not want to copy it forcibly, and I think that copying the text directly to ~ /.ssh /authorized_keys with the editor on Termux is the fastest work procedure. The
About 4.
This is a setting to make the SSH server start up automatically when Termux starts. The Termux environment may be the biggest advantage for THETA to be able to do this. Depending on the description of this shell script, various behaviors can be achieved. It’s a “universal THETA plug-in”.
This is the end of the painful environment of connecting a USB cable.

Log in to Termux via SSH

From here, work by unplugging the cable connecting THETA and the PC.

Introducing client apps

For each terminal that logs in to THETA, we will introduce a client application that allows SSH login.
(As mentioned above, these apps can also create a private / public key pair.)

Android - ConnectBot https://play.google.com/store/apps/details?id=org.connectbot
Windows - TeraTerm - Tera Term Open Source Project
Mac - ssh client on terminal will work

IP Address: In AP mode, it is 192.168.1.1
Port: 8022
Username: anything other than blank
Key: Give the private key file you created in the previous task.

Client mode IP address.

There are ways to check with various commands. For example, “nmap -sT -p8022 192.168. *. *” Searches for the IP address of the TCP protocol that opens the 8022 port. I think there are other arp commands.

Make Termux a startup plug-in

You can start Termux with the same operation as a normal THETA plug-in.
You can set from the basic application for smartphones as well as the basic application for PCs.

SSH connection

Let’s try SSH connection when you are ready.
The following is an example of connecting from an Android device with ConnectBot.

image

Termux termination

Termux cannot receive button operations on THETA itself.
For this reason, to exit Termux, you need to type the following command while logged in with SSH.

am broadcast -a com.theta360.plugin.ACTION_FINISH_PLUGIN --es packageName com.termux

If it’s too troublesome to type in a command, you can force termination by using “Short press of power button” to make THETA sleep, terminate Termux, and immediately return from sleep.

The next set of articles will explain how to create simple scripts to control the camera. Check back soon for more articles.

1 Like

Here’s my experience from Linux to the THETA.

THETA is plugged into my computer with a USB cable.

check to make sure THETA is online and visible to workstation

using adb devices -l

Download termux

https://f-droid.org/packages/com.termux/

Using version 0.84 released on Nov 25, 2019. New and fresh. :hot_pepper:

image

install termux

image

Verify with Vysor

image

Enable Keyboard

image

image

Start Termux

Click on icon on home screen.

Enable Wi-Fi when connected with USB

$ adb shell settings put global usb_debug true

image

Set up Wi-Fi with Client Mode if not already Setup

image

Test Internet Connection

ping a domain such as theta360.guide

Test apt and install a text editor

image

install nano with apt

image

set linenumbers in nano with nano ~/.nanorc

image

image

Set Storage Permission

image

image

image

Setup Termux Storage

image

Check Storage Setup

image

Install OpenSSH

image

Copy public ssh key from workstation to camera

image

Add ssh public key

image

Add sshd to .bashrc

image

image

Login from Linux

Make sure you use port 8022

image

Finding IP address

I’m using a simple Zeroconf discovery script to find the IP address.

Setting Client Mode IP Address

You can also set the client mode IP address using this article. In my case, I’ve set the client mode IP address of the THETA to 192.168.2.123 to make it easier to remember and find.

Troubleshooting

If you run into problems, start sshd in debug mode on a free port

sshd -d -p 2222

From your client, login with:

sshd -d -p 2222

image

image

Stopping Termux

am broadcast -a com.theta360.plugin.ACTION_FINISH_PLUGIN --es packageName com.termux

Next Article

Control Camera LEDs and Functions