Chuyển tới nội dung chính

Weather API

API lấy dữ liệu thời tiết hiện tại, dự báo và lịch sử.


Lấy thời tiết hiện tại

GET /api/v1/weather/current

Query Parameters:

ParamTypeRequiredDescription
stationIdstringNoID trạm cụ thể
citystringNoLọc theo thành phố

Response:

{
"data": [
{
"id": "urn:ngsi-ld:WeatherObserved:hanoi-01",
"type": "WeatherObserved",
"dateObserved": "2025-01-15T10:00:00Z",
"location": {
"type": "Point",
"coordinates": [105.8542, 21.0285]
},
"temperature": 25.5,
"humidity": 75,
"windSpeed": 12.5,
"windDirection": 180,
"precipitation": 0,
"atmosphericPressure": 1013,
"weatherType": "clear"
}
],
"source": "orion-ld",
"timestamp": "2025-01-15T10:05:00Z"
}

Dự báo thời tiết

GET /api/v1/weather/forecast

Query Parameters:

ParamTypeRequiredDescription
stationIdstringNoID trạm cụ thể

Response:

{
"data": [
{
"id": "urn:ngsi-ld:WeatherForecast:hanoi-01-2025-01-16",
"date": "2025-01-16",
"temperatureMin": 20,
"temperatureMax": 28,
"humidity": 70,
"precipitationProbability": 30,
"weatherType": "partly_cloudy"
}
],
"source": "orion-ld",
"timestamp": "2025-01-15T10:05:00Z"
}

Lịch sử thời tiết

GET /api/v1/weather/history

Query Parameters:

ParamTypeRequiredDescription
stationIdstringNoID trạm cụ thể
startDatestringNoNgày bắt đầu (ISO 8601)
endDatestringNoNgày kết thúc (ISO 8601)
pagenumberNoTrang (default: 1)
limitnumberNoSố record/trang (default: 50)

Response:

{
"data": [...],
"meta": {
"total": 1500,
"page": 1,
"limit": 50,
"totalPages": 30
}
}

Thời tiết theo trạm

GET /api/v1/weather/station/:stationId

Thời tiết theo tọa độ GPS

GET /api/v1/weather/nearby

Query Parameters:

ParamTypeRequiredDescription
latnumberYesVĩ độ
lonnumberYesKinh độ

So sánh thời tiết giữa các trạm (Admin)

GET /api/v1/weather/compare
Authorization: Bearer <ADMIN_TOKEN>

Query Parameters:

ParamTypeRequiredDescription
stationIdsstringYesDanh sách ID trạm (comma-separated)
startDatestringNoNgày bắt đầu (ISO 8601)
endDatestringNoNgày kết thúc (ISO 8601)

Xu hướng thời tiết (Admin)

GET /api/v1/weather/trends
Authorization: Bearer <ADMIN_TOKEN>