ตัวอย่างการใช้งาน
การนำไปใช้จริง (Use Cases)
เอกสารยกตัวอย่างสถานการณ์การใช้งาน เช่น:
- การแจ้งเตือนด้วยมือ: เจ้าหน้าที่สั่งการอพยพกรณีไฟไหม้โรงงาน
- ระบบอัตโนมัติ: เซนเซอร์สึนามิตรวจจับคลื่นได้และส่งข้อความแจ้งเตือนเข้าสู่ระบบอัตโนมัติ
- การรวมข้อมูล (Aggregation): ศูนย์สั่งการระดับรัฐรวบรวมข้อมูลเตือนภัยจากหลายแหล่งมาแสดงบนแผนที่เดียว
- การยกเลิก (Cancellation): กรณีเกิดการแจ้งเตือนผิดพลาด สามารถส่งข้อความประเภท "Cancel" เพื่อยกเลิกการเตือนก่อนหน้าได้ทันที
CAP Version 1.2 JSON Schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://docs.oasis-open.org/emergency/cap/v1.2/CAP-v1.2.json",
"title": "Common Alerting Protocol Version 1.2 (JSON Binding)",
"description": "JSON Schema representation of the OASIS CAP v1.2 standard.",
"type": "object",
"required": ["identifier", "sender", "sent", "status", "msgType", "scope"],
"properties": {
"identifier": {
"type": "string",
"description": "The identifier of the alert message"
},
"sender": {
"type": "string",
"description": "The identifier of the sender of the alert message"
},
"sent": {
"type": "string",
"format": "date-time",
"description": "The time and date of the origination of the alert message"
},
"status": {
"type": "string",
"enum": ["Actual", "Exercise", "System", "Test", "Draft"],
"description": "The code denoting the appropriate handling of the alert message"
},
"msgType": {
"type": "string",
"enum": ["Alert", "Update", "Cancel", "Ack", "Error"],
"description": "The code denoting the nature of the alert message"
},
"source": {
"type": "string",
"description": "The text identifying the source of the alert message"
},
"scope": {
"type": "string",
"enum": ["Public", "Restricted", "Private"],
"description": "The code denoting the intended distribution of the alert message"
},
"restriction": {
"type": "string",
"description": "The text describing the rule for limiting distribution of the restricted alert message"
},
"addresses": {
"type": "string",
"description": "The group listing of intended recipients of the alert message (Space delimited)"
},
"code": {
"type": "array",
"items": { "type": "string" },
"description": "The code denoting the special handling of the alert message"
},
"note": {
"type": "string",
"description": "The text describing the purpose or significance of the alert message"
},
"references": {
"type": "string",
"description": "The group listing identifying earlier message(s) referenced by the alert message"
},
"incidents": {
"type": "string",
"description": "The group listing naming the referent incident(s) of the alert message"
},
"info": {
"type": "array",
"items": { "$ref": "#/definitions/info" },
"description": "The container for all component parts of the info sub-element"
}
},
"definitions": {
"nameValuePair": {
"type": "object",
"required": ["valueName", "value"],
"properties": {
"valueName": { "type": "string" },
"value": { "type": "string" }
}
},
"info": {
"type": "object",
"required": ["category", "event", "urgency", "severity", "certainty"],
"properties": {
"language": {
"type": "string",
"default": "en-US",
"description": "The code denoting the language of the info sub-element"
},
"category": {
"type": "array",
"items": {
"type": "string",
"enum": ["Geo", "Met", "Safety", "Security", "Rescue", "Fire", "Health", "Env", "Transport", "Infra", "CBRNE", "Other"]
},
"minItems": 1
},
"event": {
"type": "string",
"description": "The text denoting the type of the subject event"
},
"responseType": {
"type": "array",
"items": {
"type": "string",
"enum": ["Shelter", "Evacuate", "Prepare", "Execute", "Avoid", "Monitor", "Assess", "AllClear", "None"]
}
},
"urgency": {
"type": "string",
"enum": ["Immediate", "Expected", "Future", "Past", "Unknown"]
},
"severity": {
"type": "string",
"enum": ["Extreme", "Severe", "Moderate", "Minor", "Unknown"]
},
"certainty": {
"type": "string",
"enum": ["Observed", "Likely", "Possible", "Unlikely", "Unknown"]
},
"audience": { "type": "string" },
"eventCode": {
"type": "array",
"items": { "$ref": "#/definitions/nameValuePair" }
},
"effective": { "type": "string", "format": "date-time" },
"onset": { "type": "string", "format": "date-time" },
"expires": { "type": "string", "format": "date-time" },
"senderName": { "type": "string" },
"headline": { "type": "string" },
"description": { "type": "string" },
"instruction": { "type": "string" },
"web": { "type": "string", "format": "uri" },
"contact": { "type": "string" },
"parameter": {
"type": "array",
"items": { "$ref": "#/definitions/nameValuePair" }
},
"resource": {
"type": "array",
"items": { "$ref": "#/definitions/resource" }
},
"area": {
"type": "array",
"items": { "$ref": "#/definitions/area" }
}
}
},
"resource": {
"type": "object",
"required": ["resourceDesc", "mimeType"],
"properties": {
"resourceDesc": { "type": "string" },
"mimeType": { "type": "string" },
"size": { "type": "integer" },
"uri": { "type": "string", "format": "uri" },
"derefUri": { "type": "string" },
"digest": { "type": "string" }
}
},
"area": {
"type": "object",
"required": ["areaDesc"],
"properties": {
"areaDesc": { "type": "string" },
"polygon": {
"type": "array",
"items": { "type": "string" },
"description": "List of coordinate pairs 'lat,lon lat,lon...'"
},
"circle": {
"type": "array",
"items": { "type": "string" },
"description": "Point and radius 'lat,lon radius'"
},
"geocode": {
"type": "array",
"items": { "$ref": "#/definitions/nameValuePair" }
},
"altitude": { "type": "number" },
"ceiling": { "type": "number" }
}
}
}
}
การออกแบบ "TH-CAP Data Exchange Standard"
ภาพรวมสถาปัตยกรรม (Architecture Concept)
เราจะมองว่าทุกหน่วยงานคือ Producer ที่ส่งข้อมูลเข้ามายัง Central Exchange Hub (เช่น แอปพลิเคชันแจ้งเตือนภัยแห่งชาติ) โดยใช้ JSON Schema เดียวกัน แต่จะมีความแตกต่างกันที่เนื้อหาภายใน

