Hi friends. in below sketch I want to running the V9 only for 1 second. in the below code when I press V9 button the command runs continuously. how can I running the V9 only for 1 second ?
the code:
setTimeout(function(){
var Blynk = require('blynk-library');
var AUTH = '81cc3c5ee9754be8ab6fa4a67d8d3xe0';
var blynk = new Blynk.Blynk(AUTH, options = { connector : new Blynk.TcpClient( options = { addr:"10.5.51.5", port:8080 } ) });
var exec = require('child_process').exec, child;
var v0 = new blynk.VirtualPin(0);
var v1 = new blynk.VirtualPin(1);
var v2 = new blynk.VirtualPin(2);
var v3 = new blynk.VirtualPin(3);
var v5 = new blynk.VirtualPin(5);
var v6 = new blynk.VirtualPin(6);
var v7 = new blynk.VirtualPin(7);
var v8 = new blynk.VirtualPin(8);
var v9 = new blynk.VirtualPin(9);
var slider = new blynk.VirtualPin(4);
var writeVal = '';
//volume control using slider
slider.on('write', function(param) {
child = exec('amixer set PCM ' + param[0] + '%',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
});
//turn on squeezelite turn off others
v1.on('write', function(param) {
if (param[0] == '1') {
child = exec('sudo python /home/pi/MikroTik/reboot.py',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
writeVal = 'squeezelite ON';
}
else if (param[0] == '0') {
child = exec('sudo /etc/init.d/squeezelite stop',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
writeVal = 'squeezelite OFF';
}
});
v2.on('write', function(param) {
if (param[0] == '1') {
child = exec('sudo python /home/pi/MikroTik/lcdon.py',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
writeVal = 'shairport ON';
}
else if (param[0] == '0') {
child = exec('sudo systemctl stop shairport-sync',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
writeVal = 'shairport OFF';
}
});
v3.on('write', function(param) {
if (param[0] == '1') {
child = exec('sudo python /home/pi/MikroTik/lcdoff.py',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
writeVal = 'analog ON';
}
else if (param[0] == '0') {
child = exec('sudo killall -15 ecasound',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
writeVal = 'analog OFF';
}
});
v5.on('write', function(param) {
if (param[0] == '1') {
child = exec('sudo python /home/pi/MikroTik/dsloff.py',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
writeVal = 'analog ON';
}
else if (param[0] == '0') {
child = exec('sudo killall -15 ecasound',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
writeVal = 'analog OFF';
}
});
v6.on('write', function(param) {
if (param[0] == '1') {
child = exec('sudo python /home/pi/MikroTik/lcdon.py',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
writeVal = 'analog ON';
}
else if (param[0] == '0') {
child = exec('sudo killall -15 ecasound',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
writeVal = 'analog OFF';
}
});
v7.on('write', function(param) {
if (param[0] == '1') {
child = exec('sudo python /home/pi/MikroTik/pcoff.py',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
writeVal = 'analog ON';
}
else if (param[0] == '0') {
child = exec('sudo killall -15 ecasound',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
writeVal = 'analog OFF';
}
});
v8.on('write', function(param) {
if (param[0] == '1') {
child = exec('sudo python /home/pi/MikroTik/reboottp.py',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
writeVal = 'analog ON';
}
else if (param[0] == '0') {
child = exec('sudo killall -15 ecasound',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
writeVal = 'analog OFF';
}
});
v9.on('write', function(param) {
if (param[0] == '0') {
child = exec('sudo python /home/pi/MikroTik/wifion.py',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
writeVal = 'analog ON';
}
else if (param[0] == '1') {
child = exec('sudo python /home/pi/MikroTik/wifioff.py',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
writeVal = 'analog OFF';
}
});
v0.on('read', function() {
v0.write(writeVal);
});
}, 60000);
thanks.