Delay node js script

Hello i want to put delay timers betwen 2 function cli and automatic sync virtual pins blynk


var Blynk = require('blynk-library');
var AUTH = 'xxxx';

var blynk = new Blynk.Blynk(AUTH);



var process = require('child_process');

var v9 = new blynk.VirtualPin(9);
var v2 = new blynk.VirtualPin(2); 		



v9.on('write', function(param) {
  console.log('V9:', param[0]);
   if (param == 0) {
        blynk.virtualWrite(2, 0);
        process.exec('node /home/pi/my-awesome-project/indexoff.js', function (msg) { console.log(msg) });
        delay(25000);
        process.exec('node /home/pi/my-awesome-project/indexoff.js', function (msg) { console.log(msg) });
        delay(25000);
        process.exec('node /home/pi/my-awesome-project/indexoff.js', function (msg) { console.log(msg) });
    } else if (param == 1) {
        blynk.virtualWrite(2, 255);
        process.exec('node /home/pi/my-awesome-project/indexon.js', function (msg) { console.log(msg) });
        delay(25000);
        process.exec('node /home/pi/my-awesome-project/indexon.js', function (msg) { console.log(msg) });
        delay(25000);
        process.exec('node /home/pi/my-awesome-project/indexon.js', function (msg) { console.log(msg) });
    }
});


then in case this js script its loose conection or his closing for any reason i want to run automatic this comand to run this command

process.exec(‘node /home/pi/my-awesome-project/indexmanual.js’, function (msg) { console.log(msg) });

how to do that ?

thanks

If I recall correctly… it has been awhile since I used Blynk’s NodeJS… you should use timers instead of sleep.

thanks its works

Hello this function working fine; but i dont want to repeat the same CLI status every 30000 msec .
How to avoid; this is token is from thermostat , and is sending status v72 (0) or (1) bi every 30 sec, is conected to esp8266.
I use the same token123456 1 from esp8266 1 from rasppi to bridge .
i have Error and the script from rasp pi is closing.
I want to change the status once or twice off CLI.
Note if i put another v pin for example v9 is working fine from the button app.
On mi console appear v72 0
v72 0
v72 0
v72 0
v72 0
until is change the status off v72
v72 1
v72 1
v72 1 etc


rasp pi


var Blynk = require('blynk-library');
var AUTH = '123456';

var blynk = new Blynk.Blynk(AUTH);



var process = require('child_process');

var v72 = new blynk.VirtualPin(72);
var v2 = new blynk.VirtualPin(2); 		



v72.on('write', function(param) {
  console.log('V72:', param[0]);
   if (param == 0) {
        blynk.virtualWrite(2, 0);
        process.exec('node /home/pi/my-awesome-project/indexoff.js', function (msg) { console.log(msg) });
        
    } else if (param == 1) {
        blynk.virtualWrite(2, 255);
        process.exec('node /home/pi/my-awesome-project/indexon.js', function (msg) { console.log(msg) });
        
    }
});

esp8266


#include <DHT.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#define BLYNK_PRINT Serial
#define DHTPIN 12
#define DHTTYPE DHT22
char auth[] = "123456";
char ssid[] = "xxx";
char pass[] = "xxxx";
const int red = 0;
const int green = 1;
const int blue = 16;
const int pbuttonPin = 5;   // change as per your button attached.
const int relayPin =  14;
const int rel = 2;
int motorInitiated = 0;
int motorInitiated1 = 0;
int motorInitiated2 = 0;
int motorInitiated3 = 0;
int motorInitiated4 = 0;
int motorInitiated5 = 0;
int motorInitiated6 = 0;
int motorInitiated7 = 0;
int setTemp;
int t1;
int val = 0; // push value from pin 2
int lightON = 0;//light status
int pushed = 0;//push status
SimpleTimer timer;
DHT dht(DHTPIN, DHTTYPE);
WidgetBridge bridge1(V1);



