4.2. Captures

class backendapp.captures.models.Capture(tag_id, timestamp, loopcount, format, batvoltagemv, cursorpos, timeintmins, hash, status, samples=[], id=None)[source]

A cuplTag is read by an NFC reader (such as a phone). Encoded data are stored within URL parameters, as part of an NDEF URL record.

Parameters are decoded by the API within this application.

The resultant data (a list of timestamped temperature+humidity samples and status information) are stored inside the database as a Capture.

No two captures for a given tag can have the same MD5 or HMAC checksum. A database constraint guarantees this. Identical captures would otherwise occur for 3 reasons:

  1. Insufficient time between reads.

  2. The device has run out of battery.

  3. An attacker intends to fill up the database.

The constraint produces an error message, which is fed back to the frontend web application with the API.

__init__(tag_id, timestamp, loopcount, format, batvoltagemv, cursorpos, timeintmins, hash, status, samples=[], id=None)

Create a new instance of the Capture model.

Stores the output from cuplCodec.

Parameters
  • tag_id – ID of the Tag read to make this capture.

  • timestamp – Datetime object for when the capture was decoded. The timezone should be UTC.

  • loopcount – Number of times the circular buffer cursor has wrapped around from the end to the start.

  • format – Indicates how to decode parameters in the cupl URL.

  • batvoltagemv – Voltage in milliVolts of the battery powering cuplTag.

  • cursorpos – Position of the circular buffer cursor relative to the start of the string.

  • timeintmins – Time interval between samples in minutes.

  • hash – MD5 or HMAC of Capture data.

  • status – Reference to a CaptureStatus object.

  • samples – A list of CaptureSamples objects.

  • id – ID of this capture.

tagserial

Return a serial string for the Tag that data has been read.

class backendapp.captures.models.CaptureSample(timestamp, temp, rh=None, location=None)[source]

A timestamped environmental sensor sample. Includes temperature (required) and humidity (optional).

The timestamp is stored as a datetime object and converted to an integer (the POSIX timestamp). The latter is the number of seconds since the 1st January 1970. Some SQL window functions (lag and lead) only operate on integers.

__init__(timestamp, temp, rh=None, location=None)

Create a new sample instance.

Parameters
  • timestamp – The time the sample was recorded, estimated to the nearest minute by this application.

  • temp – Temperature in degrees C.

  • rh – Relative humidity in percent.

  • location – Unused.

class backendapp.captures.models.CaptureStatus(resetsalltime, brownout, clockfail, lpm5wakeup, misc, supervisor, watchdog)[source]

Status information for the cuplTag device.

Includes the number of resets since the tag was programmed and the cause of the most recent reset.

__init__(resetsalltime, brownout, clockfail, lpm5wakeup, misc, supervisor, watchdog)

Create a new instance of the CaptureStatus model.

This stores information from the MSP430 on cuplTag.

Parameters
  • resetsalltime – The number of times the MSP430 has reset for any reason.

  • brownout – True if the most recent reset was caused by a brownout condition.

  • clockfail – True if a clock failure has occurred.

  • lpm5wakeup – True if the MSP430 has woken up from low power mode LPMx.5. This is normal, not an error.

  • misc – True if the MSP430 reset cause is miscellaneous.

  • supervisor – True if the MSP430 Supply Voltage Supervisor has triggered a reset. Implies a low battery.

  • watchdog – True if the MSP430 watchdog has timed out. Indicative of a firmware bug or hardware failure.