detect-rpi
detect-rpi copied to clipboard
Update detection method and add helper functions
Updated Raspberry Pi Detection & Added Helper Functions
This PR improves the Raspberry Pi detection reliability and adds useful helper functions for getting detailed system information.
Key Changes
-
Enhanced Detection Method:
- Improved hardware detection by checking both
/proc/cpuinfofields - Added support for newer Pi models (including Pi 5 and Zero 2 W)
- Added fallback checks when Hardware field is missing (Bookworm 64-bit)
- Expanded list of known Pi hardware identifiers
- Improved hardware detection by checking both
-
New Helper Functions:
- Added
model()- Returns the full Pi model string - Added
revision()- Returns the board revision code - Added
info()- Returns structured detection results
{ isPi: boolean, model: string, hardware: string, revision: string } - Added
Backward Compatibility
- Fully maintains existing API
- No breaking changes
- Same simple
isPi()interface still works as before
Testing
Verified on:
- Raspberry Pi OS Bullseye (32-bit)
- Raspberry Pi OS Bookworm (64-bit)
- Pi models: 3B+, 4B, 5, Compute Model 4
- Non-Pi systems (negative testing)
Example Usage
const isPi = require('detect-rpi');
// Basic detection
console.log(isPi()); // true/false
// Get detailed info
const piInfo = isPi.info();
if (piInfo.isPi) {
console.log(`Running on ${piInfo.model}`);
console.log(`Hardware: ${piInfo.hardware}`);
console.log(`Revision: ${piInfo.revision}`);
}