I use this for reboot… just remove the -r for shutdown.
EDIT - this is for NodeJS, not WiringPi
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) });
}
});
@Gunner thanks, just tried that (changed to V1) but got this error when trying to rebuild…
main.cpp:80:1: error: ‘var’ does not name a type
var process = require('child_process'); // Allows this script to run CLI commands
^~~
main.cpp:83:1: error: ‘var’ does not name a type
var RPiReboot = new blynk.VirtualPin(1); // Setup Reboot Button
^~~
main.cpp:85:1: error: ‘RPiReboot’ does not name a type
RPiReboot.on('write', function(param) { // Watches for V1 Button
^~~~~~~~~
main.cpp:89:2: error: expected unqualified-id before ‘)’ token
});
^
Makefile:70: recipe for target 'main.o' failed
make: *** [main.o] Error 1
dont worry about that lol… atleast it will work on the one running nodejs as I have to run it on that one too… two pi’s with two different ways of doing it is a pain in the arse… know anyone who would know the process for wiringpi?
//#define BLYNK_DEBUG
#define BLYNK_PRINT stdout
#ifdef RASPBERRY
#include <BlynkApiWiringPi.h>
#else
#include <BlynkApiLinux.h>
#endif
#include <BlynkSocket.h>
#include <BlynkOptionsParser.h>
static BlynkTransportSocket _blynkTransport;
BlynkSocket Blynk(_blynkTransport);
static const char *auth, *serv;
static uint16_t port;
#include <BlynkWidgets.h>
BLYNK_WRITE(V1)
{
printf("Got a value: %s\n", param[0].asStr());
}
var process = require('child_process'); // Allows this script to run CLI commands
// ----- RPi Reboot Command -----
var RPiReboot = new blynk.VirtualPin(2); // Setup Reboot Button
RPiReboot.on('write', function(param) { // Watches for V2 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) });
}
});
void setup()
{
Blynk.begin(auth, serv, port);
}
void loop()
{
Blynk.run();
}
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) });
}
});
int main(int argc, char* argv[])
{
parse_options(argc, argv, auth, serv, port);
setup();
while(true) {
loop();
}
return 0;
getting this error:
pi@tombabypi:~ $ cd ~/blynk-library/linux/
pi@tombabypi:~/blynk-library/linux $ make clean all target=raspberry
rm main.o ../src/utility/BlynkDebug.o ../src/utility/BlynkHandlers.o ../src/utility/BlynkTimer.o blynk
rm: remove write-protected regular file 'main.o'?
rm: remove write-protected regular file '../src/utility/BlynkDebug.o'?
rm: remove write-protected regular file '../src/utility/BlynkHandlers.o'?
rm: remove write-protected regular file '../src/utility/BlynkTimer.o'?
rm: remove write-protected regular file 'blynk'?
g++ -I ../src/ -I ./ -DLINUX -c -O3 -w -DRASPBERRY main.cpp -o main.o
main.cpp:33:1: error: ‘var’ does not name a type
var process = require('child_process'); // Allows this script to run CLI commands
^~~
main.cpp:36:1: error: ‘var’ does not name a type
var RPiReboot = new blynk.VirtualPin(2); // Setup Reboot Button
^~~
main.cpp:38:1: error: ‘RPiReboot’ does not name a type
RPiReboot.on('write', function(param) { // Watches for V2 Button
^~~~~~~~~
main.cpp:42:2: error: expected unqualified-id before ‘)’ token
});
^
main.cpp:54:1: error: ‘var’ does not name a type
var process = require('child_process'); // Allows this script to run CLI commands
^~~
main.cpp:57:1: error: ‘var’ does not name a type
var RPiReboot = new blynk.VirtualPin(20); // Setup Reboot Button
^~~
main.cpp:59:1: error: ‘RPiReboot’ does not name a type
RPiReboot.on('write', function(param) { // Watches for V20 Button
^~~~~~~~~
main.cpp:63:2: error: expected unqualified-id before ‘)’ token
});
^
Well, for one, you still have it mixed in with C++ style commands
WiringPi is more like a GPIO support library for the RPi that uses C++ type commands.
NodeJS is a full language based on javascript (AFAIK)… and while I have seen WiringPi ports that work with (under) other languages, I don’t see the purpose myself.
just thought i’d let you know that i managed to get the virtual shutdown button to work for the raspberry pi using wiring pi… now to figure out the mess of the other raspberry pi using nodejs or both if i dare lol