ใช้ JSON Schema ของ CAP v1.2 เป็นฐาน แต่จะ "บังคับ (Enforce)" กฎเพิ่มเติมสำหรับประเทศไทยดังนี้:
- บังคับระบุ sender: ต้องระบุชื่อหน่วยงานชัดเจน (เช่น "กรมอุตุนิยมวิทยา")
- บังคับระบุ geocode: ต้องใช้รหัสจังหวัด/อำเภอ/ตำบล ตามมาตรฐานกระทรวงมหาดไทย (5 หลัก หรือ 6 หลัก) เพื่อความแม่นยำในการแจ้งเตือนรายพื้นที่
- การใช้ parameter: ใช้สำหรับส่งค่า Sensor หรือข้อมูลจำเพาะของหน่วยงาน
TH-CAP Universal Schema (Core)
Schema กลางที่ทุกหน่วยงานต้องใช้ร่วมกัน
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://alert.th/schemas/th-cap-v1.2-universal.json",
"title": "TH-CAP Universal All-Hazard Schema",
"description": "Standard schema for all hazard types in Thailand based on OASIS CAP v1.2",
"type": "object",
"required": ["identifier", "sender", "sent", "status", "msgType", "scope", "info"],
"properties": {
"identifier": {
"type": "string",
"description": "Unique ID from the agency e.g., 'TMD-2023-001'"
},
"sender": {
"type": "string",
"format": "email",
"description": "Email or unique identifier of the agency"
},
"sent": {
"type": "string",
"format": "date-time",
"description": "ISO 8601 Timestamp"
},
"status": {
"type": "string",
"enum": ["Actual", "Exercise", "System", "Test", "Draft"]
},
"msgType": {
"type": "string",
"enum": ["Alert", "Update", "Cancel", "Ack", "Error"]
},
"scope": {
"type": "string",
"enum": ["Public", "Restricted", "Private"]
},
"info": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#/definitions/infoBlock" }
}
},
"definitions": {
"nameValuePair": {
"type": "object",
"required": ["valueName", "value"],
"properties": {
"valueName": {
"type": "string",
"description": "Key from the Parameter Dictionary e.g., 'WaterLevel', 'Magnitude'"
},
"value": {
"type": ["string", "number", "boolean"],
"description": "The measured value e.g., '5.4', 'Rising'"
}
}
},
"infoBlock": {
"type": "object",
"required": ["category", "event", "urgency", "severity", "certainty", "headline", "area"],
"properties": {
"language": { "type": "string", "default": "th-TH" },
"category": {
"type": "array",
"items": {
"type": "string",
"enum": ["Geo", "Met", "Safety", "Security", "Rescue", "Fire", "Health", "Env", "Transport", "Infra", "CBRNE", "Other"]
}
},
"event": { "type": "string", "description": "Human readable event type e.g. 'Flood'" },
"urgency": { "type": "string", "enum": ["Immediate", "Expected", "Future", "Past", "Unknown"] },
"severity": { "type": "string", "enum": ["Extreme", "Severe", "Moderate", "Minor", "Unknown"] },
"certainty": { "type": "string", "enum": ["Observed", "Likely", "Possible", "Unlikely", "Unknown"] },
"headline": { "type": "string" },
"description": { "type": "string" },
"instruction": { "type": "string" },
"area": {
"type": "array",
"items": { "$ref": "#/definitions/areaBlock" }
},
"parameter": {
"type": "array",
"description": "Dynamic fields for specific hazard data",
"items": { "$ref": "#/definitions/nameValuePair" }
}
}
},
"areaBlock": {
"type": "object",
"required": ["areaDesc"],
"properties": {
"areaDesc": { "type": "string" },
"polygon": { "type": "array", "items": { "type": "string" } },
"circle": { "type": "array", "items": { "type": "string" } },
"geocode": {
"type": "array",
"items": { "$ref": "#/definitions/nameValuePair" }
}
}
}
}
}
- กรณี: กรมอุตุนิยมวิทยา (TMD) - แจ้งเตือนพายุ-อากาศ
- กรณี: อัคคีภัย หรือ สารเคมีรั่วไหล (Fire & Rescue)
- กรณี: กรมควบคุมมลพิษ (PCD) - ฝุ่น PM2.5
- กรณี: แผ่นดินไหว หรือ สึนามิ (Geophysical)
- กรณี: อุทกภัย หรือ น้ำท่วม (Flood)
- กรณี: โรคระบาด (Epidemic)
- กรณี: ภัยแล้ง (Drought)
- กรณี: ความมั่นคง หรือ เหตุร้าย (Security)