OTA using ESP8266 working but seems to lose configuration after several hours

Hi Blynk Community,

I have a small project using 2 temp sensors up and running using ESP8266 (LOLIN). It’s configured to work with OTA and all is fine.

BUT…after several hours the device goes offline. The only way to recover is to delete the device on the mobile phone (using the Blynk.app) and re-add this device (so go through the complete configuration again)
Then it works again for several hours before going offline again…

I tried already by using another ESP8266 → same problem.
I have another ESP8266 (identical board) in a different OTA project (simular, also temp sensors connected) and this stays nicely online!!!

Also, if I run this project without using OTA…everything works fine, the device stays online!

Output from the board after went offline in the cloud:
07:10:45.957 → / _ )/ /_ _____ / /__
07:10:45.957 → / _ / / // / _ / '/
07:10:45.957 → /
//_, /////_
07:10:45.957 → /
__/ v1.2.0 on ESP8266
07:10:45.957 →
07:10:45.957 → #StandWithUkraine https://bit.ly/swua
07:10:45.958 →
07:10:45.958 →
07:10:45.958 → ----------------------------------------------------
07:10:45.958 → Device: Blynk Zwembad Filtratie-6H9P
07:10:45.958 → Firmware: 0.1.0 (build May 5 2023 06:59:48)
07:10:45.958 → Platform: ESP8266 @ 80MHz
07:10:45.958 → Boot ver: 6
07:10:45.958 → SDK: 2.2.2-dev(38a443e)
07:10:45.990 → ESP Core: 3.1.2
07:10:45.990 → Flash: 4096K
07:10:45.990 → Free mem: 27952
07:10:45.990 → ----------------------------------------------------
07:10:45.990 →
07:10:45.990 → >[431] INIT => WAIT_CONFIG
07:10:46.068 → [504] Hold the button for 10 seconds to reset configuration…
07:10:46.068 →
07:10:46.068 → Waiting for time
07:10:46.068 → .[2215] AP URL: blynk.setup

Parts of the code:

#define BLYNK_TEMPLATE_ID "xxxxxxxxxxxxxxxxx"
#define BLYNK_TEMPLATE_NAME "xxxxxxxxxxxxxxxx"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h
//#define USE_WEMOS_D1_MINI

#include "BlynkEdgent.h"

//#include "time.h"
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <math.h>
#include <ESP8266WiFi.h>

void setup()
void loop()

Thx for ideas!!!

You’ve referred to this as being an OTA issue, but I think you mean that it’s a dynamic provisioning problem - the device is losing its WiFi credentials. Is this correct?

Unfortunately, the snippet of code you’ve posted doesn’t really help, because it doesn’t tell us which pins your sensors are attached to.
One thing that is clear is that you’ve not un-commented a board type as you should, so the custom board configuration in the Settings.h tab is being used.
My guess is that you are using GPIO0 (pin D3 on a Wemos D1 Mini - if that what you mean by a LOLIN board) for something, and this is being pulled LOW for > 10 seconds and this is clearing your credentials.

You should read this, and refer to the actual Settings.h tab in your sketch (the default settings have changed since this was written)…

Do you really need the dynamic provisioning functionality of Blunk Edgent?


Hi Pete,

thx for your troubleshooting info!

Here’s my definition of the pins…as you can see, nearly all are used!

 pinMode(D1, INPUT); //Status Pump  
 //pin 2 = temp sensors
 pinMode(D3, OUTPUT); //Relais Pump    
 pinMode(D4, OUTPUT); //Relais Lights 
 pinMode(D5, INPUT); //Flow Water  
 pinMode(D6, INPUT); //Status Lights
 pinMode(D7, INPUT); //Flow Solar Heating

 //Initialize the Blynk library
 digitalWrite(D3, HIGH);
 digitalWrite(D4, HIGH);

Connected like shown above → if I un-comment the ‘define USE_WEMOS_D1_MINI’ then after uploading the sketch the board keeps on resetting.

Are we allowed to free up this pin? (by commenting out BOARD_BUTTON_PIN)
:slight_smile: I’m trying this now :slight_smile: Seems to be ok…

Regarding the question if I really need the OTA to work…well, it’s a nice option as the ESP will be placed away from my pc later on.

Again thx for the assit!!!

Take a look

Hi Blynk_Coeur,

yes, I know this one…and this is also the reason I connected my relais’s to GPIO0(D3) and GPIO2(D4) as they will never by pulled low during boot.

But from what I understand from Pete, I should not use GPIO0(D3)

1 Like

I didn’t ask if you need OTA ago work, I asked…

Once again, you seem to be mixing-up OTA and Dynamic provisioning.

If you don’t mind hard-coding your WiFi SSID and password in your sketch then there are much simpler ways to enable the use of Blynk.Air OTA than using the Edgent example.

That comment tells me you haven’t really read and understood the link I provided, but that’s irrelevant if you move away from Blynk and simply add-in the Blynk.Air code to a regular Blynk sketch.


Hi Pete,

ok, I mixed up OTA and Dynamic provisioning (I had to look this one up!)
Call me stupid, but I started with this only 3 weeks ago :frowning:

Can you please provide (like you said) the simpler way to enable he use of Blynk.Air OTA as I can find only documentation that starts from the Edgent example.


Here you go…



yes, I found that link already but don’t understand how to integrate this in my sketch.

