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