Giter Club home page Giter Club logo

raspi-temp's Introduction

raspi-temp

JavaScript functions to query the Raspberry Pi's CPU in celsius or fahrenheit and perhaps later, the GPU temperature as well

A lot of people probably think that you'd need to purchase a Sense Hat at $40 in order to ask the Pi how hot it is. Clearly, if the Desktop which comes with the PIXEL version of Raspbian has access to the temperature of the Pi itself, then so should you.

Express

Given that most people in the coding space are familiar with Express, this is the demonstration piece for these functions but all you need is the raspi-temp.js file for your own project. You'd be expected to extract that out and then query the function(s) as necessary.

Installation

SSH into the Raspberry Pi (of any type) and run the following, say, under a Sites folder.

$ cd ~
$ mkdir Sites
$ cd Sites
$ git clone --depth 1 https://github.com/OutsourcedGuru/raspi-temp.git
$ cd raspi-temp
$ npm install
$ DEBUG=raspi-temp:* npm start

From another computer, you'd then open up a browser session to something like http://name-of-pi-host.local:3000. The home page of this simple site should exercise the JavaScript function to display the CPU temperature in fahrenheit as a demonstration.

getTemperature(which, scale, type)

I've tried to create an easy-to-use interface here.

which

Either 'cpu' or 'gpu' as a string should select which chip's temperature you're interested in, with 'cpu' as the default.

scale

Either 'celsius' or 'fahrenheit' as a string should select which scale you're interested in, with 'fahrenheit' as the default.

type

Use 'integer', 'decimal(2)' for a decimal with two digits of precision, or 'string' if you want to see the degree symbol plus either 'F' or 'C' at the end, with 'string' as the default. As of v1.0.0, null/integer/string are recognized and anything else returns decimal(2).

returns

The function will return a string or a number, depending upon that third argument.

Examples

var strTempCPU = getTemperature('cpu', 'fahrenheit');
console.log('The CPU temperature is ' + strTempCPU);

...or more directly...

console.log('The CPU temperature is ' + getTemperature());

In case you need the temperature as a number...

console.log('The GPU temperature is ' + getTemperature('gpu', 'celsius', 'integer').toString() + '°C');
Donate Cryptocurrency
eth-receive btc-receive
Ethereum Bitcoin

raspi-temp's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.