longjie / dpt-rp1-py

Python script to manage Sony DPT-RP1 without Digital Paper App

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dpt-rp1-py

Python script to manage Sony DPT-RP1 without Digital Paper App. This repository includes a Python library and a command line utility to manage documents on the DTP-RP1. Tested on Windows, Linux, and macOS.

Install

To install the library run python3 setup.py install or pip3 install . from the root directory. To install as a developer use python3 setup.py develop (see the setuptools docs) and work on the source as usual.

Installing the package also installs the command line utility called dptrp1.

Using the command line utility

dptrp1 \
	--addr <DPT-RP1 hostname or IP address> \
	--client-id <client_id file> \
	--key <key file> \
	command [arguments]

The required files for the client ID and private key will be created when you first register the reader. The files can also be extracted from the original Digital Paper App.

Supported commands

You can get a list of the implemented commands by running dptrp1 with no additional arguments. Supported commands include register, list-documents, download , upload , new-folder , delete <remote_path>, wifi-list, wifi-scan, wifi-enable, and wifi-disable.

Registering the DPT-RP1

The DPT-RP1 uses SSL encryption to communicate with the computer. This requires registering the DPT-RP1 with the computer, which results in two pieces of information -- the client ID and the key file -- that you'll need to run the script. You can get this information in three ways.

Registering without the Digital Paper App

This method requires your DPT-RP1 and your computer to be on the same network segment via WiFi, Bluetooth or a USB connection. The USB connection works on Windows on macOS but may not work on a Linux machine. If you the USB connection does not work for you, perform the initial setup on a different PC to connect the reader to your WiFi network.

Second, find the DPT-RP1's IP address. If you're on WiFi, go to Wi-Fi Settings on the device and tap the connected network. If you're on Bluetooth, it's likely 172.25.47.1. You can also try the hostname digitalpaper.local.

Finally, use the register command, substituting the files you want the client ID and key written to, and the IP address of the device:

dptrp1 \
	--client-id <client_id file> \
	--key <key file> \
	--addr <address> \
	register

If you get an error, wait a few seconds and try again. Sometimes it takes two or three tries to work.

Finding the private key and client ID on Windows

If you have already registered on Windows, the Digital Paper app stores the files in Users/{username}/AppData/Roaming/Sony Corporation/Digital Paper App/. You'll need the files deviceid.dat and privatekey.dat.

Extracting the private key and client ID on macOS

You can also modify the Digital Paper App to write your files to the desktop.

First, download the Digital Paper App. I am going to use the macOS version here but the process should be similar on Windows as the Digital Paper App is just an Electron wrapper around some JavaScript code. You will need to manipulate the application to extract the client identifier (client_id) and the certificate that the application receives from the device upon pairing.

The main application logic resides in a file called app.asar, which can be found at /Applications/Digital Paper App.app/Contents/Resources/app.asar after the installation. Extract this archive to a folder called dpt on your desktop using the asar command line utility, which can be installed using homebrew and npm.

brew install npm
npm install --global asar
cd "/Applications/Digital Paper App.app/Contents/Resources"
asar e app.asar ~/Desktop/dpt 

Surprisingly, the application is nicely organised into different modules that even come with source code comments and readme files. Those modules can be found in node_modules/mw-* within the dpt folder. To extract the client_id and the certificate to handle communication with the DPT-RP1, make just one change in /node_modules/mw-auth-ctrl/authctrl.js by adding a few statements after line 189:

// console.log('attempt to put /auth');
// console.log(JSON.stringify(authInfo, null, "  "));
var fs = require('fs');
var os = require('os');
var certPath = os.homedir() + '/Desktop/key.pem';
var clientPath = os.homedir() + '/Desktop/client_id.txt';
fs.writeFileSync(certPath, data, 'utf-8');
fs.writeFileSync(clientPath, deviceId, 'utf-8');
console.log(data);
console.log(deviceId);

Then use the asar utility again to archive the changes and implement them into the Digital Paper App.

cd "/Applications/Digital Paper App.app"
sudo asar p ~/Desktop/dpt ./Contents/Resources/app.asar

Now run the Digital Paper App and it will create two files, client_id.txt and key.pem, on the desktop once the pairing is complete.

About

Python script to manage Sony DPT-RP1 without Digital Paper App


Languages

Language:Python 100.0%