Blynk + Web browser OTA update = disconnect?

Hello everybody!

It’s my first post here so at the beginning I want to introduce myself :smile:
My name is Radek and I’ve used Blynk in 2 of my projects for now, one to operate my gate opener and one to read temperature values from my furnance.

But back to the issue I have, after a few trips to my basement with the laptop and cable I’ve decided to implement OTA update in my code, after some research (on this forum of course :slight_smile:) I’ve integrated Web Browser OTA code into my Blynk sketch.
And everything worked fine at the beginning, temps in the app were correct and I was able to upload sketch through web browser, but after a few hours I’ve noticed that “Device was disconnected.” message pops up in the app every few seconds.
I know what you are thinking right now “another guy that uses Delays or stuffed a lot of instructions in the Loop function” :wink: but my loop function looks like this:

void loop()

It looks like httpServer.handleClient(); is causing some delays and my device is considered as offline by the server, is that correct? Is there a way to solve this?

Thanks in advance.

Oh, by the way my device is NodeMCU v2, and if all of the code is needed I will post it here, just let me know.

1 Like

but what does httpServer.handleClient(); exactely do?
why you need it?

for the standard “ota via local wifi”, there are other implementations…

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

const char* ssid = "..........";
const char* password = "..........";

void setup()
  WiFi.begin(ssid, password);
  // Port defaults to 8266
  // ArduinoOTA.setPort(8266);

  // Hostname defaults to esp8266-[ChipID]
  // ArduinoOTA.setHostname("myesp8266");

  // No authentication by default
  // ArduinoOTA.setPassword("admin");

  // Password can be set with it's md5 value as well
  // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
  // ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");


void loop()

or see arduino ide > file > examples > arduino ota > basic ota for more details.

1 Like

Yeah, you are talking about Classic OTA Update, through Arduino IDE, but that wasn’t working consistently for me, and thanks to web browser update i was able to upload sketch to ESP using my android device :grin: (loading sketch to phone memory before of course)
I took inspiration from

ok, i see.
but why classic ota didn’t work for you? probably millions esp8266 boards use it without problems…

just my opinion, it would be better to debug why ota is not working for you as expected, than upload code from ide to phone and from phone to mcu every time.

1 Like

I’m sorry for the writing, I’m on the phone.
Try to put a condition on the loop to execute handleclient().
I added a push button widget on my project to execute the web update.
When I press the button, my sketch execute the webupdate.

Now I’m on a PC, and I can explain better:

On order to avoid what happens to you I did the following on my project and sketch.

I created a push button widget on Blynk (V15 in my case), and this is my sketch related to web update:

int updateWeb;

void setup()
  updateWeb = 0;

BLYNK_WRITE(Update_Firmware) // Activa Busqueda y ejecución de actualización de firmware
    int pinData = param.asInt();
    updateWeb = pinData;
    if ( updateWeb == 1 )
       terminal.println(F("Inicia Actualización"));
       terminal.print("MAC: ");
       terminal.println(F("Debe estar conectado a la misma"));
       terminal.println(F("red wifi del controlador."));
       terminal.println(F("Abra el siguiente enlace y luego"));
       terminal.println(F("seleccione el archivo y presione UPDATE"));
       terminal.print( WiFi.localIP());
       Blynk.disconnect(); // suggested to avoid problems
       MDNS.addService("http", "tcp", 80);

void loop()
  if ( updateWeb == 1 )

It makes sense to you?


Yes, it makes sense, in fact I did something similar before but it didn’t help.
But your sketch is slightly different, you are setting up MDNS in the BLYNK_WRITE function, in my previous sketch i left this in the Setup function (BLYNK_WRITE was used only to assign value to my updateWeb variable) and you also uses Blynk.disconnect();.

I will check your solution as soon as I will return to home and I will let you know.

Thanks :slight_smile:

Just tested, works like a charm :relieved:

Thanks a lot Irossel!


The reason why it does not work in the function, is because you are making a new instances everytime of the MDNS and Httpupdater. Multiple instances will be started and will at the end create stack problems and uncontrollable behavior. So keep de httpupdater.setup and MDNS.addservice etc in the setup();

1 Like