(NodeJS) Script for send auto tasks for a virtual button and disconnecting at the end

Hi guys, I’m new to Blynk and not an expert on anything, but I’ll try to make myself clear.

I have a RPi 3B with some relays already monitored by a simple nodejs Blynk script
that runs all time since boot, and it works fine: At any time I can manually turn on/off
a virtual button in the app and set relays to command some external lights.

Now I need send an auto command from a RPi script to set lights on/off after some hours
(start/end of night).

I did a js script to do that, it looks to do the job and even sync virtual buttons in the app but it stays connected at the end, so I need to interrupt it with ctrl-C.

How interrupt it by command after do its job?

Thank you in advance!

var Blynk = require('blynk-library');
var AUTH = 'shoobidoobidoodabadabadaa';
var blynk = new Blynk.Blynk(AUTH, options = {
 connector : new Blynk.TcpClient()
});

var v1 = new blynk.VirtualPin(1);  // Button widget

blynk.on('connect', function() {
  blynk.syncVirtual(1);
});


var Gpio = require('/usr/lib/node_modules/onoff').Gpio;
var relay1 = new Gpio(17);  // Pi BCM # 17 - Light 1

v1.on('write', function(param) { //sets relay1 ON if V1 OFF
        if(param == 0) {
                relay1.writeSync(1);
                v1.on('write', function() {
                v1.write(1);
                });
        }
});

blynk.on('connect', function() {
  blynk.syncVirtual(1);
});

Log:

OnOff mode
Connecting to TCP: blynk-cloud.com 80
Connected
Authorized
^C
1 Like

Backticks, not commas or apostrophes :wink:

Blynk%20-%20FTFC

Please don’t add another post of the correction, just go back and edit the initial post.

Do you mean stop the script from running, basically send itself a ctrl-C? That is a new one :stuck_out_tongue: most want to keep a script from stopping.

You would have to Google for that as it would be a JS issue not Blynk specific…

Hint, it turns out it is a simple command, or process of commands, depending on how cleanly you want to exit - NodeJS command to stop script from running - Google Search

Sorry for the initial ‘’’ and for think was a Blynk issue.

Using your search got it to work using the below code at the end of the script, but will search for a better solution, not just using a delay (I will try to test the execution of commands).

setTimeout((function() {
    return process.exit(22);
}), 10000);
1 Like