npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@p4d/rpi

v1.14.0

Published

Raspberry Pi utility that handles messaging to Hermes server via a queue daemon.

Downloads

16

Readme

RPi

RPi is a nodejs library that provides access to basic Raspberry Pi info and functionality.

Installation

RPi is distributed via NPM:

npm install --save @p4d/rpi

Usage

// Include library
const RPi = require('@p4d/rpi')

// Access RPi data
console.log(RPi.Kronos.id)
console.log(RPi.Project.name)

// Exposed functionality
if (RPi.Cmd.exists('rpi-config')) {     // This is actually not required since RPi.Cmd.run already checks if the command exists.
  console.log(RPi.Cmd.run('rpi-config', ['hostname', 'PAPA4D']))
}

Classes

RPi library exposes RPi data and functionality as static classes:

Serial

  • Serial.id - gets the Serial Id for the RPi. Gets value from /proc/cpuinfo. Returns 0000000000000000 on non-RPi architectures.
  • Serial.exists - returns true if /proc/cpuinfo file exists.

Kronos

  • Kronos.id - gets the Kronos Id for the RPi stored at /etc/kronos. Returns null if no id is assigned.
  • Kronos.exists - returns true if /etc/kronos file exists.
  • Kronos.update(newId) - Updates Kronos Id value to newId. /etc/kronos is updated.

Hermes

  • Hermes.id - gets the Hermes URL for the RPi stored at /etc/hermes. Returns null if no url is assigned.
  • Hermes.exists - returns true if /etc/hermes file exists.
  • Hermes.update(newUrl) - Updates Hermes URL value to newUrl. /etc/hermes is updated.

Cloud

  • Cloud.id - gets the Cloud URL for the RPi stored at /etc/cloud. Returns null if no url is assigned.
  • Cloud.exists - returns true if /etc/cloud file exists.
  • Cloud.update(newUrl) - Updates Cloud URL value to newUrl. /etc/cloud is updated.

Project

  • Project.id - gets the Project Id for the RPi stored at /etc/project. Project Id is the snake case formated version of the Project Name. Returns null if no id is assigned.
  • Project.name - gets the Project Name for the RPi stored at /etc/project. Project name is the full string formated name for the current project. Returns null if no name is assigned.
  • Project.exists - returns true if /etc/project file exists.
  • Project.update(newName) - Updates Project Name value to newName and Project Id to snake_cased_newName. /etc/project is updated.

Status

  • Status.ready() - Checks wether RPi is ready to send data packets to Hermes. Three conditions are needed: RPi must have assigned Project Id, Kronos Id and Hermes URL.
  • Serial.data() - Generates a data package with status information on the RPi. It does NOT check if RPi is ready to send the data to Hermes - Status.ready() needs to be checked before sending it.

The data package includes the following info:

serial - Serial id
kronosId - Kronos id
hermesUrl - Hermes url
cloudUrl - Cloud url
project: {
  name - Project name
  id - Project Id
}
hostname - OS Hostname
ip - IP Address
uptime - OS Uptime
disk: {
  free - Free space in bytes
  freeGB - Free space in GBytes
  freePer - Free space in percentile
  total - Total space in bytes
  totalGB - Total space in GBytes
}
ram: {
  free - Free RAM in bytes
  freeMB - Free RAM in MBytes
  freePer - Free RAM in percentile
  total - Total RAM in bytes
  totalMB - Total RAM in MBytes
}
platform: {
  os - OS Pretty Name for Rasbpian with version. For example `Raspbian GNU/Linux 8 (jessie)`
  version - OS version release identifier. For example `16.4.0` on macOS Sierra
  type - OS string identifier. For example `Linux` on Linux, `Darwin` on macOS, `Windows_NT` on Windows
}

Cmd

  • Cmd.run(cmd, args) - Runs a command with arguments. Equivalent of doing cmd args[0] args[1] ... args[n]. args can be a string for single argument commands or an array with multiple arguments.
  • Cmd.exists(cmd) - Checks wether cmd command exists on the current environment.

Temperature

  • Temperature.measure() - gets CPU and GPU temperature in Celsius.
  • Temperature.existsCPUTemp() - returns true if /sys/class/thermal/thermal_zone0/temp file exists.

RAM

  • RAM.measure() - gets RAM usage statistics

Disk

  • Disk.measure() - gets Disk usage statistics

Network

  • Network.data() - gets Network information