ESP 12 worked fine, now disconnects all the time. Server error?

Hi all,

Ive been using blynk server with ESP12 for a 3 month and it woas working excelent until 2 days ago when it started to reset every few minutes.

Connection to wifi is stable but it drops conn with blynk server and usualy it timesout. So I have to reset it hard to begin conn again. It’s been like this for 2-3 days. Haven’t changed anythign to code or to hardware.

Is there any changes to server connestion ot are there any problems with servers.

I am seriously thinking of running my one stand alone server as my device is dependent on internet now. It would be better not to be.

It home heating and automation system in development.

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//#include <IRremote.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#include <SPI.h>

#define DHTPIN 14     // what digital pin we're connected tonclude <SD.h>
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321

//const int RECV_PIN = 1;
//IRrecv irrecv(RECV_PIN);
//decode_results results;

#define chMinus  16753245   // code received from button 1
#define chPlus  16769565   // code received from button 2
#define ch 16736925 // CH button
#define play 16761405 //play green button
#define eqButton 16748655


float temperatura;
float tempRoom;
float tempBoiler;
float tempDebug;
float tempMobile;
int rHum;
float hic;


bool lcdLightFlag = 1;

float tempSet;
float tempMin;
float tempMax;

float tempDifference = 0.6;

float tempSetDay = 22;
float tempMinDay;

float tempMaxDay = 28;

float tempSetNight = 20;
float tempMinNight;
float tempMaxNight = 25;

bool isconnected;

int hours;
int minutes;

int wifiPeriod = 10000;
//unsigned long time_now = 0;
unsigned long lastTime = 0;
unsigned long currentMillis;
unsigned long lastMillis;
bool autoMode;
bool blockMode;
bool manualMode;
bool nightMode;

bool heating = LOW;
bool pump = 0;

int i = 0;

#define relay  16
#define greenLed  24
#define redLed 26
#define yellowLed 9
//#define lcdLight 16


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
//char auth[] = "e48226e5b8b34febbf44cf7238311418"; // samo za mobile temo
char auth[] = "06ef7c80b1b24d68993de96e2baf21af";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "HUAWEI-B315-31B5";
char pass[] = "089HG42D289";


// Create a Onewire Referenca and assign it to pin 6 on your Arduino
OneWire oneWire(12);

// declare as sensor referenec by passing oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);


BlynkTimer timer;
DHT dht(DHTPIN, DHTTYPE);
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
DeviceAddress tempSensorOut = {0x28, 0xFF, 0xF6, 0xA6, 0x62, 0x16, 0x4, 0x1F};
DeviceAddress tempSensorDebug = {0x28, 0xFF, 0x87, 0xA, 0x63, 0x16, 0x4, 0xAF};


void setup()
{
  // Debug console
  Serial.begin(9600);

  //Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
  pinMode(relay, OUTPUT);
  digitalWrite(relay, HIGH);
  //  pinMode(lcdLight, OUTPUT);
  // Setup a function to be called every second
  dht.begin();
  lcd.begin(20, 4);
  // irrecv.enableIRIn();
  //timer.setInterval(1000L, printTemp);
  sensors.setResolution(tempSensorOut, 11);
  sensors.setResolution(tempSensorDebug, 11);
  Serial.print("Sensor Resolution Out: ");
  Serial.println(sensors.getResolution(tempSensorOut), DEC);
  timer.setInterval(2000L, checkConn);
  timer.setInterval(5000L, reseting);


}

BLYNK_CONNECTED()
{
  //Blynk.syncAll();
  Blynk.syncVirtual(V8);
  Blynk.syncVirtual(V1);
  Blynk.syncVirtual(V2);
  Blynk.syncVirtual(V3);
  Blynk.syncVirtual(V12);
  Blynk.syncVirtual(V13);
}


void checkConn()
{
  currentMillis = millis() / 1000;
  isconnected = Blynk.connected();
  //Serial.println("CurrentMillis");
  //Serial.println(currentMillis);



  modeSelection();
  printTemp();

  printLcd();
  sendToBlynk();
  serialPrint();


}

