OTA and Blynk.begin()

Ok I have now got it working. @PeteKnight you were right the Wi-Fi connection routine was not connecting first time round and hence then skipped the setup again were the ArduinoOTA.begin() is placed. So I removed the ArduinoOTA.begin() & ArduinoOTA.setHostname() into the BLYNK_CONNECTED() function and it now works. Below the code snipped for others to use.

void setup() 
{
  Serial.begin(115200);
  
  WiFi.begin(ssid, pass);
  Blynk.config(auth, server, port);
  //Blynk.begin(auth, ssid, pass);
  Blynk.connect();
  
  pinMode(2, OUTPUT);
  
  timer.setInterval(1000L, UpTime);

  //ArduinoOTA.setHostname("Loss of connection test");  // For OTA
  //ArduinoOTA.begin();  // For OTA
}

BLYNK_CONNECTED() 
{
  Serial.println("Cconnected");
  ReCnctCount = 0;
  rtc.begin();
  ArduinoOTA.setHostname("Loss of connection test");
  ArduinoOTA.begin();  // For OTA
}
3 Likes

Excellent!
This is obviously caused by a change in the ESP core and it would be nice if they fixed this behaviour at some point in the future. In the meantime at least we now understand what’s causing this behaviour and how to work around it.

Pete.

Could you please advise:

  • was this rtc.begin() declared? My Arduino IDE gives a mistake.
  • pinMode(2, OUTPUT) - what is it used for (in the code)?

@John1 i suggest that you start a new “Need help with my project” topic and provide ALL of the information that is requested when you do that.

If you are using Blynk IoT then I’d suggest you read the documentation about BLYNK_WRITE(InternalPinUTC)

This isn’t a Blynk specific function. A quick Google search will show you what it means in the Arduino/C++ coding language.

Pete.