Skip to content

Instantly share code, notes, and snippets.

@lancechentw
Last active March 20, 2026 01:09
Show Gist options
  • Select an option

  • Save lancechentw/96ce1cbe0483f5dea706b79fccc51923 to your computer and use it in GitHub Desktop.

Select an option

Save lancechentw/96ce1cbe0483f5dea706b79fccc51923 to your computer and use it in GitHub Desktop.
farm observations upload api sample
curl -X POST "https://api.example.com/upload" \
-H "Content-Type: application/json" \
--data-raw '{
"token": "35b15075d577cf2f0af0249a9c35dd72e19a89f8",
"datetime": "2026-03-20T10:30:00+08:00",
"temperature": {
"value": 26.4,
"unit": "°C",
"ObsTime": "2026-03-20T10:25:00+08:00"
},
"relative_humidity": {
"value": 71.2,
"unit": "%",
"ObsTime": "2026-03-20T10:25:00+08:00"
},
"solar_irradiance": {
"value": 523.8,
"unit": "lux",
"ObsTime": "2026-03-20T10:25:00+08:00"
},
"rainfall": {
"value": null,
"unit": null,
"ObsTime": "2026-03-20T10:30:00+08:00"
},
"wind_speed": {
"value": null,
"unit": null,
"ObsTime": "2026-03-20T10:30:00+08:00"
},
"wind_direction": {
"value": null,
"unit": null,
"ObsTime": "2026-03-20T10:30:00+08:00"
}
}'
openapi: 3.0.3
info:
title: Farm Observations Upload API
version: 1.0.0
description: >
This endpoint uploads the latest device sensor readings.
servers:
- url: https://api.example.com
paths:
/upload:
post:
summary: Upload sensor observations
operationId: uploadSensorObservations
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UploadPayload'
examples:
sample:
summary: Sample upload payload
value:
token: 35b15075d577cf2f0af0249a9c35dd72e19a89f8
datetime: '2026-03-20T10:30:00+08:00'
temperature:
value: 26.4
unit: '°C'
ObsTime: '2026-03-20T10:25:00+08:00'
relative_humidity:
value: 71.2
unit: '%'
ObsTime: '2026-03-20T10:25:00+08:00'
solar_irradiance:
value: 523.8
unit: lux
ObsTime: '2026-03-20T10:25:00+08:00'
rainfall:
value: null
unit: null
ObsTime: '2026-03-20T10:30:00+08:00'
wind_speed:
value: null
unit: null
ObsTime: '2026-03-20T10:30:00+08:00'
wind_direction:
value: null
unit: null
ObsTime: '2026-03-20T10:30:00+08:00'
responses:
'200':
description: Successful response, expected to be JSON
content:
application/json:
schema:
type: object
additionalProperties: true
default:
description: Non-JSON or error response
content:
application/json:
schema:
type: object
additionalProperties: true
components:
schemas:
Observation:
type: object
properties:
value:
type: number
nullable: true
example: 26.4
unit:
type: string
nullable: true
example: '°C'
ObsTime:
type: string
format: date-time
example: '2026-03-20T10:25:00+08:00'
required:
- value
- unit
- ObsTime
UploadPayload:
type: object
properties:
token:
type: string
description: Device-specific token
datetime:
type: string
format: date-time
description: Payload generation time
temperature:
$ref: '#/components/schemas/Observation'
relative_humidity:
$ref: '#/components/schemas/Observation'
solar_irradiance:
$ref: '#/components/schemas/Observation'
rainfall:
$ref: '#/components/schemas/Observation'
wind_speed:
$ref: '#/components/schemas/Observation'
wind_direction:
$ref: '#/components/schemas/Observation'
required:
- token
- datetime
- temperature
- relative_humidity
- solar_irradiance
- rainfall
- wind_speed
- wind_direction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment