1.14.0 • Published 8 years ago
@p4d/rpi v1.14.0
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/rpiUsage
// 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. Returns0000000000000000on non-RPi architectures. - Serial.exists - returns
trueif/proc/cpuinfofile exists.
Kronos
- Kronos.id - gets the Kronos Id for the RPi stored at
/etc/kronos. Returnsnullif no id is assigned. - Kronos.exists - returns
trueif/etc/kronosfile exists. - Kronos.update(newId) - Updates Kronos Id value to
newId./etc/kronosis updated.
Hermes
- Hermes.id - gets the Hermes URL for the RPi stored at
/etc/hermes. Returnsnullif no url is assigned. - Hermes.exists - returns
trueif/etc/hermesfile exists. - Hermes.update(newUrl) - Updates Hermes URL value to
newUrl./etc/hermesis updated.
Cloud
- Cloud.id - gets the Cloud URL for the RPi stored at
/etc/cloud. Returnsnullif no url is assigned. - Cloud.exists - returns
trueif/etc/cloudfile exists. - Cloud.update(newUrl) - Updates Cloud URL value to
newUrl./etc/cloudis 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. Returnsnullif 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. Returnsnullif no name is assigned. - Project.exists - returns
trueif/etc/projectfile exists. - Project.update(newName) - Updates Project Name value to
newNameand Project Id tosnake_cased_newName./etc/projectis 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].argscan be a string for single argument commands or an array with multiple arguments. - Cmd.exists(cmd) - Checks wether
cmdcommand exists on the current environment.
Temperature
- Temperature.measure() - gets CPU and GPU temperature in Celsius.
- Temperature.existsCPUTemp() - returns
trueif/sys/class/thermal/thermal_zone0/tempfile exists.
RAM
- RAM.measure() - gets RAM usage statistics
Disk
- Disk.measure() - gets Disk usage statistics
Network
- Network.data() - gets Network information
1.14.0
8 years ago
1.13.0
8 years ago
1.12.0
8 years ago
1.11.0
8 years ago
1.10.0
8 years ago
1.9.2
9 years ago
1.9.1
9 years ago
1.9.0
9 years ago
1.8.0
9 years ago
1.7.2
9 years ago
1.7.1
9 years ago
1.7.0
9 years ago
1.6.2
9 years ago
1.6.1
9 years ago
1.6.0
9 years ago
1.5.0
9 years ago
1.4.0
9 years ago
1.3.0
9 years ago
1.2.0
9 years ago
1.1.1
9 years ago
1.1.0
9 years ago
1.0.0
9 years ago