Skip to content

Commit

Permalink
complete wifi add/del funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
arcolife committed Jan 5, 2020
1 parent 6faf448 commit 021816c
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 24 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,20 @@ If you have already registered on macOS, the Digital Paper app stores the files
* Currently there is no caching, therefore operations can be slow as they require uploading or downloading from the
device. However, this avoids having to resolve conflicts if a document has been changed both on the Digital Paper and
the caching directory.

## Usage

If paired over bluetooth, use `172.25.47.1` (double check IP from bluetooth connection network access point)

Else, over Wifi:

```
# Try multiple times
dptrp1 --addr 192.168.0.107 register
dptrp1 --addr 192.168.0.107 list-folders
dptrp1 --addr 192.168.0.107 wifi-add ./samples/wifi_2.5G.json
dptrp1 --addr 192.168.0.107 wifi-del ./samples/wifi_del_2.5G.json
```
Empty file modified dptrp1/cli/dptmount.py
100755 → 100644
Empty file.
55 changes: 35 additions & 20 deletions dptrp1/cli/dptrp1.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,38 @@ def do_wifi_enable(d):
def do_wifi_disable(d):
print(d.disable_wifi())

def do_add_wifi(d):
print(d.configure_wifi(ssid = "vecna2",
security = "psk",
passwd = "elijah is a cat",
dhcp = "true",
static_address = "",
gateway = "",
network_mask = "",
dns1 = "",
dns2 = "",
proxy = "false"))

def do_delete_wifi(d):
print(d.delete_wifi(ssid = "vecna2", security = "psk"))
def do_add_wifi(d, cfg_file=''):
try:
cfg = json.load(open(cfg_file))
except JSONDecodeError:
quit("JSONDecodeError: Check the contents of %s" % cfg_file)
except FileNotFoundError:
quit("File Not Found: %s" % cfg_file)
if not cfg:
print(d.configure_wifi(ssid = "vecna2",
security = "psk",
passwd = "elijah is a cat",
dhcp = "true",
static_address = "",
gateway = "",
network_mask = "",
dns1 = "",
dns2 = "",
proxy = "false"))
else:
print(d.configure_wifi(**cfg))

def do_delete_wifi(d, cfg_file=''):
try:
cfg = json.load(open(cfg_file))
except ValueError:
quit("JSONDecodeError: Check the contents of %s" % cfg_file)
except FileNotFoundError:
quit("File Not Found: %s" % cfg_file)
if not cfg:
print(d.delete_wifi(ssid = "vecna2", security = "psk"))
else:
print(d.delete_wifi(**cfg))

def do_register(d, key_file, id_file):
_, key, device_id = d.register()
Expand Down Expand Up @@ -184,11 +202,11 @@ def main():
dp = DigitalPaper(addr=args.addr, id=args.serial)
if args.command == "register":
# When registering the device, we default to storing auth files in our own configuration directory
default_deviceid, default_privatekey = get_default_auth_files()
default_deviceid, default_privatekey = get_default_auth_files()
do_register(dp, args.key or default_privatekey, args.client_id or default_deviceid)
return
# When connecting to a device, we default to looking for auth files in

# When connecting to a device, we default to looking for auth files in
# both our own configuration directory and in Sony's paths
found_deviceid, found_privatekey = find_auth_files()
if not args.key:
Expand All @@ -212,6 +230,3 @@ def main():

if __name__ == "__main__":
main()



8 changes: 4 additions & 4 deletions dptrp1/dptrp1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/local/bin/python3
#!/usr/bin/env python3
import os
import sys
import uuid
Expand Down Expand Up @@ -29,13 +29,13 @@ def get_default_auth_files():
os.makedirs(config_path, exist_ok=True)
deviceid = os.path.join(config_path, "deviceid.dat")
privatekey = os.path.join(config_path, "privatekey.dat")

return deviceid, privatekey

def find_auth_files():
"""Search for authentication files for connecting to DPT-RP1, both in default path and in paths from Sony's Digital Paper App"""
deviceid, privatekey = get_default_auth_files()

if not os.path.exists(deviceid) or not os.path.exists(privatekey):
# Could not find our own auth-files. Let's see if we can find any auth files created by Sony's Digital Paper App
search_paths = [
Expand All @@ -49,7 +49,7 @@ def find_auth_files():
privatekey_matches = glob(os.path.join(path, "**/privatekey.dat"), recursive=True)

if deviceid_matches and privatekey_matches:
# Found a match. Selecting the first file from each for now.
# Found a match. Selecting the first file from each for now.
# This might not be correct if the user has several devices with their own keys. Should ideally be configurable
deviceid = deviceid_matches[0]
privatekey = privatekey_matches[0]
Expand Down
12 changes: 12 additions & 0 deletions samples/wifi_2.5G.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"security": "psk",
"ssid": "Roxy123",
"passwd": "Lucinda",
"dhcp": "true",
"static_address": "",
"gateway": "",
"network_mask": "",
"dns1": "",
"dns2": "",
"proxy": "false"
}
12 changes: 12 additions & 0 deletions samples/wifi_5G.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"security": "psk",
"ssid": "BadBomb",
"passwd": "TickingLikeAHotSamosa",
"dhcp": "true",
"static_address": "",
"gateway": "",
"network_mask": "",
"dns1": "",
"dns2": "",
"proxy": "false"
}
4 changes: 4 additions & 0 deletions samples/wifi_del_2.5G.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"security": "psk",
"ssid": "Roxy123"
}

0 comments on commit 021816c

Please sign in to comment.