Skip to content

Latest commit

 

History

History
172 lines (118 loc) · 3.41 KB

uploaddatapoint.md

File metadata and controls

172 lines (118 loc) · 3.41 KB

uploadDataPoint

Description

Use HTTPs POST to upload data points

Request URL

https://api.mediatek.com/mcs/v2/devices/:deviceId/datapoints

The API will by default assume the json format, if you want to use the csv, please add.csv at the end of the Request URL.

Action

HTTPs POST

Parameters

Header

Token

For Devices

deviceKey: `device_key_here`

For Users

Authorization: Bearer `{token}`

Content Type

For JSON format:

Content-Type:`application/json`

For Comma Separated Value (CSV) format:

Content-Type:`text/csv`

Body

For CSV format:

Syntax:

:Data_Channel_Id_1, :Timestamp, :Value_1, :Value_2, :Value_3\n

:Data_Channel_Id_2, :Timestamp, :Value_1\n

For more detail about the format of each data channel teyp, please reference the link here.

Note: Leave :Timestamp field empty (but keep the commas) if device does not wish to generate its own timestamp, the timestamp will be generated by MCS upon receiving this datapoint.

Example:

1,946684800,26
2,,26.34,12,59

Line 1: Data Channel Id = 1, with a given timestamp, 26 is the value of this datapoint (in this case the data type pre-defined as integer)

Line 2: Data Channel Id = 2, with no given timestamp (therefore MCS will generate, 26.34 is the value of this data point (in this case the data type pre-defined as float)

For JSON format

Syntax:

Each JSON representation of a datapoint is wrap around with

dataChnId, timestamp, values

Values is the context of the datapoint value, for most cases represented by one entity. Some other cases, like GPS, will be represented as three key values.

{
   "datapoints":[
      {
         "dataChnId":"1",
         "timestamp":946684800,
         "values":{
            "value":"26"
         }
      },
      {
         "dataChnId":"2",
         "timestamp":946684800,
         "values":{
            "latitude":"26.34",
            "longitude":"12",
            "altitude":"59"
         }
      }
   ]
}

Item 1: Data Channel Id = 1, with a given timestamp, 26 is the value of this datapoint (in this case the data type pre-defined as integer)

Item 2: Data Channel Id = 2, with no given timestamp (therefore MCS will generate, 26.34 is the value of this data point (in this case the data type pre-defined as float)

Please note, the unix time is in milliseconds, for human readable time conversion, please refer to http://www.epochconverter.com/

Response

Response Code

200

Response Header

Content-Type:application/json

Response Body

Example:

Request URL

https://api.mediatek.com/mcs/v2/devices/d1234567890/datapoints

Request Body

1,946684800,26
2,,26.34,12,59

Response Body

{
  "apiVersion": "0.0.1",
  "code": 200,
  "message": "Request has succeeded",
  "results": "Success."
}

Error Response

When error is incurred, the response code will be non-200 and the response body will construct in JSON format with the following fields:

Field Name Type Description
code Integer Error Code
url String url to API Error detail page
description String Error Description

Example:

{
  "apiVersion": "0.0.1",
  "code": 200,
  "message": "Request has succeeded",
  "results": "Partial success.",
  "descriptions": [
    "The uploaded data point for data channel gps exceeds the bound of longitude in GPS"
  ]
}