📡

API Documentation

v1.0
📡

HTTP API Reference

Base URL: https://gps.aitalim.com

📤 POST /api/post_data.php

Send GPS + fuel data from ESP32 or simulator. Supports single and batch mode.

Single Record

{
  "device_id": "TRUCK_01",       // Required — unique device name
  "device_name": "Fuel Tanker",  // Optional — friendly name
  "device_type": "truck",        // Optional — category
  "latitude": 27.7172,           // GPS decimal degrees
  "longitude": 85.3240,
  "speed": 45.2,                 // km/h
  "altitude": 1350.0,            // meters ASL
  "satellites": 8,               // GPS satellite count
  "hdop": 1.2,                   // Precision indicator
  "fuel_level": 72.5,            // Percentage 0-100
  "fuel_voltage": 2.35,          // Raw sensor voltage
  "battery_voltage": 12.6,       // Battery volts
  "signal_strength": -67,        // dBm
  "timestamp": "2026-03-24 14:30:00"
}

Batch Mode (10 records at once)

{
  "device_id": "TRUCK_01",
  "data": [
    { "latitude": 27.7172, "longitude": 85.324, "speed": 45, "fuel_level": 72 },
    { "latitude": 27.7180, "longitude": 85.325, "speed": 42, "fuel_level": 71 },
    ...
  ]
}

Response

// Success (200)
{ "status": "ok", "inserted": 10, "total_sent": 10, "device_id": "TRUCK_01" }

// Partial failure (207)
{ "status": "partial", "inserted": 8, "errors": [...] }

// Error (400/500)
{ "status": "error", "message": "Missing required field: device_id" }

📋 GET /api/get_devices.php

Returns all registered devices with their latest data point.

// Response
{
  "status": "ok",
  "count": 3,
  "devices": [
    {
      "device_id": "TRUCK_01",
      "device_name": "Fuel Tanker #1",
      "last_seen": "2026-03-24 14:30:00",
      "latest": { "latitude": 27.7172, "longitude": 85.324, "fuel_level": 72 }
    }
  ]
}

📊 GET /api/get_data.php

Fetch GPS + fuel records for a specific device.

Query Parameters

ParameterRequiredDefaultDescription
device_id✅ YesDevice to fetch data for
limitNo200Max records (capped at 5000)
fromNoStart date: YYYY-MM-DD
toNoEnd date: YYYY-MM-DD
orderNodesc"asc" or "desc"

Example URLs

/api/get_data.php?device_id=TRUCK_01
/api/get_data.php?device_id=TRUCK_01&limit=50
/api/get_data.php?device_id=TRUCK_01&from=2026-03-20&to=2026-03-24
/api/get_data.php?device_id=TRUCK_01&order=asc&limit=1000

💻 curl Examples

Windows PowerShell

# Post single record
$body = '{"device_id":"TRUCK_01","latitude":27.7172,"longitude":85.324,"fuel_level":72.5}'
Invoke-WebRequest -Uri "https://gps.aitalim.com/api/post_data.php" -Method POST -ContentType "application/json" -Body $body

# Get all devices
(Invoke-WebRequest "https://gps.aitalim.com/api/get_devices.php").Content

# Get device data
(Invoke-WebRequest "https://gps.aitalim.com/api/get_data.php?device_id=TRUCK_01&limit=10").Content

Linux / Mac (bash)

# Post data
curl -X POST https://gps.aitalim.com/api/post_data.php \
  -H "Content-Type: application/json" \
  -d '{"device_id":"TRUCK_01","latitude":27.7172,"longitude":85.324,"fuel_level":72.5}'

# Get devices
curl https://gps.aitalim.com/api/get_devices.php

# Get data
curl "https://gps.aitalim.com/api/get_data.php?device_id=TRUCK_01&limit=10"

Windows CMD

curl.exe -X POST https://gps.aitalim.com/api/post_data.php -H "Content-Type: application/json" -d "{\"device_id\":\"TRUCK_01\",\"latitude\":27.7172}"

curl.exe https://gps.aitalim.com/api/get_devices.php

⚠️ Error Codes

CodeMeaningCommon Cause
400Bad RequestInvalid JSON, missing device_id, bad format
404Not FoundDevice has never sent data
405Method Not AllowedUsing GET on POST endpoint
500Server ErrorDatabase connection failure