OTA and Blynk.begin()

@proietti today I’ve been having some issues with OTA that were very similar to yours. I added OTA into a non-Blynk sketch and couldn’t get the network port to show-up, either in the IDE or Bonjour Browser.

So, I flashed a sketch to the device that I knew worked before, and that didn’t work either. I realised that the only thing that had changed since the last time I used this working sketch was updating the Arduino core.

After quite a lot of head-scratching, searching and experimenting with the OTA example sketches I realised that in both sketches I had ArduinoOTA.begin() before I called my Wi-Fi connection function.

Swapping this around, and putting ArduinoOTA.begin() after my Wi-Fi connection function solved the problem and the port showed-up immediately.

You’ve not actually shared the code that you were using with Blynk.begin, but I think that one of two things are happening:

  1. Your Wi-Fi connection routine is after ArduinoOTA.begin() or
  2. Your Wi-Fi connection routine isn’t sophisticated enough and is failing to create a connection first time around. The actual Wi-Fi connection is then taking place in the void loop, so ArduinoOTA.begin() is actually being called before the Wi-Fi connection is established.

Looking at your code, I think it’s the second scenario that we’re seeing.

With this line un-commented, only one attempt will be made at connecting to Wi-Fi. In my experience that’s not enough, and you’d normally have a loop to keep retying every 500ms or so until you do connect. Of course this will create a blocking process, which is what yo’re trying to avoid.
Maybe a series of tries at connecting before exiting a loop is the best alternative, with maybe the ArduinoOTA.begin() only called if a successful Wi-Fi connection is created?

Hope this helps.

Pete.