Hi guys, I created a sketch for raspberry with node.js, in this sketch I turn 2 relays via the blynk app widget button. my sketch works, only when i turn it on I turn on the relays automatically. I would like that when I start my sketch the relays remain off, how can I do it? thank you
var Blynk = require('blynk-library');
var Gpio = require('onoff').Gpio;
var AUTH = 'xxxxxxxxxxxxxxxxxxxxxxx';
var blynk = new Blynk.Blynk(AUTH);
Relay1 = new Gpio(25, 'out');
Relay2 = new Gpio(24, 'out');
var v0 = new blynk.VirtualPin(0);
v0.on('write', function(param) {
if (param == 1) {
Relay1.writeSync(1);
Relay2.writeSync(1);
} else {
Relay1.writeSync(0);
Relay2.writeSync(0);
}
console.log('v0:', param[0]);
});
Try adding the following to the end of the script to turn off the relays on reboot:
blynk.on('connect', function() {
console.log("Blynk ready.");
blynk.virtualWrite(0, 0); // send LOW / OFF to virtual pin 0
});
blynk.on('disconnect', function() { console.log("DISCONNECT"); }); // connection to the server is dropped
Ok so first observation is that when the PI reboots the Blynk button itself is going from OFF to ON, regardless of what might be happening with the relays. This suggests you have “sync” in your script. Please post your latest script to save me looking back through the thread. Meanwhile I will keep watching the video to see if I can spot anything else.