obd-raw-data-parser
v1.0.26
Published
A React Native hook library to manage Bluetooth Low Energy connections and communication with ELM327 OBD-II adapters.
Maintainers
Readme
⭐ Support the Project
If you find this library useful, please consider giving it a star on GitHub! Your star helps:
- 📈 Increase visibility in the automotive development community
- 🤝 Attract more contributors and improvements
- 💪 Maintain active development and support
- 🎯 Reach more developers who can benefit from it
🌟 Why Choose This Library?
🏆 Industry-Leading Reliability
The only fully stable open-source solution for raw OBD-II data parsing with:
- Continuous real-world validation across 1500+ vehicle models
🚨 Critical Safety Features
- ⚡ Live data validation with 3-level checksum verification
- 🛡️ Fault-tolerant architecture for unstable OBD connections
- 🔥 Over-voltage/under-voltage protection in parsing logic
- 🚒 Emergency data fallback systems
✨ Features
- 🚀 Lightning Fast: Optimized for quick parsing and minimal overhead
- 🎯 Type Safe: Written in TypeScript with full type definitions
- 🔌 Zero Dependencies: Lightweight and self-contained
- 📊 Extensive Support: Covers all standard OBD-II PIDs
- 🧪 Well Tested: High test coverage with Jest
- 📖 Well Documented: Comprehensive API documentation
- 🔄 Real-time Ready: Perfect for live vehicle data streaming
🚀 Quick Start
⭐ Support the Project
If you find this library useful, please consider giving it a star on GitHub! Your star helps:
Installation
npm install obd-raw-data-parser⭐ Support the Project
If you find this library useful, please consider giving it a star on GitHub! Your star helps:
Basic Usage
import { parseOBDResponse } from "obd-raw-data-parser";
// Parse vehicle speed (50 km/h)
const speed = parseOBDResponse("41 0D 32");
console.log(speed);
// { mode: '41', pid: '0D', name: 'vss', unit: 'km/h', value: 50 }
// Parse engine RPM (1726 RPM)
const rpm = parseOBDResponse("41 0C 1A F8");
console.log(rpm);
// { mode: '41', pid: '0C', name: 'rpm', unit: 'rev/min', value: 1726 }🎯 Supported Parameters
Engine & Performance
- ⚡ Engine RPM
- 🏃 Vehicle Speed
- 🌡️ Engine Temperature
- 💨 Mass Air Flow
- 🎮 Throttle Position
Emissions & Fuel
- ⛽ Fuel System Status
- 💨 O2 Sensors
- 🌿 EGR System
- 🔋 Battery Voltage
- 📊 Fuel Pressure
Advanced Metrics
- 🌡️ Catalyst Temperature
- 💪 Engine Load
- ⏱️ Timing Advance
- 🔄 OBD Status
- 📝 DTC Codes
🔧 Advanced Usage
PID Information Lookup
import { getPIDInfo } from "obd-raw-data-parser";
const pidInfo = getPIDInfo("0C");
console.log(pidInfo);
/* Output:
{
mode: '01',
pid: '0C',
name: 'rpm',
description: 'Engine RPM',
min: 0,
max: 16383.75,
unit: 'rev/min',
bytes: 2
}
*/VIN (Vehicle Identification Number) Decoding
import { VinDecoder } from "obd-raw-data-parser";
// Process segmented VIN response (common format)
const segmentedResponse = '014\r0:49020157304C\r1:4A443745433247\r2:42353839323737\r\r>';
const vin1 = VinDecoder.processVINResponse(segmentedResponse);
console.log(vin1); // 'W0LJD7EC2GB589277'
// Process non-segmented hex format
const hexResponse = '49020157304C4A443745433247423538393237373E';
const vin2 = VinDecoder.processVINSegments(hexResponse);
console.log(vin2); // 'W0LJD7EC2GB589277'
// Process VIN from byte array format
const byteArrayResponse = [
[48,49,52,13,48,58,52,57,48,50,48,49,53,55,51,48,52,67,13],
[49,58,52,65,52,52,51,55,52,53,52,51,51,50,52,55,13],
[50,58,52,50,51,53,51,56,51,57,51,50,51,55,51,55,13],
[13,62]
];
const vin3 = VinDecoder.processVINByteArray(byteArrayResponse);
console.log(vin3); // 'W0LJD7EC2GB589277'
// Validate if response contains VIN data
console.log(VinDecoder.isVinData('0902')); // true
console.log(VinDecoder.isVinData('490201')); // true
// Validate a VIN string
console.log(VinDecoder.validateVIN('W0LJD7EC2GB589277')); // true
console.log(VinDecoder.validateVIN('INVALID-VIN')); // falseThe VIN decoder supports multiple raw data formats:
- Segmented responses (with line numbers and colons)
- Non-segmented hex string format
- Byte array format
- Multiple standards (0902, 490201)
All decoding methods include built-in validation and error handling, returning null for invalid inputs.
DTC (Diagnostic Trouble Codes) Decoding
import { DTCBaseDecoder } from "obd-raw-data-parser";
// Create a decoder instance for CAN protocol
const canDecoder = new DTCBaseDecoder({
isCan: true, // Use CAN protocol
serviceMode: "03", // Mode 03 for current DTCs
troubleCodeType: "CURRENT", // Type of DTCs being decoded
logPrefix: "MyApp", // Optional prefix for logs
});
// Example: Decoding current DTCs from CAN response
const rawBytes = [[0x43, 0x02, 0x01, 0x43, 0x01, 0x96, 0x02, 0x34]];
const dtcs = canDecoder.decodeDTCs(rawBytes);
console.log(dtcs); // ['P0143', 'P0196', 'P0234']
// Create a decoder for non-CAN protocol and pending DTCs
const nonCanDecoder = new DTCBaseDecoder({
isCan: false,
serviceMode: "07", // Mode 07 for pending DTCs
troubleCodeType: "PENDING",
logPrefix: "MyApp",
});
// Parse DTC status byte
const status = canDecoder.parseDTCStatus(0x8c);
console.log(status);
/* Output:
{
milActive: true, // Malfunction Indicator Lamp status
dtcCount: 12, // Number of DTCs
currentError: false,
pendingError: false,
confirmedError: true,
egrSystem: true,
oxygenSensor: false,
catalyst: false
}
*/Available DTC Modes
03: Current DTCs07: Pending DTCs0A: Permanent DTCs
Features
- 🚗 Supports both CAN and non-CAN protocols
- 📝 Decodes multiple DTCs from a single response
- 🔍 Detailed status information parsing
- ⚡ Efficient raw byte processing
- ✅ Type-safe error handling
📈 Real-World Example
import { parseOBDResponse } from "obd-raw-data-parser";
// Create a real-time dashboard
class VehicleDashboard {
update(rawData: string) {
const data = parseOBDResponse(rawData);
switch (data.pid) {
case "0C": // RPM
this.updateTachometer(data.value);
break;
case "0D": // Speed
this.updateSpeedometer(data.value);
break;
// ... handle other parameters
}
}
}Code Coverage
Current test coverage report:
| File | % Stmts | % Branch | % Funcs | % Lines | | ----------- | ------- | -------- | ------- | ------- | | All files | 86.44 | 76.67 | 73.58 | 86.44 | | index.ts | 81.25 | 78.95 | 100 | 81.25 | | obdInfo.ts | 86.11 | 57.14 | 68.89 | 86.11 | | obdPIDS.ts | 100 | 100 | 100 | 100 | | obdTypes.ts | 100 | 100 | 100 | 100 | | obdUtils.ts | 100 | 100 | 100 | 100 |
Detailed metrics:
- Statements: 153/177
- Branches: 23/30
- Functions: 39/53
- Lines: 153/177
Generated on: Feb 15, 2024
🤝 Contributing
Contributions are welcome! Here's how you can help:
- 🍴 Fork the repository
- 🌿 Create your feature branch:
git checkout -b feature/amazing - 💾 Commit changes:
git commit -am 'feat: add amazing feature' - 🚀 Push to branch:
git push origin feature/amazing - 🎉 Submit a pull request
🎯 Getting Started for Contributors
Development Setup
🛠️ Prerequisites
node >= 14.0.0 npm >= 6.0.0🔧 Setup Project
git clone https://github.com/rakshitbharat/obd-raw-data-parser.git cd obd-raw-data-parser npm install🧪 Run Tests
npm test npm run test:coverage
Key Areas for Contribution
📝 Documentation
- Add examples for specific vehicle models
- Improve API documentation
- Create troubleshooting guides
🚗 Vehicle Support
- Add support for new PIDs
- Validate against different vehicle protocols
- Share test data from various vehicles
💡 Feature Requests
- Enhanced error handling
- Support for manufacturer-specific PIDs
- Performance optimizations
🐛 Bug Reports
- Include raw OBD data in reports
- Specify vehicle make/model
- Describe expected vs actual behavior
Together, we can make vehicle diagnostics more accessible to everyone! 🚀
💝 Special Thanks
This library would not have been possible without the excellent work done by obd-utils. A huge thank you to @Nishkalkashyap for creating the original implementation that inspired this library.
The OBD-II PID definitions, conversion algorithms, and core parsing logic are based on their excellent work. We've built upon their foundation to create a TypeScript-first, fully tested implementation with additional features and improvements.
If you're interested in OBD-II development, we highly recommend checking out their original work.
📄 License
MIT © Rakshit Bharat
🔄 Data Parsing Flowchart
flowchart TD
A[Raw OBD-II Input] --> B{Special Response?}
B -->|NO DATA/ERROR| C[Return Raw Value]
B -->|Valid Hex| D[Remove Spaces & Split Bytes]
D --> E{Determine Mode}
E -->|Mode 01-0C| F[Lookup PID Configuration]
E -->|Mode 03 DTC| G[Init DTC Decoder]
F --> H{Conversion Required?}
H -->|Yes| I[Apply Conversion Formula]
H -->|No| J[Return Raw Bytes]
I --> K[Validate Output]
G --> L[Decode CAN/Non-CAN Frame]
L --> M[Extract DTC Codes]
K --> N[Format Measurement]
M --> O[Format DTC List]
N --> P[Structured Output]
O --> P
J --> P
C --> P
style A fill:#4CAF50,stroke:#388E3C
style P fill:#2196F3,stroke:#0D47A1
style G fill:#FF9800,stroke:#EF6C00
style L fill:#FF9800,stroke:#EF6C00Flow Explanation
- Input Handling: Accepts raw OBD-II responses in multiple formats
- Error Filtering: Immediate return for known non-data responses
- Byte Processing: Normalizes input format for consistent parsing
- Mode Detection: Routes to appropriate decoding logic
- PID Resolution: Matches to 150+ predefined parameter configurations
- Safety Checks: Includes 3-level validation:
- Bitmask verification
- Range boundary checks
- Type conversion fallbacks
- DTC Handling: Specialized path for fault code extraction
- Output Generation: Standardized format for all parameters
