Authorization and Configuration

FLUX Device use password and RSA key to authorizing access. At the first time a user connect to device, a RSA key and password is required. After the password is authorized, you can insert your RSA key into device trusted key list.

Note

Note: You must add your RSA Key to device trusted list because robot and camera service does not accept password authorize.

Authorize with password

When create a UpnpTask instance, call fluxclient.upnp.task.UpnpTask.authorized() to ensure your connection grant permission to operation. If authorized return False, you have to call fluxclient.upnp.task.UpnpTask.authorize_with_password() to complete authorize.:

upnptask = UpnpTask(uuid)
if upnptask.authorized:
    pass  # authorized

else:
    password = getpass("Password: ")
    try:
        upnptask.authorize_with_password(password)
        print("Authorized")
    except UpnpError as e:
        print("Authorize failed: %s" % e)
        raise

Manage device name, network and security

class fluxclient.upnp.task.UpnpTask(uuid, client_key, ipaddr=None, device_metadata=None, remote_profile=None, backend_options={}, lookup_callback=None, lookup_timeout=inf)

UpnpTask provides some configuration methods for the device. When creating a UpnpTask instance, the argument uuid is required. If parameter device_metadata is not given, UpnpTask will use lookup_callback and lookup_timeout to create a UpnpDiscover instance and try to get metadata from network.

Parameters:
  • uuid (uuid.UUID) – Device uuid, set UUID(int=0) while trying to connect via ip address.
  • client_key (encrypt.KeyObject) – Client key to connect to device.
  • ipaddr (str) – IP Address of the machine.
  • device_metadata (dict) – This is an internal parameter, which is not recommended to provide because it may has different definitions in different versions.
  • backend_options (dict) – More configuration for UpnpTask.
  • lookup_callback (callable) – Invoke repeatedly while looking for device.
  • lookup_timeout (float) – Raise an error if the program can not find the device in a limited time.
Raises:
  • UpnpError – For protocol or operation error.
  • socket.error – For system defined socket error.
close()

Closes the upnp socket connection. After close(), any other method should not be called anymore.

authorized

Indicates whether the connection has been authorized with a correct password or RSA key. If the connection is not authorized, you must call authorize_with_password first to authorize.

connected

Indicates whether the upnp connection is connected with the device

authorize_with_password(password)

Authorizes via password, only use when the RSA key has not been trusted from device.

Parameters:password (str) – Device password
add_trust(label, key)

Adds a client_key to device trust list

Parameters:
  • label (str) – Key label will show for human only
  • key (object) – A vaild RSA key object or pem
Returns:

Key hash

Return type:

str

list_trust()

Gets all trusted key in the device

Returns:((label, key hash), (label, key hash), ...)
remove_trust(access_id)

Removes a trusted key

Parameters:access_id (str) – Key hash which will be removed
rename(new_name)

Renames the device

Parameters:new_name (str) – New device name
modify_password(old_password, new_password, reset_acl=True)

Changes the device password, if reset_acl set to True, all other authorized user will be deauthorized.

Parameters:
  • old_password (str) – Old device password
  • new_password (str) – New device password
  • reset_acl (bool) – Clear authorized user list in device
modify_network(**settings)

Modifies the device network, details will be revealed in future documentation.

get_wifi_list()

Gets wifi lists discovered from the device

Network config settings

key value example Describe
method (“static”|”dhcp”)  
     
Only required when *method*=”static”
ipaddr “192.168.1.2” Device ip address (IPv4, str)
mask 24 Network mask, int
route “192.168.1.1” Default gateway
ns [“8.8.8.8”] DNS, a list of IPv4 address, str
     
Only required when config a wifi device
wifi_mode (“host”|”client”)  
ssid “A valid SSID” A valid ssid to join or hosted
security (None, “WEP”, “WPA2-PSK”) Wifi security, None if no security
     
Only required when wifi security=”WEP”
wepkey “PASSWORD” WEP security password
     
Only required when wifi security=”WPA2-PSK”
psk “PASSWORD” WPA-PSK security password

Error Handling

class fluxclient.upnp.task.UpnpError(*args, **kw)

When a request can not be processed, UpnpError will be raised

class fluxclient.upnp.task.UpnpException(*args, **kw)

When upnp session got a fatel error, UpnpException will be raised and the UpnpTask instance should be closed and can not be used anymore.