var Blynk = require('blynk-library');
var AUTH = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxpm2 ';
var blynk = new Blynk.Blynk(AUTH, options = {
connector : new Blynk.TcpClient()
});
var Gpio = require('onoff').Gpio,
relay = new Gpio(23, 'out'); // Pi BCM # 23
var v2 = new blynk.VirtualPin(2); // virtual pin to control GPIO 23
v2.on('write', function() {
if(relay.readSync() == 0) { // toggle gpio 23 from high to low
relay.writeSync(1);
}
else {
relay.writeSync(0);
}
});
When i use above code everything is ok,but when i restart Rpi and after Blynk connect to cloud my relay state go HIGH…can this behavior change to LOW?
That is more due to the nature of the device, musch like as on ESP… but you can try adding in a sync command to reset it upon boot to whatever last server value was.
I guess you can ask on the RPi forum if there is any way of changing the nature of the hardware…
Change to a different GPIO, add additional PULL DOWN resistors, wire your relay differently, perhaps add in a capacitor/resistor to the pin output that might smooth out the brief bump without triggering the relay, etc.
Basically I don’t see this as a Blynk related issue… hardware does what it is built to do, and some GPIOs boot or pulse HIGH.
Possibly due to how you have coded it? It is not my code so I haven’t really tried to figure out what you are doing or why you are doing it that way ;)… I was just explaining that sometimes GPIO pins boot high… if that is not your case, then it is your code.
I would toggle the pin this way (untested)
v2.on('write', function(param) {
if (param == 1) { // If Button HIGH
relay.write(1);
}
else if (param == 0) { // If Button LOW
relay.write(0);
}
});
Yes i read already…but if that is the case,i dont understand why is hapening only when i try VIRTUAL pin…
My relay is trigering on a HIGH signal (i have led indicator)