(SOLVED) (Virtual) Buttons to start and stop programs (on RPi from App)

Hi all,

Is there a simple way to run a button on a virtual pin which when pressed starts a program on my Raspberry Pi? I’m tring to start and stop the program ‘Kismet’ remotely. Many thanks.

@Tobias if you have a basic understanding of Javascript then it’s a fairly straightforward to call any program on the Pi with child_process.

Many thanks Costas. I’m one of those anoying Noobs! i’ve been looking for examples, could you help ? I can set up the buttons and virtual pin but am struggling to get the my .js file to execute what i would normally type ‘sudo kismet_server’ in terminal to do. Any help much appriciated.

@Tobias something like this in your js:

const spawn = require('child_process').spawn;

and in the virtual pin call a script file with:

const sh = spawn('sh', ['/home/pi/runKismet.sh']);

Thank! I’ll give it a go.

I’m struggling! The below is all i have so far. Missing the bit in my .js file that sets up the button on V2 …Help?!

var Blynk = require(‘blynk-library’);

const spawn = require(‘child_process’).spawn;

var AUTH = ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxx’;

var blynk = new Blynk.Blynk(AUTH);

var v2 = new blynk.VirtualPin(2);

const sh = spawn(‘sh’, [’/home/pi/startkismet.sh’]);

@Tobias have you worked through the few js examples that are available for Blynk?
Are you using Blynk’s cloud server?

Move the script call as indicated below:

v2.on('write', function(param) {
  if (param[0]=='1') {
    console.log('Button pressed');
    const sh = spawn('sh', ['/home/pi/startkismet.sh']);
  }
});

Hi Costas,

Yes, i’m using the cloud server. I’ve looked through the exaples but can’t see one that launches a program. I have my sh file working. Just struggling tring to get a virtual pin button to start it. Thanks again for your help.

Thanks Costas - I got it working!!!
You’re a star.

1 Like