BLYNK_CONNECTED() {
  Blynk.syncAll();
  // Place the AuthToken of the second hardware here
  bridge1.setAuthToken("56e9098a1b5c43f5a5e230055b186c75");
}







BLYNK_WRITE(V11) {

  int pinData = param.asInt();

  if (pinData == 1) {
    digitalWrite(blue, HIGH );
    motorInitiated = 0;
    timer.restartTimer(t1);
  } else {
    timer.restartTimer(t1);
    timer.disable(t1);
    motorInitiated++;
    motorInitiated1++;
    motorInitiated2++;
    motorInitiated6 = 0;
    digitalWrite(red, HIGH);
    digitalWrite(green, HIGH );
  }
}

BLYNK_WRITE(V71) {

  int pinData = param.asInt();

  if (pinData == 1) {
    motorInitiated7++;// Sets motor Initiated to 1
  } else {
    motorInitiated7 = 0;
  }
}



BLYNK_WRITE(V3)
{
  setTemp = param.asInt();
}

void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  Blynk.virtualWrite(V41, h);
  Blynk.virtualWrite(V31, t);

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }


  if (t >= setTemp)
  {
    digitalWrite(red, HIGH);
    digitalWrite(blue, HIGH );
    timer.restartTimer(t1);
    timer.disable(t1);
    motorInitiated1++;
    motorInitiated2++;
    motorInitiated6 = 0;
    if (motorInitiated == 0) {
      digitalWrite(green, LOW );


    }
  }
  else  {
    digitalWrite(green, HIGH );
    if (motorInitiated == 0) {
      digitalWrite(red, LOW );
      motorInitiated6++;
      timer.enable(t1);
      motorInitiated1 = 0;


    }
    else {
      motorInitiated1++;
      motorInitiated2++;
      digitalWrite(red, HIGH);
      digitalWrite(blue, LOW );
    }

  }

}


void sendSensor1() {

  if (motorInitiated1 == 0)
  {

    motorInitiated2 = 0;

  }
}

void sendSensor2() {

  if (motorInitiated2 == 0)
  {

    digitalWrite(red, HIGH);
    delay(500);
    digitalWrite(blue, LOW );
    delay(500);
    digitalWrite(blue, HIGH );
    digitalWrite(red, LOW );
    delay(500);
    digitalWrite(red, HIGH);
  }

}


void sendSensor3()
{
  val = digitalRead(pbuttonPin);// read the push button value

  if (val == 1 && lightON == 0) {

    pushed = 1 - pushed;
    delay(200);
  }

  lightON = val;

  if (pushed == 1 && motorInitiated3 == 0) {
    motorInitiated4++;
  }
  else {
    motorInitiated4 = 0;

  }
  if (motorInitiated4 == 0 && motorInitiated5 == 1)
  {

    digitalWrite(relayPin, HIGH);
  } else {
    digitalWrite(relayPin, LOW);
  }
}


void sendSensor4() {

  if (motorInitiated6 == 0 && motorInitiated7 == 0)
  {

    digitalWrite(rel, HIGH);
    bridge1.virtualWrite(V72, 0);
  } else {
    digitalWrite(rel, LOW );
    bridge1.virtualWrite(V72, 1);
  }
}



void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(pbuttonPin, INPUT_PULLUP);
  pinMode(relayPin, OUTPUT);
  pinMode(rel, OUTPUT);
  digitalWrite(red, HIGH);
  digitalWrite(green, HIGH);
  digitalWrite(blue, HIGH);
  digitalWrite(relayPin, HIGH);
  digitalWrite(rel, HIGH);
  dht.begin();
  timer.setInterval(800L, sendSensor);
  timer.setInterval(400L, sendSensor2);
  timer.setInterval(300L, sendSensor3);
  timer.setInterval(35000L, sendSensor4);
  t1 = timer.setInterval(3600000L, sendSensor1);
  timer.disable(t1);



}

void loop() {
  Blynk.run();
  timer.run();
}


the arduino code is running fine , i dont want to change.