HOW TO: Display RPI's Temperature & Restart/ Shutdown RPI from Blynk

Hi Blynkers,
I am trying to figure out if there is any simpler way to achieve the following:

  1. I want to see the RPI’s temperature on the Blynk app.
  2. A button on Blynk app for Restarting and Shut Down RPI

Would appreciate if someone can help me on this.

Hello, you need just a little googling - http://www.instructables.com/id/Raspberry-Pi-Nodejs-Blynk-App-DHT11DHT22AM2302/

@Dmitriy, I think I didn’t explain myself well enough. I didn’t mean to use a DHT11/22 sensor with Pi. What I wanted was to show the temperature of raspberry pi itself on the Blynk app.

Also I was thinking of having 2 buttons on the Blynk app to remotely restart or shutdown the Pi using Blynk App but not sure how to achieve this.

@Dmitriy I suspect @ram1505 is interested in the Pi’s temperature, not the temperature around the Pi.
Pi has it’s own temperatures sensors so it can be done.

1 Like

This is what I just googled https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=114044 but this is for python. You can do the same for node.js, same with turn on/off.

1 Like

And here https://medium.com/@cyprusglobe/raspberry-pi-tutorial-plot-temperature-of-the-cpu-with-node-js-using-highcharts-59749ca29f0f#.f552o9a0u a piece of node.js code. I have no rasp now, so you have to do it by yourself =). Let us know how it is going on.

1 Like

Thanks @Dmitriy. Will try it out.

@ram1505 do you have java skills (I don’t know the first thing about java)?

touch temp.txt
awk ‘{printf("\nrPI Temperature = %.1f °C\n\n",$1/1e3)}’ /sys/class/thermal/thermal_zone0/temp > temp.txt

this will create a text file of the temperature and you could set up cron to repeat at requested intervals.

Then you need java to read characters 19 to 22 of the file (again at requested intervals) and have Blynk display the result on a ValueDisplay.

1 Like

@Costas thanks for the info. However, I don’t have java skills. :disappointed_relieved:

Here is the working node version to get RPI’s temperature shown in Blynk App on Virtual Pin V5. Thanks to @Dmitriy for the reference code :+1:

var blynkLib = require('blynk-library'),
sys = require('util'),
exec = require('child_process').exec,
child;

var AUTH = 'ENTER_AUTH_CODE_HERE';

// Setup Blynk
var blynk = new blynkLib.Blynk(AUTH);

// Automatically update sensor value every 5 seconds

setInterval(function() {
    child = exec("cat /sys/class/thermal/thermal_zone0/temp", function (error, stdout, stderr) {
    if (error !== null) {
        console.log('exec error: ' + error);
    } else {
        var temp = parseFloat(stdout)/1000;
        blynk.virtualWrite(5, temp);
       
       console.log('RPI_Temp:' temp +'C');
    }
});}, 5000);

3 Likes

Nice! Was you able to restart rasp?

I’m still working on the restart/ shutdown via Blynk App. Added the node path node app.js to rc.local and the temp shows up on Blynk each time Pi boots up.

Managed to figure out how to reboot and shutdown RPI from Blynk.

var blynk = new blynkLib.Blynk(AUTH);
var v1= new blynk.VirtualPin(1);
var v2= new blynk.VirtualPin(2);

v1.on('write', function(){
 child = exec("sudo halt", function (error, stdout, stderr) {
 });});

v2.on('write',function(){
 child = exec("sudo reboot", function (error, stdout, stderr) {
 });}); 

3 Likes

that’s Great can you share the Full code and dash Board Setup.
what happens after restart , did you set Blynk to Run after boot so you can again able to monitor and interact with it?

hello @ram1505 i saw your project and i would like to integrate it into my project too. using your sketch tells me that I need the following installed files: require (‘util’) and require (‘child_process’) .exc: how can i download them? do you have the installation link for you? Thank you for the reply

@Jack1 Please take note of the TimeDate stamps before posting… this topic is almost two years old :wink:

Also, try Google for these types of non-Blynk specific questions:

https://nodejs.org/api/child_process.html

http://node.readthedocs.io/en/latest/api/child_process/

etc…

1 Like