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

Problems with NodeJS Blynk Library

I have run into some issues with the blynk library for NodeJS. Some things that I think should work after reading the documentation don’t. I am not sure if i am using things correctly, after a lot of research and reading examples it appears that I am.

below is my test script with inline comments as to what works and what doesn’t.

The library also contains some widgets including an LED widget that has turnOn() and turnOff(). These functions do not work. Looking at that code, they use virtual write, the same as my code that does not work.

#!/usr/bin/env node


const Blynk = require('/node_modules/blynk-library');  // Links variable 'Blynk' to the Blynk Library
const AUTH = <authcode her> 
const blynk = new Blynk.Blynk(AUTH, options = {
  connector : new Blynk.TcpClient()
});

// add an LED, label and button in switch mode to the Blynk App
// setup the pins
var LED = new blynk.VirtualPin(2);
var label = new blynk.VirtualPin(1);
var button = new blynk.VirtualPin(0);
var wLED = new blynk.WidgetLED();

button.write(0);

button.on('write', function(param) {  // Watches for  Button
    if (param == 1) {  // Runs the CLI command if the button  is pressed
      console.log('button:', param);

      //this works
      LED.write(255);

   // this does not
     // wLED.turnOn(LED);

      //this does not either
     // blynk.virtualWrite(LED, 255);

      //this works
     label.write("button on")

     //these do not
     // blynk.setProperty(label, "label", "button on");
    //  blynk.setProperty(button, "onColor", "#ED9D00" );
    
  }
  else {
  LED.write(0);
label.write("button off")
console.log('button:', param);
   
  }
  });