I’m looking for the correct way to set a dashboard button HIGH in the setup part of the code. I’ve tried a simple Blynk.virtualWrite, as well as combining it with a Blynk.run command (both before and after), but the only way I’ve managed to do it is by repeating the commands a few times:
@jamin This is what I tried initially, only with Blynk.config replacing Blynk.begin, since I use WiFiManager to handle the wifi credentials. It didn’t work.
@costas I’m only trying to write a single pin HIGH. The loop is there just because it wasn’t working if I only called it once.
Just to be clear, VPIN is defined as V1, which is also the asignment of my button widget.
The code also seems to work if I put the Blynk.virtualWrite after the FOR loop, but it seems to need the 3X Blynk.run to sort of “jump start” the process.
This is your problem, config is configuration not connection.
I guess that’s why you were trying Blynk.run() in the loop.
I have WiFiManager running so I’ll check what you need.
@chrome1000 in our WiFIManager projects we use the following code to ensure the Blynk connection is live before we start trying to run Blynk functions:
Blynk.config(blynk_token, server); // obtained from WiFiManager
unsigned long blynktimeout = 4000;
unsigned long blynkstart = millis();
while (Blynk.connect() == false) {
if (millis() > blynkstart + blynktimeout){
digitalWrite(TX, HIGH); // active LOW, so OFF
Serial.println(F("Not connected to Blynk"));
break;
}
}
if(Blynk.connect() == true){
Blynk.virtualWrite(V5, LOW);
Blynk.syncVirtual(V5);
digitalWrite(TX, LOW); // active LOW, so ON
}
Aaaaahhhh, thanks, @costas! The Blynk.connect() function is what I needed. I simplified your version a bit, and just allowed it to time out 10 seconds after boot if it’s unable to connect.