API & Data · Lesson 16 of 17
Logging Sensor Data
In this tutorial, we will cover the steps to POST your sensor data via the Leftover Labs API so you can visualise them and collect them in a graph.
If you haven’t set up your account and created a Graph and Dataset yet, you can do so by following this guide here.
API Endpoint [API Schema]
The Leftover Labs API endpoint to post sensor data is:
https://api.leftoverlabs.com/graph/data/create/
Required Headers
Ensure you include the following headers in your POST request:
Content-Type: application/jsonapi-key: YOUR_API_CREDENTIALS_KEYdataset-id: YOUR_DATASET_ID
Request Payload
Your request should include the following JSON payload:
{
"sensor_value": "10"
}
You can also include an optional timestamp to specify when the data was collected. If not provided, the current time will be used.
{
"sensor_value": "10",
"timestamp": "2023-07-15T14:30:00Z"
}
Timestamp Format
The timestamp should be in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
Format Components:
YYYY: Four-digit yearMM: Two-digit monthDD: Two-digit dayT: Separator between date and timeHH: Two-digit hour (24-hour format)MM: Two-digit minuteSS: Two-digit secondZ: UTC timezone indicator
Example Implementation
Here is an example Python code snippet to help you POST your sensor data: