Schemas
JSON Schema definitions ของ EcuData, RidePoint, Ride — ใช้ validate payloads ของ ESP32 dongle ของคุณเอง หรือ generate TypeScript types อัตโนมัติ
GET /v1/schemas
Example
curl "https://api.smongrot.com/v1/schemas" \
-H "Authorization: Bearer sk_live_..."
Returns:
{
"data": {
"EcuData": { "$schema": "https://json-schema.org/...", ... },
"RidePoint": { "$schema": "...", ... },
"Ride": { "$schema": "...", ... }
}
}
Use cases
1. Validate ESP32 payload
ถ้าสร้าง dongle เอง — ใช้ schema เช็คว่าส่ง data ถูก format:
import Ajv from "ajv";
import addFormats from "ajv-formats";
const ajv = new Ajv();
addFormats(ajv);
const schemas = await fetch("https://api.smongrot.com/v1/schemas", {
headers: { Authorization: `Bearer ${KEY}` },
}).then(r => r.json()).then(x => x.data);
const validate = ajv.compile(schemas.EcuData);
const payload = {
rpm: 4200,
tps: 45.2,
timestamp: new Date().toISOString(),
};
if (!validate(payload)) console.error(validate.errors);
2. Generate TypeScript types
ใช้ json-schema-to-typescript:
npx json-schema-to-typescript -i schemas.json -o types.ts
Or with openapi-typescript if you want the same:
export interface EcuData {
rpm?: number;
tps?: number;
ect?: number;
timestamp: string; // ISO 8601
// ...
}
Schemas overview
EcuData
Live sensor snapshot — 1 record ต่อ tick (100ms หรือถี่กว่านั้น)
| Field | Type | หน่วย |
|---|---|---|
rpm | integer | rpm |
tps | number | % (0-100) |
ect | number | °C |
iat | number | °C |
map_pressure | number | kPa |
battery_v | number | V |
speed | integer | km/h |
afr | number | ratio |
injector_ms | number | ms |
ignition_deg | number | ° BTDC |
timestamp | string | ISO 8601 UTC |
RidePoint
Time-series data ของ ride — extend EcuData ด้วย GPS
Extra fields: seq, lat, lng, altitude, accuracy, gps_speed_kmh
Ride
Ride summary — 1 record ต่อการขี่ครั้ง
Fields: id, bike_id, started_at, ended_at, duration_sec, distance_km, avg_speed_kmh, max_speed_kmh, avg_rpm, max_rpm, max_ect, start_lat, start_lng, end_lat, end_lng, route_polyline, rpm_zones