Measurement API documentation - mercury-telemetry/mercury-telemetry GitHub Wiki

Measurement

This is a Django REST API supporting user to send POST request sending new measurement data to the backend.

  • URL

      /measurement/<uuid:event_uuid>
    
  • Method:

    POST

  • Data Params

    JSON messages carrying sensor data will have the following format:

{
  "sensor_id": << sensor id number >>,
  "values": {
    "value_x" : << some value >>,
    "value_y" : << some value >>,
    "value_z" : << some value >>
  }
  "date" : << ISO 8601 date/time >>
}
  • Success Response:

    • Code: 201
    • Content:
    {
        "measurement_timestamp": << ISO 8601 date/time >>,
        "measurement_sensor": << sensor id number >>,
        "measurement_event": << event uuid >>,
        "measurement_value": << json string for value field>>
    }
    
  • Error Response:

    • Code: HTTP_400_BAD_REQUEST
      Content: { error : "Missing enable value in url" }

    • Code: HTTP_404_NOT_FOUND
      Content(Invalid event uuid): { error : "Event uuid not found" }

      Content(Fail to save new model):

      {
        "measurement_sensor":["Invalid pk \\"1\\" - object does not exist."],
        "measurement_event":["Invalid pk \\"d81cac8d-26e1-4983-a942-1922e54a943d\\" - object does not exist."]
      }
      
    • Code: 415 Unsupported Media Type

      Reason(Wrong request content datatype): Raised if there are no parsers that can handle the content type of the request data when accessing request.data. In our project, Django Rest Framework includes JSONParser by default. So when you pass the request to Django Rest Framework API, you should make sure the overload of your request should be application/json format, just like what we showed above.

By default this exception results in a response with the HTTP status code "415 Unsupported Media Type".

  • Example url and response

    Example url

     https://localhost:8000/measurement/d81cac8d-26e1-4983-a942-1922e54a943d?
    

    Example json body

    {
       "sensor_id": 1,
       "values": {
         "power" : "1.0",
         "speed" : "2.0"
       }
       "date" : "2020-03-11T20:20+01:00"
    }
    

    Example response

     {
         "measurement_timestamp": "2020-03-11T19:20:00",
         "measurement_sensor": 1,
         "measurement_event": "d81cac8d-26e1-4983-a942-1922e54a943d",
         "measurement_value": "{\"power\":\"1.0\",\"speed\":\"2.0\"}"
     }
    
⚠️ **GitHub.com Fallback** ⚠️