void reseting()
{

  if (isconnected == false)
  {

    Blynk.connect();

    i = i + 1;
    lcd.setCursor(8, 3);
    lcd.print(i);
  }

  //if (currentMillis == lastMillis) ESP.reset();

  /*if (isconnected== true)
     {
     Blynk.syncAll();
     }*/

  if (i == 5)
  {
    i = 0;

    if (isconnected == false)
    {
      i = 0;
      lcd.setCursor(6, 3);
      lcd.print("Reseting");
      Serial.println("Reseting");
      ESP.reset();
    }


  }

  Serial.print("i=");
  Serial.println(i);
  //lastMillis=millis()/1000;
  //Serial.print("LastMillis iliti reseting");
  //Serial.println(lastMillis);



}

/*void remote()
  {
  if (irrecv.decode(&results)) //this checks to see if a code has been received
  {
    unsigned int value = results.value;
    switch (value) {

      case chMinus:
        autoModeF();
        break;

      case ch:
        manualModeF();
        break;

      case chPlus:
        blockModeF();
        break;

      case play:
        nightModeF();
        break;

      case eqButton:
        lcdLightFlag = !lcdLightFlag;
        break;
    }

    Serial.println(value);
    irrecv.resume(); //receive the next value

  }
  }
*/
void sendToBlynk()
{
  //send to blynk
  Blynk.virtualWrite(V5, millis() / 1000);
  Blynk.virtualWrite(V6, tempRoom);
  Blynk.virtualWrite(V4, tempBoiler);
  Blynk.virtualWrite(V7, pump);
  Blynk.virtualWrite(V0, tempSet);
  Blynk.virtualWrite(V3, nightMode);
  Blynk.virtualWrite(V2, blockMode);
  Blynk.virtualWrite(V1, manualMode);
  Blynk.virtualWrite(V8, autoMode);
  //Blynk.virtualWrite(V11, tempMobile);
  Blynk.virtualWrite(V12, tempSetDay);
  Blynk.virtualWrite(V13, tempSetNight);
}

void printLcd()
{
  //LCD PRINT
  //String displayDate = rtc.getDateStr();
  //String displayTime = rtc.getTimeStr();

  unsigned long upTime = millis() / 1000;
  lcd.setCursor(0, 0);
  lcd.print("RH");
  lcd.setCursor(3, 0);
  lcd.print("     ");
  lcd.setCursor(3, 0);
  lcd.print(rHum);
  lcd.setCursor(8, 0);
  lcd.print(tempRoom);
  lcd.setCursor(15, 0);
  lcd.print(tempBoiler);
  lcd.setCursor(0, 1);
  lcd.print(tempMin);
  lcd.setCursor(8, 1);
  lcd.print(tempSet);
  //lcd.setCursor(15, 1);
  //lcd.print(tempMobile);

  if (isconnected == true)
  {
    lcd.setCursor(13, 3);
    lcd.print(" ONLINE");
  }
  else
  {
    lcd.setCursor(13, 3);
    lcd.print("OFFLINE");
  }


  lcd.setCursor(0, 3);
  lcd.print(upTime);

  if (autoMode == 1 && nightMode == 0)
  {
    lcd.setCursor(0, 2);
    lcd.print("                ");
    lcd.setCursor(8, 2);
    lcd.print("AUTO");
  }
  if (manualMode == 1)
  {
    lcd.setCursor(6, 2);
    lcd.print("          ");
    lcd.setCursor(6, 2);
    lcd.print("MANUALNO");
  }
  if (blockMode == 1)
  {
    lcd.setCursor(6, 2);
    lcd.print("          ");
    lcd.setCursor(6, 2);
    lcd.print("BLOKADA");
  }

  if (pump == 1)
  {
    lcd.setCursor(17, 2);
    lcd.print("   ");
    lcd.setCursor(18, 2);
    lcd.print("ON");
  }
  else
  {
    lcd.setCursor(17, 2);
    lcd.print("   ");
    lcd.setCursor(17, 2);
    lcd.print("OFF");
  }

  if (nightMode == 1)
  {
    lcd.setCursor(6, 2);
    lcd.print("         ");
    lcd.setCursor(8, 2);
    lcd.print("NIGHT");
  }

}

void printTemp()
{

  //t = rtc.getTime();
  //hours = t.hour;
  //minutes = t.min;

  //Serial.println(isconnected);

  // Tell the Sensor to Measure and Remember the Temperature it Measured
  sensors.requestTemperaturesByAddress(tempSensorDebug); // Send the command to get temperatures
  //tempRoom = sensors.getTempC(tempSensorRoom);
  tempRoom = sensors.getTempC(tempSensorDebug);
  sensors.requestTemperaturesByAddress(tempSensorOut);
  tempBoiler = sensors.getTempC(tempSensorOut);
  //feels like
  hic = dht.computeHeatIndex(tempRoom, rHum, false);

  //tempRoom = dht.readTemperature();
  //rHum = dht.readHumidity();
  temperatura = tempRoom;

}

