Controlling THETA Over USB with libptp

We’ll test libptp with the included ptpcam command line program.

Preparing the Camera

Camera is on, there is a blue light

Camera is connected with USB to Linux computer (camera is USB 2.0, but it’ll work on a USB 3.0 port)

Camera is not mounted

Verify Computer finds Camera as USB Devices

$ lsusb Bus 003 Device 009: ID 05ca:0366 Ricoh Co., Ltd

Verify ptpcam Can Connect to Camera

First verify that ptpcam can connect to the camera.

$ ptpcam -i Camera information ================== Model: RICOH THETA S manufacturer: Ricoh Company, Ltd. serial number: '00010093' device version: 01.42 extension ID: 0x00000006 extension description: (null) extension version: 0x006e

Next, we’ll list all the operations that libptp can access on the camera over usb.

$ ptpcam -o Listing supported operations... Camera: RICOH THETA S 0x1001: GetDeviceInfo 0x1002: OpenSession 0x1003: CloseSession 0x1004: GetStorageIDs 0x1005: GetStorageInfo 0x1006: GetNumObjects 0x1007: GetObjectHandles 0x1008: GetObjectInfo 0x1009: GetObject 0x100a: GetThumb 0x100b: DeleteObject 0x1014: GetDevicePropDesc 0x1015: GetDevicePropValue 0x101b: GetPartialObject 0x9001: UNKNOWN 0x9991: UNKNOWN 0x9999: UNKNOWN 0x999a: UNKNOWN 0x999b: UNKNOWN 0x999c: UNKNOWN 0x999d: UNKNOWN 0x100e: InitiateCapture 0x1016: SetDevicePropValue 0x101c: InitiateOpenCapture 0x1018: TerminateOpenCapture 0x99a2: UNKNOWN

It’s looking very promising. Next, we’ll list the properties that can accessed.

Accessing Camera Properties Over USB

$ ptpcam -p Listing properties... Camera: RICOH THETA S 0x5001: Battery Level 0x5002: Functional Mode 0x5003: Image Size 0x5011: Date Time 0x5012: Pre-Capture Delay 0xd407: UNKNOWN 0x5005: White Balance 0x500e: Exposure Program Mode 0x500f: Exposure Index (film speed ISO) 0x5010: Exposure Bias Compensation 0x5013: Still Capture Mode 0x501a: Timelapse Number 0x501b: Timelapse Interval 0x502c: UNKNOWN ....

Let’s check if I have battery.

$ ptpcam --show-property=0x5001 Camera: RICOH THETA S 'Battery Level' is set to: 100

It’s plugged into USB, so it makes sense that my battery is at 100%.

Next, I’ll check the image size:

$ ptpcam --show-property=0x5003 Camera: RICOH THETA S 'Image Size' is set to: "5376x2688"

I’ll check the time:

$ ptpcam --show-property=0x5011 Camera: RICOH THETA S 'Date Time' is set to: "20160701T142845-0700"

Check Capture Mode

$ ptpcam --show-property=0x5013 Camera: RICOH THETA S 'Still Capture Mode' is set to: [Normal]

Set Capture Mode to Video

Using the RICOH v2 USB documentation, you can find that video shooting corresponds to 0x8002 .

$ ptpcam --set-property=0x5013 --val=0x8002 Camera: RICOH THETA S 'Still Capture Mode' is set to: [Normal] Changing property value to 0x8002 [(null)] succeeded.

Verify that the change was saved:

craig@linux-silver:~$ ptpcam --show-property=0x5013 Camera: RICOH THETA S 'Still Capture Mode' is set to: 0x8002 (-32766)

The blue light on the THETA now shows a video icon.

At this stage, I boiled a pot of tea and left the camera on. When I came back, it had turned off.

I verified that the battery was still at 100%.

$ ptpcam --show-property=0x5013 Camera: RICOH THETA S 'Still Capture Mode' is set to: 0x8002 (-32766) craig@linux-silver:~$ ptpcam --show-property=0x5001 Camera: RICOH THETA S 'Battery Level' is set to: 100

I then looked at the sleepDelay

craig@linux-silver:~$ ptpcam --show-property=0xd803 Camera: RICOH THETA S 'UNKNOWN' is set to: 600

The sleepDelay is set to 600 seconds, or 10 minutes. I’m going to turn it off.

$ ptpcam --set-property=0xd803 --val=0 Camera: RICOH THETA S 'UNKNOWN' is set to: 600 Changing property value to 0 [(null)] succeeded.

Now, hopefully, the THETA will stay on indefinitely, powered by the USB and I’ll be able to use it in an industrial application such as security surveillance.

List the files on your THETA.

$ ptpcam -L Listing files... Camera: RICOH THETA S Handler: Size: Captured: name: 0x0064026e: 4000851 2016-06-03 21:11 R0010622.JPG 0x0064026f: 3953884 2016-06-09 22:52 R0010623.JPG 0x00640270: 3923907 2016-06-10 00:22 R0010624.JPG

Download the first file from the camera to your local computer.

$ ptpcam --get-file=0x0064026e Camera: RICOH THETA S Saving file: "R0010622.JPG" is done.

Boom! It’s super fast.

You can look at the image in your Linux file browser just to verify that the image was downloaded. In this picture, I have the THETA lying on it’s side on my desk.

