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

Set default values for some of my Widgets

#1

Hi Blynkers,

I want to set default values for some of my widgets each time the project is run in the Blynk App. Types of widgets used are menu (4 selections), button (on/off) and segmented switch settings (5 selections). What I want to achieve is to always have the widgets revert to the following defaults each time it is run : the first option of the menu selected, Off for the button and option 3 selected for the segmented switch, even though the selections might have changed from a previous run session.

Code is written in nodejs. Snippet of code below :

var v0 = new.blynk.VirtualPin(0); // menu selection
var v1 = new.blynk.VirtualPin(1); // Button
var v2 = new.blynk.VirtualPin(2); // segmented switch

blynk.setProperty(v0, “label”, “menu”, “min”, 1)
blynk.setProperty(v1, “label”, “State”, “min”, 0)
blynk.setProperty(v2, “label”, “menu”, “min”, 3)

Above setProperty does not seem to work. How and what is the correct method to do what I intend. Or am I using the wrong command?

Thanks,
Alan

0 Likes

#2

@alantch: If I understand the description correctly you don’t want to change lables and limits but set values.
In this case blynk.setProperty() would not be an option.

My suggestion:

BLYNK_APP_CONNECTED() 
{
  blynk.virtualWrite(V0, 1);
  blynk.virtualWrite(V1, 0);
  blynk.virtualWrite(V2, 3);
}

Have not tested it, but could work … :wink:

0 Likes

#3

@IBK, that was what I did initially, but it did not work. So I tried setProperty and that did not work as well.

0 Likes

#4

@alantch: I don’t use nodejs. But I just tested with an Arduiono Mega and it works for all three types of widgets that you use.

One more thing:
For using BLYNK_APP_CONNECTED() you need to have “Notify device when app connected” in the “Project settings” swichted on.

0 Likes

#5

What happened? Error? Anything? With NodeJS you do NOT use the V when referencing the vPin in the command… it should throw an error if you do.

I use this command to change the “intensity” of a virtual LED on V10, with vOrangeLEDintensity being a slider provided range of 0-255

blynk.virtualWrite(10, parseInt(vOrangeLEDintensity));

0 Likes

#6

With NodeJS - as per this example…

The correct syntax is more like this (for server connection)…

blynk.on('connect', function() {
  blynk.virtualWrite(0, 1);
  blynk.virtualWrite(1, 0);
  blynk.virtualWrite(2, 3);
});

Don’t know if there is an APP CONNECTED option yet.

1 Like

#7

@Gunner, your suggestion worked. Thanks for the help. I just wonder why there is so much less projects in Blynk using nodejs. Its kinda hard looking for code examples.

1 Like

#8

I have a few simple ones here…

0 Likes

#9

@Gunner, very nice of you to do this for the community. I do refer to it and the nodejs / javascript reference too every now and then. Your efforts are much appreciated.

0 Likes

#10

Refer?

1 Like

#11

Good catch. Corrected. Thanks.

0 Likes

#12

Is this option available already?

0 Likes

#13

I couldn’t tell you… I am not the developer.

EDIT - you can look at the GitHub files yourself. It seems something changed around 4 months ago…

0 Likes