//termostat flags

void autoModeF()
{
  autoMode = 1;
  blockMode = 0;
  manualMode = 0;
  nightMode = 0;
  lcdLightFlag = 1;

}

void blockModeF()
{
  blockMode = 1;
  autoMode = 0;
  manualMode = 0;
  nightMode = 0;

}

void manualModeF()
{
  manualMode = 1;
  blockMode = 0;
  autoMode = 0;
  nightMode = 0;
}

void nightModeF()
{
  nightMode = 1;
  manualMode = 0;
  blockMode = 0;
  autoMode = 0;
  lcdLightFlag = 0;


}


void serialPrint ()
{

  //print status to serial
  //Serial.print(String((char*)rtc.getDateStr()) + ", " + String((char*)rtc.getTimeStr()) + ", ");
  Serial.println ("H" + String(rHum) + ", R" + String(tempRoom) + ", M" + (tempMobile) + ", B" + String(tempBoiler) + ", A" + String(autoMode) + ", M" + String(manualMode) + ", B" + String(blockMode) + ", N" + nightMode + ", P" + pump + ", " + (tempSet) + ", " + (tempMin) + ", CONN " + isconnected);
  Serial.println(tempDebug);
}



void termostatFunction ()
{
  //termostat function

  if (tempRoom >= tempSet) //if room temperature is  over or = set temp
  {
    offF();
  }
  else if (tempRoom <= tempMin) //if room temp is below set temp
  {
    onF();
  }


  if (tempRoom >= tempMax) //turn all off is temp is over set absolute max
  {
    blokada();
  }

}

void modeSelection()
{

  if (autoMode == 1)
  {
    dayMode();
    termostatFunction();
  }

  else if (manualMode == 1) manOn();

  else if (blockMode == 1) blokada();

  else if (nightMode == 1)
  {
    nightModeSetings();
    termostatFunction();
  }


}

void dayMode()
{
  tempSet = tempSetDay;
  tempMin = tempSetDay - tempDifference;
  tempMax = tempMaxDay;
  //digitalWrite (lcdLight, lcdLightFlag);
}

void nightModeSetings()
{
  tempSet = tempSetNight;
  tempMin = tempSetNight - tempDifference;
  tempMax = tempMaxNight;

  //  digitalWrite (lcdLight, lcdLightFlag);

}

void offF()
{

  heating = LOW;
  digitalWrite(relay, HIGH);
  pump = 0;
}

void onF()
{
  heating = HIGH;

  if (tempBoiler >= 45)
  {
    digitalWrite(relay, LOW);
    pump = 1;
  }
}

void manOn()
{
  if (tempBoiler >= 45)
  {
    digitalWrite(relay, LOW);
    pump = 1;
  }
}

void manOff()
{
  digitalWrite(relay, HIGH);
  digitalWrite(redLed, HIGH);
  pump = 0;
}

void blokada()
{
  digitalWrite(relay, HIGH);
  heating = 0;
  pump = 0;
}

void ledControl()
{
  digitalWrite(greenLed, autoMode);
  digitalWrite(redLed, blockMode);
  digitalWrite(yellowLed, manualMode);
}

BLYNK_WRITE(V1)
{
  int  V2Manual = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (V2Manual == 1)
  {
    manualModeF();
  }


  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  Serial.print("Manualno: ");
  Serial.println(V2Manual);
}

BLYNK_WRITE(V2)
{
  int  V2Block = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (V2Block == 1)
  {
    blockModeF();
  }


  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  Serial.print("Blokada: ");
  Serial.println(V2Block);
}

BLYNK_WRITE(V3)
{
  int  V3Night = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (V3Night == 1)
  {
    nightModeF();
  }


  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  Serial.print("Night: ");
  Serial.println(V3Night);
}

BLYNK_WRITE(V8)
{
  int  v8Auto = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (v8Auto == 1)
  {
    autoModeF();
  }
  Serial.print("Auto: ");
  Serial.println(v8Auto);
}

BLYNK_WRITE(V12)
{
  tempSetDay = param.asFloat(); // assigning incoming value from pin V12 to a variable
  Serial.print("tempSetDay: ");
  Serial.println(tempSet);
}

