BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Need help with basic Blynk script for relay switch

#1

Hi. Im new to programing so i need help to make the scrip work right. Below is my basic script to trigger the relays.
Im having problems because the script toggles the relay on startup so i would like to implement the function Blynk.syncAll
so that the last command is always set on startup. The second thing i would like to add is the code to set the duration( in sec ) for the command when pressing the button.

var Blynk = require(‘blynk-library’);
var Gpio = require(‘onoff’).Gpio;
var led = new Gpio(11, ‘out’);

var AUTH = ‘...........’;

var blynk = new Blynk.Blynk(AUTH);

var v0 = new blynk.VirtualPin(0);

v0.on(‘write’, function(param) {

if (param[0] == ‘1’) {
led.writeSync(1);
} else {
led.writeSync(0);
}

console.log(‘Open’, param[0]);

});
0 Likes

#2

Are you new to reading directions as well? :stuck_out_tongue_winking_eye: You didn’t format your posted code, as requested in the directions you deleted when posting your topic… as well as listed in the Welcome Topic… and repeated all throughout this forum :wink:

Blynk - FTFC

Also, we do not really teach programming here… but you can search this forum for other NodeJS examples that might give you some insight how to implement Blynk in that language.

For example…

0 Likes