4.1. Tags

class backendapp.tags.models.Tag(serial=None, secretkey=None, usehmac=True, fwversion='', hwversion='', description='', **kwargs)[source]

Each Tag instance represents one cuplTag device.

Columns fall into the categories below.

These scalars must be copied to a cuplTag (by serial or NFC):

Tags are identified with an 8-character alphanumeric serial string.

A secret key is used for authentication. This string is stored only in this table and on the tag itself. Authentication is enabled with usehmac. When disabled, the secret key is ignored.

These scalars can be populated by read from the programmed cuplTag:

Tag firmware and hardware versions. These are not otherwise used by this software.

The remainder are for information only:

The time registered column stores the date and time an instance was created.

Description can be populated by the end-user, with strings such as “in the downstairs bathroom”.

Each Tag contains a list of captures and webhooks.

__init__(serial=None, secretkey=None, usehmac=True, fwversion='', hwversion='', description='', **kwargs)

Create a new instance of the Tag model.

All parameters are optional. The serial and secret key strings are automatically generated when not supplied.

Parameters
  • serial – An URL-safe string of length SERIAL_LEN_BYTES, which uniquely identifies a tag.

  • secretkey – An URL-safe string of length SECKEY_LEN_BYTES, used for tag authentication.

  • usehmac – When true (default), the checksum received from a tag is assumed to be a Hash-Based Message Authentication Code. Captures are verified with knowledge of the secret key. When false, the checksum is a (weak) MD5 message integrity check only.

  • fwversion – Tag firmware version string (e.g. F1.5_C2_HT07)

  • hwversion – Tag hardware version string (e.g. HT07)

  • description – A user-editable description of the tag, which normally pertains to location.

  • kwargs

static gen_secret_key() str[source]

Generate a random secret key, containing 16 URL-safe base64 characters.

uniquesampleswindow(starttime: datetime.datetime, endtime: datetime.datetime)[source]

Return the set of samples collected from this tag within a time window. Duplicate samples are removed.

Consecutive captures, taken a short time apart, will contain a large number of duplicate samples. These have identical sensor readings, but slightly different timestamps. All samples are timestamped relative to that of the capture, which has a margin of error of +/- 1 minute.

This software does not use a time series database, so an algorithm had to be written.

Parameters
  • starttime – Start of the time window.

  • endtime – End of the time window.

Returns

A query on the CaptureSample table, bounded by the starttime and endtime.