BLYNK_WRITE(V13)
{
  tempSetNight = param.asFloat(); // assigning incoming value from pin V1 to a variable
  Serial.print("tempSetNight: ");
  Serial.println(tempSetNight);
}


void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
  //  remote();
}
1 Like

Is the ESP rebooting when this happens?
Could be a faulty PSU.

Pete.

Yes it does sometimes. You think it could be power source? Hmm. Why and how if i haven’t touched it. I’ll check it
Thx

It could be that the PSU was marginal anyway, and may have deteriorated due to component failure or tolerance changes caused by heat.
What reboot code does your ESP show in the serial monitor when it restarts?

Pete.

Hmm now I remembered. I made a part of code reboot esp after 4 disconnects because when heartbeat timeout happens (3 conections) esp is not reconnecting automatically until rebooted. But for now only error i get is heartbeat timeout and then connecting to blynk cloud 80. Internet is working fine. Close to router. Don’t know…

You need to post your code.

Pete.

Thx

I was at job when I posted first time. I edited the first post with code.

I do believe this is faulty device. There is a 700mA power suply with both 5V and 3.3V output. Only one relay is conected to ESP but relays are powered separately.

One thing that leaps out at me is this bunch of consecutive Blynk.virtualWrites:

Try splitting them into two functions and calling them at slightly different times.

Also, GPIO 16 probably isn’t the best pin to use for your relay, and GPIOs 24, 26 & 9 don’t exist on the ESP (I do realise that you’re not using these at the moment, but just saying).
Have you read this:

Pete.

Thanks for a fast reply. Unfortunately I had only that one pin free for relay. That’s why I am planing to take nano with esp01 and recreate everything. Yes those pins are not in use bit they don’t make problem.

What I noticed is that when I reflash it it works stable for few hours.

I did multiple digital writes because syncAll didn’t do the job. I’ll just switch to nano. I have a gut feeling something is wrong with the node it self.

I’ll read about pins… And let you know the solution.

So what else do you have connected to your ESP that are taking-up the other pins?

sounds like a backward step to me!

Pete.

1 Like

I am planning to get an esp32 to replace my nodemcu !

Meanwhile, some people enjoy a challenge and want to know why their steam powered difference engine isn’t on the Blynk supported hardware list…

image

Seriously though, there are cases where Arduino boards linked to ESP-01’s are a sensible choice of hardware, but I wouldn’t choose that setup for a home automation heating controller. A NodeMCU or two should do the trick.

I have a few ESP-32s kicking around, but haven’t got around to trying them in any real world projects yet. I like my Wemos D1 Minis too much :heart:

Pete.

5 Likes

:rofl::rofl::rofl: :steam_locomotive:

D1 mini is really a good choice.
New nodemcu ESP32S provide 32 I/O and has a dual core.
This is why I’ll replace my 2 NodeMcu by one esp32.
I plan to get the plateforme développement one, so no need breadboard no more USB power supply.
All that for only 6$ :heart_eyes::heart_eyes:

1 Like

@Blynk_Coeur, do you have a link to this board?

Pete.

2 Likes

Lcd screen 20x4, ds1820, relay.
As you can see in the code there was a IR receiver so I could set it up via remote. But that was impossible to integrate in this nodeMCU. Now there is not enought pins to plug it. Il check this D1 mini (but it looks like it have only 10IO) …I need somthing with lot of IO pins, wifi, stable and programable via arduino IDE.

I read that ESP32 is more complicated to flash and to setup arduino IDE?

I just read the list and it looks like there are only 5 stable available pins. Can’t work with that. I need at least 5 more. I am planing to add TFT screen that uses 8 pins. IR 1, DS 1. It would be great to have interrupt pin for IR remote. It would be awsome to add a button or to when all other fail.

That’s the worst combination I can think of. ESP-01’s are trash and you need all the extra components.

It is more complicated and even though I have half a dozen I do all my work with WeMos D1 mini’s.

At $3 a pop you can you buy a bag full of WeMos’ and bridge them together. I bought about half a dozen port expanders for my WeMos’. I think they were about a dollar a piece but I have never used them, just there in case I ever need them.

Everyone has a smartphone these days so I see physical LCD’s as a waste of effort. I have a couple but again I never use them.

WeMos rocks :slight_smile:

1 Like

If you build a project with an Arduino it’s not a true iOT project as it can’t be updated remotely like you can with a WeMos.