habitat.views.payload_telemetry

Functions for the payload_telemetry design document.

Contains schema validation and a view by flight, payload and received time.

Functions

flight_payload_time_map(doc) View: payload_telemetry/flight_payload_time
payload_time_map(doc) View: payload_telemetry/payload_time
read_json_schema(schemaname)
rfc3339_to_timestamp Mock out external modules that might annoy documentation build systems.
validate(new, old, userctx, secobj) Validate this payload_telemetry document against the schema, then perform
validate_doc(data, schema) Validate data against schema, raising descriptive errors
version Mock out external modules that might annoy documentation build systems.

Exceptions

ForbiddenError Mock out external modules that might annoy documentation build systems.
UnauthorizedError Mock out external modules that might annoy documentation build systems.
habitat.views.payload_telemetry.flight_payload_time_map(doc)[source]

View: payload_telemetry/flight_payload_time

Emits:

[flight_id, payload_configuration_id, estimated_time_received] -> null

Useful to find telemetry related to a certain flight.

habitat.views.payload_telemetry.payload_time_map(doc)[source]

View: payload_telemetry/payload_time

Emits:

[payload_configuration_id, estimated_time_received] -> null

Useful to find telemetry related to a specific payload_configuration.

habitat.views.payload_telemetry.time_map(doc)[source]

View: payload_telemetry/time

Emits:

estimated_time_received -> is_flight_telemetry

Useful to get recent telemetry uploaded to habitat.

This can also be used to make a simple map application. It’s worth noting that such a technique is a bit of a bodge, since estimated_time_received will not necessarily (but could) update if another receiver is added to the doc, so asking this view for all telemetry since min(the last poll, the most recent telemetry I have) is not infallible. That said, doing a proper sync is quite difficult.

habitat.views.payload_telemetry.add_listener_update(doc, req)[source]

Update function: payload_telemetry/_update/add_listener

Given a prototype payload_telemetry JSON document in the request body, containing just the _raw telemetry string and one entry in receivers, create the document or merge this listener into it as appropriate.

Used by listeners when a new payload telemetry string has been received.

Usage:

PUT /habitat/_design/payload_telemetry/_update/add_listener/<doc ID>

{
    "data": {
        "_raw": "<base64 raw telemetry data>"
    },
    "receivers": {
        "<receiver callsign>": {
            "time_created": "<RFC3339 timestamp>",
            "time_uploaded": "<RFC3339 timestamp>",
            <other keys as desired, for instance
             latest_listener_telemetry, latest_listener_info, etc>
        }
    }
}

The document ID should be sha256(doc[“data”][“_raw”]) in hexadecimal.

Returns “OK” if everything was fine, otherwise CouchDB will raise an error. Errors might occur in validation (in which case the validation error is returned) or because of a save conflict. In the event of a save conflict, uploaders should retry the same request until the conflict is resolved.

habitat.views.payload_telemetry.http_post_update(doc, req)[source]

Update function: payload_telemetry/_update/http_post

Creates a new payload_telemetry document with all keys present in the HTTP POST form data available in doc.data._fallbacks and the from HTTP querystring key as the receiver callsign if available. The data field will be base64 encoded and used as doc.data._raw.

This function has additional functionality specific to RockBLOCKs: if all of the keys imei, momsn, transmit_time, iridium_latitude, iridium_longitude, iridium_cep and data are present in the form data, then: * imei will be copied to doc.data._fallbacks.payload so it can be

used as a payload callsign.
  • iridium_latitude and iridium_longitude will be copied to doc.data._fallbacks.latitude and longitude respectively.
  • data will be hex decoded before base64 encoding so it can be directly used by the binary parser module.
  • transmit_time will be decoded into an RFC3339 timestamp and used for the time_created field in the receiver section.
  • transmit_time will be decoded into hours, minutes and seconds and copied to doc.data._fallbacks.time.

Usage:

POST /habitat/_design/payload_telemetry/_update/http_post?from=callsign

data=hello&imei=whatever&so=forth

This update handler may not currently be used on existing documents or with a PUT request; such requests will fail.

Returns “OK” if everything was fine, otherwise CouchDB will return a (hopefully instructive) error.