Use BLYNK_CONNECTED() to ensure that setProperty() works during initial start up

I created an app some months ago and it was all working fine until I noticed this week that some of the UI elements were not getting set. After looking into the problem I found that calls to setProperty() within the setup() function were not working, yet the exact code called later (via a test button) worked just fine.

I then moved those calls into BLYNK_CONNECTED() and that fixed the problem.

What I find interesting is that there now seems to be some sort of longer delay in the connection status that was not as long before, so my mistake of placing the calls in setup() was masked.

So here is some of the code, hopefully it will help someone down the road if they find that setProperty() is failing during setup()…

const long FW_VERSION = 2019111512 ;      // yyyymmddnn

// this used to be called from within setup() and would fail
void showversion(int pin){
  Blynk.setProperty(pin,"label","Ver " + String(FW_VERSION));
}


// this used to be called from within setup() and would fail
void showNetworkStatus(int pin){
  long rssi = WiFi.RSSI();
  String IP = WiFi.localIP().toString();
  Blynk.setProperty(pin,"label",IP); // put IP address onto Network button
  Blynk.setProperty(pin,"offLabel", String(rssi) + "dBm " + "📶");

}

BLYNK_CONNECTED() {
  // show version of firmware
   showversion(V20);
   showNetworkStatus(V29); // and network status
   Blynk.virtualWrite(V36, " "); // clear connection info

    // set default k83 slider etc
   Blynk.virtualWrite(V23,k83adr);
 
   // set default s88
   Blynk.virtualWrite(V39,s88);
 
}

void setup() {

  Serial.begin(115200);
  WiFi.hostname("CAB");
  WiFi.begin(ssid, password);
  Blynk.config(auth);

// used to call showversion() and showNetworkStatus() here

}