4

I'm developing a UI which also runs on a Raspberry Pi (currently with Raspbian).

With the os object I can get information about the OS. But how can I be sure that I'm running on Raspbian or in general on a Raspberry Pi?

console.log(os.platform()); // 'linux'
console.log(os.release()); //'3.12.28+'
4
  • what's the point? what should happen if your UI runs on Beagle or Panda or hundreds of other ARM-based linux-running boards?
    – lenik
    Nov 30, 2014 at 5:06
  • For example that i would expect an GPIO only on as raspberry pi. Nov 30, 2014 at 18:38
  • 1
    no idea how you would go about it but should you not be checking for GPIO support instead? Raspbian can be run on qemu on any platform for instance.
    – rob
    Dec 5, 2014 at 11:53
  • Hmm thinking about this your right. Do you have an starting but on whot to detemerine that there is a gpio support? Dec 9, 2014 at 17:35

2 Answers 2

7

To check for Raspbian read the file /etc/os-release and check for ID=raspbian.

PRETTY_NAME="Raspbian GNU/Linux jessie/sid"
NAME="Raspbian GNU/Linux"
ID=raspbian
ID_LIKE=debian
ANSI_COLOR="1;31"
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

To check for a Pi read the file /proc/cpuinfo and check for hardware BCM2708.

processor   : 0
model name  : ARMv6-compatible processor rev 7 (v6l)
Features    : swp half thumb fastmult vfp edsp java tls 
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part    : 0xb76
CPU revision    : 7

Hardware    : BCM2708
Revision    : 0010
Serial      : 00000000f7094d77
6

Based on joan's answer I've created a tiny Node.js library. It can be used to check if node is currently running on the RPi.

You can install it through:

npm install detect-rpi --save

To use it, you can use the following snippet:

var isPi = require('detect-rpi');

if (isPi()) {
  console.log('Running on Raspberry Pi!');
} else {
  // ...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.