ระบุตัวกล่องและ API key
อ่าน ECM-ID จากกล่องแบบออฟไลน์ และถ้าต้องการชื่อรุ่นให้ใช้ API key ฟรี
identify() อ่าน ECM-ID จากกล่อง เป็น 5 ไบต์ แสดงเป็นตัวอักษร hex 10 ตัว
(เช่น 0101880D01) ใช้แค่สาย และทำงานออฟไลน์ได้
ชื่อรุ่น (พร้อมผู้ผลิต, รหัส ECU, และ live profile ที่แนะนำ) มาจาก
smongrot API ต้องใช้ API key ฟรีจาก https://developers.smongrot.com
ถ้าไม่มี key ก็ไม่พัง: live data กับรหัสข้อผิดพลาดทำงานเหมือนเดิม
และ model เป็น null
JavaScript
import { connect, smongrotApi } from '@smongrot/sdk';
const api = smongrotApi({ apiKey: process.env.SMONGROT_API_KEY });
const s = await connect(transport, { lookupModel: api.lookupModel });
const id = await s.identify();
console.log(id.ecmId); // "0101880D01", read from the box
console.log(id.model?.model ?? '—'); // model name (may be Thai), or "—" if unknown / offline / no key
Dart
final api = SmongrotApi(apiKey: myKey);
final s = await connect(transport, lookupModel: api.lookupModel);
final id = await s.identify();
print(id.ecmId);
print(id.model?.model ?? '—');
model มีอะไรบ้าง
| ฟิลด์ | |
|---|---|
model |
ชื่อรุ่นที่คนขี่ใช้เรียก อาจเป็นภาษาไทย และไม่มีปีรุ่น |
maker |
keihin หรือ shindengen (ใช้เลือกตัวถอดรหัสข้อผิดพลาดด้วย) |
ecuCode |
รหัสอะไหล่เต็ม เช่น 38770-K03-H01 (ตั้งเป็น partCode ด้วย) |
liveProfile |
รหัส live profile ที่แนะนำ มักเป็น null เพราะ live() ตรวจ profile เอง จึงไม่ต้องใส่ |
verified |
true ถ้า ECM-ID นี้ถูกยืนยันกับกล่องจริงแล้ว |
ecmId |
ECM-ID ที่ API ตอบกลับ |
ตัวอย่าง data: {"ecm_id": "0101880D01", "maker": "keihin", "model": "<model name>", "ecu_code": "38770-K03-H01", "live_profile": null, "verified": true}
คำขอ
GET https://api.smongrot.com/v1/ecu/identify?ecm=<10 hex> พร้อม header
Authorization: Bearer <your key> สำเร็จได้ { "data": { "ecm_id", "maker", "model", "ecu_code", "live_profile", "verified" } } ผิดพลาดได้
{ "error": { "code", "message", "docs_url" } } ส่งไปแค่ ECM-ID
ข้อผิดพลาดไม่ทำให้ identify พัง
lookupModel ไม่ throw ECU ที่ไม่รู้จัก (404), key ผิด, rate limit,
timeout (ค่าเริ่มต้น 5 วินาที ตั้งที่ timeoutMs / timeout) หรือไม่มีเครือข่าย
ทุกกรณีนี้ได้ model: null อยากรู้สาเหตุ ให้ส่ง onError:
smongrotApi({ apiKey, onError: (e) => console.warn(e.code, e.message) });
รหัส: API_UNAUTHORIZED, API_RATE_LIMITED, API_NETWORK, API_ERROR,
API_BAD_RESPONSE, API_BAD_INPUT ถ้าลืมใส่ key ถือเป็นความผิดพลาดตอนเขียนโปรแกรม
จะ throw NO_API_KEY ตอนสร้างตัวช่วย ไม่ใช่ระหว่าง identify
เก็บ key ไว้เป็นความลับ
อย่าใส่ key ในหน้าเว็บสาธารณะ ถ้าเป็นแอปบนเบราว์เซอร์ ให้เรียก API จาก
เซิร์ฟเวอร์ของคุณเอง แล้วส่ง lookupModel(ecmId) ของคุณเข้า connect
ฟังก์ชันที่คืน { model, maker, ... } หรือ null ใช้ได้ทั้งหมด
ถัดไป: ภาพรวมโปรโตคอล