NodeJS Blynk - Code Examples for Basic Tasks (Work in Progress)

8 - Reboot or shutdown RPi from Button Widget

I use this for reboot… just remove the -r for shutdown.

var process = require('child_process'); // Allows this script to run CLI commands

// ----- RPi Reboot Command -----
var RPiReboot = new blynk.VirtualPin(20);  // Setup Reboot Button

RPiReboot.on('write', function(param) {  // Watches for V20 Button
  if (param == 1) {  // Runs the CLI command if the button on V20 is pressed
    process.exec('sudo /sbin/shutdown -r', function (msg) { console.log(msg) });
}
});
1 Like