But you’re right about the pins I used…I’ve seen the system crash while switching on/off pin D3.

I’ll stick with the stable non-OTA version…if updates are needed I’ll use a notebook to link it directly to the usb port.

Anyway, thx for the proposed solutions!


If you post your non-Edgent sketch then we’ll show you how to integrate it.


Ok, here you go:

#define BLYNK_PRINT Serial

/* Fill in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "xxxxxxxxxxxxxxxx"
#define BLYNK_TEMPLATE_NAME "xxxxxxxxxxxxxxxxxxxxx"
#define BLYNK_AUTH_TOKEN "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

#include <NTPClient.h>
#include <WiFiUdp.h>
#include <math.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// Your WiFi credentials.
char ssid[] = "test;
char pass[] = "test2023";

const long utcOffsetInSeconds = 7200;

// Define NTP Client to get time
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);

//eigen code
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port D2 on the ESP8266
#define ONE_WIRE_BUS D2
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
float tempSensor1, tempSensor2;
uint8_t sensor1[8] = { 0x28, 0xC0, 0x14, 0x81, 0xE3, 0xE1, 0x3C, 0x3B  }; 
uint8_t sensor2[8] = { 0x28, 0x2D, 0xCF, 0x81, 0xE3, 0xE1, 0x3C, 0x76  }; 

int temp1;
int temp2;
int relais1_on;
int relais2_on;
int StatusPomp;
int StatusLamp;
int StatusFlow;
int StatusFlowHeating;
int AutoMan = 1;
int Shedule;
int CurrentHour; 
int Hour_Org;
int shedule_change_occured = 0;
int pomp_is_aan = 0;
int Solar_Active = 0;
int avoid_repeat = 0;
int avoid_repeat_after_end_timer = 0;
int aliveandkicking = 0;
int flow_check;

unsigned long eventTime =  18000000;
unsigned long previousTime = 0;

static unsigned long REFRESH_INTERVAL1 = 0;
static unsigned long lastRefreshTime1 = 0;
unsigned long currentTime_start_solar = 0;
unsigned long currentTime_stop_solar = 0;
unsigned long currentTime = 0;
long int pompTime_solar = 0;

void setup()

  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);



  Blynk.virtualWrite(V7, 1); 
  AutoMan = 1;
  Shedule = 5;
  Blynk.virtualWrite(V8, Shedule); 
  Blynk.virtualWrite(V9, 0);

  pinMode(D1, INPUT); //Status Pomp  
  //pin 2 = temp sensors
  pinMode(D3, OUTPUT); //Relais Pomp    
  pinMode(D4, OUTPUT); //Relais Lampen)   
  pinMode(D5, INPUT); //Flow Water  
  pinMode(D6, INPUT); //Status Lampen
  pinMode(D7, INPUT); //Flow Solar Heating

  //Initialize the Blynk library
  digitalWrite(D3, HIGH);
  digitalWrite(D4, HIGH);
  configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");
  Serial.println("\nWaiting for time");
  while (!time(nullptr)) {

void loop()
  currentTime = millis();

  maintainDisplay(); // update Blynk met tempsensor/inputs (status pomp/lamp + flow water)


This can’t be your complete sketch, because you’re calling a function from within your void loop called maintainDisplay() that doesn’t exist in the sketch.

Depending on what is in this maintainDisplay() function you could be breaking several Blynk golden rules, but you certainly shouldn’t have this in your void loop, it should be called with a Blynk Timer.

You should probably get your time from the Blynk server too, instead of using an NPT server.

Having Blynk.virtualWrites in your void setup inst a good idea, they very rarely work as expected. You’d be better putting them in a BLYNK_CONNECTED() function to run once once the Blynk connection is actually established correctly.

As far as integrating Blynmk.Air OTA is concerned, you just put these three lines up at the top of your sketch with the other #includes and global variable definitions…

include <Update.h>
#include <HTTPClient.h>

String overTheAirURL = "";

and just tag the rest of the code on to the end of your sketch.

You should also add this near the top of your sketch…


and replace “x.x.x” with numbers like “0.0.1” that you increment in your sketch before compiling it and attempting to deploy via OTA.


waauw…I was just reading your post: My home automation projects built with MQTT and Node Red

I even didn’t know that you could integrate Blynk in node-red

I had the project close to ready in node-red with a Raspberry Pi4 but as I fell in love with the way you can control everything from anyware by using Blynk…I switched to Arduino.

Hmm, messy!

All of this millis() comparison stuff is very messy, especially when you do nested calls.
You’d be far better using a BlynkTimer to call a function which checks if your various on/off schedules are active or not.
It seems that you aren’t using the Blynk Time Input widget to input your start/stop times?

If your already using Node-Red then I’d probably use Node-Red as my rules engine, with the BigTimer contrib to manage your schedule and use MQTT messaging to communicate with your device (no Blynk code).
Then I’d use Blynk as the primary UI to see the current status, switch between auto and manual override and maybe input changes to your schedule.


A lot of stuff to think about!

Thx Pete!!!

I have problems finding the Update.h library, could you give me some details? Thank you

Update.h is part of the ESP32 core files, so will be installed automatically with the ESP32 core package.

If you’re wanting to do the minimal OTA with an ESP8266 then the files you’ll need to include are:

#include <ESP8266HTTPClient.h>  // For HTTP updates
#include <ESP8266httpUpdate.h>  // For HTTP updates


Thanks Pete