I’ve spent a few hours trying to get this to work looking at example code etc but not really getting anywhere.
When I execute the script the GPIO pin goes high but clicking V1 button does not toggle the pin. (not even if I set it in reverse in the Android App…)
Im connected to my Raspberry Pi via wifi and the connection is definitely ok.
var Blynk = require('blynk-library');
var Gpio = require('onoff').Gpio;
var door = new Gpio(17, 'out');
var AUTH = 'xxxxx';
var blynk = new Blynk.Blynk(AUTH);
var v1 = new blynk.VirtualPin(1);
// Sync State
blynk.on('connect', function() {
console.log("Blynk ready.");
blynk.syncAll();
});
v1.on('write', function() {
if(door.readSync() == 0) {
door.writeSync(1);
}
else {
door.writeSync(0);
}
function unexportOnClose() { //function to run when exiting program
door.writeSync(0); // Turn LED off
door.unexport(); // Unexport LED GPIO to free resources
}
});
You don’t have any link between the function and the if condition… and I am unsure whether door.readSync() would work that way? (whatever that is referring too, perhaps your WiringPi reference?)
I typically have something like this, using param as the link (no, I don’t know the technical term )…
// ----- RPi Reboot Command -----
var RPiReboot = new blynk.VirtualPin(20); // Setup Reboot Button on V20
RPiReboot.on('write', function(param) { // Watches for V20 Button
if (param == 1) { // Runs the CLI command if the button on V20 is pressed
process.exec('sudo /sbin/shutdown -r', function (msg) { console.log(msg) });
}
});