It’s not a very nice picture, so I’ll delete it.

$ ptpcam --delete-object=0x0064026e Object 0x0064026e (R0010622.JPG) deleted.

I’m going to attempt to take another shot with my camera in a tripod. First, I’ll set the mode to still image as I set it to video earlier.

$ ptpcam --set-property=0x5013 --val=0x0001 Camera: RICOH THETA S 'Still Capture Mode' is set to: 0x8002 (-32766) Changing property value to 0x0001 [(null)] succeeded.

Then, I take the image.

$ ptpcam -c Initiating captue...

List the files on the camera:

$ ptpcam -L Listing files... Camera: RICOH THETA S Handler: Size: Captured: name: .... 0x0064027e: 3930938 2016-07-01 23:22 R0010638.JPG

Download the file to my local computer

$ ptpcam --get-file=0x0064027e Camera: RICOH THETA S Saving file: "R0010638.JPG" is done.

Verify that the download worked.

You can now see my boss Antec case for my overclocked system and the top of my overclocked and watercooled Linux test rig decorated with rainbow tape by my daughter.

I then checked the battery to verify that the THETA can last indefinitely connected with USB:

$ ptpcam --show-property=0x5001 Camera: RICOH THETA S 'Battery Level' is set to: 100

The camera still turned off. I’m going to connect with the WiFi USB to set the offDelay.

As I have two network interfaces in my computer, I can access the THETA over WiFi while I am connected to the Internet. Once I connect to the THETA, I use DHC to easily set the options. DHC is simply a tool to send, save, and organize HTTP requests. As I test the THETA frequently. I find it convenient to save the HTTP POST commands in DHC.

If the image is difficult to see, the relevant POST body is

{"name": "camera.setOptions", "parameters": { "sessionId": "SID_0001", "options": { "offDelay": 65535 } } }

You can check the offDelay parameter with this:

{"name": "camera.getOptions", "parameters": { "sessionId": "SID_0001", "optionNames": [ "offDelay" ] } }

Again, I have this template saved in DHC, so it’s easy for me to just change the optionNames .

I’m hopeful that the THETA will now stay on forever. At this point, it’s been on for an hour and I can send it API commands. So, it’s in a good state for surveillance or mapping. I can’t switch it to livestreaming mode. Also, the video is a bit problematic.

Using Raw PTP Commands

Grabbing Info

Pass the raw ptp command of GetDeviceInfo as a hex string, 0x1001

craig@linux-silver:$ ptpcam -R 0x1001 Camera: RICOH THETA S Sending generic request: reqCode=0x1001, params=[0x00000000,0x00000000,0x00000000,0x00000000,0x00000000] 64 00 06 00 00 00 6e 00 00 01 80 1a 00 00 00 01 - d.....n......... 10 02 10 03 10 04 10 05 10 06 10 07 10 08 10 09 - ................ 10 0a 10 0b 10 14 10 15 10 1b 10 01 90 91 99 99 - ................ 99 9a 99 9b 99 9c 99 9d 99 0e 10 16 10 1c 10 18 - ................ 10 a2 99 06 00 00 00 02 40 06 40 08 40 0a 40 0c - ........@.@.@.@. 40 0d 40 1d 00 00 00 01 50 02 50 03 50 11 50 12 - @.@.....P.P.P.P. 50 07 d4 05 50 0e 50 0f 50 10 50 13 50 1a 50 1b - P...P.P.P.P.P.P. 50 2c 50 06 d0 0f d0 01 d8 02 d8 03 d8 05 d8 06 - P,P............. d8 07 d8 08 d8 09 d8 0a d8 0b d8 0c d8 0d d8 0e - ................ d8 00 00 00 00 04 00 00 00 01 30 01 38 02 b8 82 - ..........0.8... b9 14 52 00 69 00 63 00 6f 00 68 00 20 00 43 00 - ..R.i.c.o.h. .C. 6f 00 6d 00 70 00 61 00 6e 00 79 00 2c 00 20 00 - o.m.p.a.n.y.,. . 4c 00 74 00 64 00 2e 00 00 00 0e 52 00 49 00 43 - L.t.d......R.I.C 00 4f 00 48 00 20 00 54 00 48 00 45 00 54 00 41 - .O.H. .T.H.E.T.A 00 20 00 53 00 00 00 06 30 00 31 00 2e 00 34 00 - . .S....0.1...4. 32 00 00 00 09 30 00 30 00 30 00 31 00 30 00 30 - 2....0.0.0.1.0.0 00 39 00 33 00 00 00 00 - .9.3.... PTP: response OK

Checking Battery Status

0x1015 is GetDevicePropValue. The property battery is 0x5001 . The result is a number between 0 and 100. I get 64 in hex which corresponds to a decimal value of 100. My battery charge is 100%.

craig@linux-silver:$ ptpcam -R 0x1015,0x5001 Camera: RICOH THETA S Sending generic request: reqCode=0x1015, params=[0x00005001,0x00000000,0x00000000,0x00000000,0x00000000] 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 - d............... 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 - ................ 00 00 00 00 00 00 00 00 - ........ PTP: response OK

Getting Size of Still Image

In this example, I look for the property ImageSize which is 0x5003 . Just to refresh from the previous example, 0x1015 is GetDevicePropValue. In the right column, you can see that the image size is 5376x2688