Smart Home

Hello I am making a smart home application using ESp8266-01 with my UNo.

I don’t know how to use timers with blynk, so whenever I code i get the buffer overflow of flood error. Can someone please help me with the code?

//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_SoftSer.h>
#include <BlynkSimpleShieldEsp8266_SoftSer.h>
#include <dht.h>
#include <SimpleTimer.h>
dht DHT;
WidgetLCD lcd(V3);
int nRainVal;
#define DHT11_PIN 5 // DHT11 PIN FOR NOW
int nRainIn = A1;
int nRainDigitalIn = 9;
// Set ESP8266 Serial object
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
ESP8266 wifi(EspSerial);
SimpleTimer timer;
char auth[] = "";
void sendUptime()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
}
void setup()
{
  // Set console baud rate
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  // 9600 is recommended for Software Serial
  EspSerial.begin(9600);
  delay(10);

  Blynk.begin(auth, wifi, "net_9718015549call", "macbeth123" );
}
void temp(){
  int chk = DHT.read11(DHT11_PIN);
    Blynk.virtualWrite(0, DHT.temperature);  // Write values to the app
  Blynk.virtualWrite(1, DHT.humidity);
    
}
void rain() {
   Blynk.virtualWrite(2, nRainVal);
     lcd.clear();
  if (nRainVal< 550)
  {
       lcd.clear(); //Use it to clear the LCD Widget
  lcd.print(4, 0, "Raining"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  lcd.print(4, 1, "Heavily!");
  Blynk.notify("");
  Blynk.tweet("");
 // Blynk.email("kaustubhagarwal18@gmail.com","Subject","Message");
  }
  if (nRainVal> 700 && nRainVal < 1000)
  {
      lcd.clear(); //Use it to clear the LCD Widget
  lcd.print(4, 0, "Rain"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  lcd.print(4, 1, "Warning!");
  
  Blynk.notify("");
  Blynk.tweet("");
  delay(1500);
  //Blynk.email("kaustubhagarwal18@gmail.com","Subject","Message");
  } 
    if (nRainVal> 1000)
  {
       lcd.clear(); //Use it to clear the LCD Widget
  lcd.print(4, 0, "No"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  lcd.print(4, 1, "Rain!!");
  Blynk.notify("No");
  }

}

void loop()
{
  Blynk.run();
  timer.run();
  temp();
  rain();
  delay(1000);
}

@Lichtsignaal @Costas ?

Remove delays and also the empty blynk.notify & blynk.tweet

Done. No improvement.

remove rain() and temp() functions from the loop.

Look at the PushData example which comes with the Blynk library. It has an example of how to use SimpleTimer.

@KAUSTUBHAGARWAL I found the very best way of avoiding flood errors was to throw the Arduino Uno / Nano and ESP-01’s in the bin and ask Ebay / AliExpress to send me some decent hardware.

If you have plenty of time to waste then your fix is at https://github.com/blynkkk/blynk-library/blob/master/examples/GettingStarted/PushData/PushData.ino#L30

I know how that feels but I have a submission on the weekend and I can’t afford a new hardware right now. I also want to get rid of this, but I have no choice as of now.

@KAUSTUBHAGARWAL ok let’s take the sendUptime function example:

void sendUptime()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
} 

Having included the SimpleTimer libraries etc rain() would be:

void setup()
{
  // normal setup stuff
  timer.setInterval(1000L, rain);  // 1 sec interval, 10000L would be 10 secs etc
}

void rain()
{
   // do something
}

Full details for SimpleTimer are available at http://playground.arduino.cc/Code/SimpleTimer

More to follow…

Same problem after sometime(approx 2 mins). This is the new code

//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_SoftSer.h>
#include <BlynkSimpleShieldEsp8266_SoftSer.h>
#include <dht.h>
#include <SimpleTimer.h>
dht DHT;
WidgetLCD lcd(V3);
int nRainVal;
#define DHT11_PIN 5 // DHT11 PIN FOR NOW
int nRainIn = A1;
int nRainDigitalIn = 9;
// Set ESP8266 Serial object
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
ESP8266 wifi(EspSerial);
SimpleTimer timer;
char auth[] = "";

void sendUptime()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V0, millis() / 1000);
  Blynk.virtualWrite(V1, millis() / 1000);
  Blynk.virtualWrite(V2, millis() / 1000);
  Blynk.virtualWrite(V3, millis() / 1000);
}

void setup()
{
  // Set console baud rate
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  // 9600 is recommended for Software Serial
  EspSerial.begin(9600);
  delay(10);

  Blynk.begin(auth, wifi, "net_9718015549call", "macbeth123" );
}
void loop()
{
  Blynk.run();
  timer.run();
  

  int chk = DHT.read11(DHT11_PIN);
    Blynk.virtualWrite(0, DHT.temperature);  // Write values to the app
  Blynk.virtualWrite(1, DHT.humidity);
    


   Blynk.virtualWrite(2, nRainVal);
     lcd.clear();
  if (nRainVal< 550)
  {
       lcd.clear(); //Use it to clear the LCD Widget
  lcd.print(4, 0, "Raining"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  lcd.print(4, 1, "Heavily!");
 // Blynk.email("kaustubhagarwal18@gmail.com","Subject","Message");
  }
  if (nRainVal> 700 && nRainVal < 1000)
  {
      lcd.clear(); //Use it to clear the LCD Widget
  lcd.print(4, 0, "Rain"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  lcd.print(4, 1, "Warning!");
  
  //Blynk.email("kaustubhagarwal18@gmail.com","Subject","Message");
  } 
    if (nRainVal> 1000)
  {
       lcd.clear(); //Use it to clear the LCD Widget
  lcd.print(4, 0, "No"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  lcd.print(4, 1, "Rain!!");
  //Blynk.notify("No");
  }

}


I have some LED hooked up, their response time is also very slow

@KAUSTUBHAGARWAL 2 lines only in loop, move everything else.

You are not using SimpleTimer correctly as you don’t have the relevant details in setup.

Study what is being provided by the Blynk community rather than making your own stuff up.

No error for 5 mins. But sometimes the response is slow

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_SoftSer.h>
#include <BlynkSimpleShieldEsp8266_SoftSer.h>
#include <dht.h>
#include <SimpleTimer.h>
dht DHT;
WidgetLCD lcd(V3);
int nRainVal;
#define DHT11_PIN 5 // DHT11 PIN FOR NOW
int nRainIn = A1;
int nRainDigitalIn = 9;
// Set ESP8266 Serial object
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
ESP8266 wifi(EspSerial);
SimpleTimer timer;
char auth[] = "";

void sendUptime()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V0, millis() / 1000);
  Blynk.virtualWrite(V1, millis() / 1000);
  Blynk.virtualWrite(V2, millis() / 1000);
  Blynk.virtualWrite(V3, millis() / 1000);
}

void setup()
{
  // Set console baud rate
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  // 9600 is recommended for Software Serial
  EspSerial.begin(9600);
  delay(10);
 Blynk.begin(auth, wifi, "net_9718015549call", "macbeth123" );
  timer.setInterval(1000L, rain);
  timer.setInterval(1000L, tempe);
}
void rain()
{

   Blynk.virtualWrite(2, nRainVal);
     lcd.clear();
  if (nRainVal< 550)
  {
       lcd.clear(); //Use it to clear the LCD Widget
  lcd.print(4, 0, "Raining"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  lcd.print(4, 1, "Heavily!");
 // Blynk.email("kaustubhagarwal18@gmail.com","Subject","Message");
  }
  if (nRainVal> 700 && nRainVal < 1000)
  {
      lcd.clear(); //Use it to clear the LCD Widget
  lcd.print(4, 0, "Rain"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  lcd.print(4, 1, "Warning!");
  
  //Blynk.email("kaustubhagarwal18@gmail.com","Subject","Message");
  } 
    if (nRainVal> 1000)
  {
       lcd.clear(); //Use it to clear the LCD Widget
  lcd.print(4, 0, "No"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  lcd.print(4, 1, "Rain!!");
  //Blynk.notify("No");
  }
}

void tempe() {

  int chk = DHT.read11(DHT11_PIN);
    Blynk.virtualWrite(0, DHT.temperature);  // Write values to the app
  Blynk.virtualWrite(1, DHT.humidity);
}
void loop()
{
  Blynk.run();
  timer.run();
}

Looking MUCH better. I will take a quick look at your code now and see if I can spot anything.

Not sure what your specific project is but it is unlikely that you need to know the temperature and amount of rain (or negative rain?) every second. The 1000L (1 second) is just an example for seeing uptime / clock time every second but you might need to change 1000L to 60000L (every minute) or 3600000L (every hour).

sendUptime timer isn’t in setup so either add it or remove the function. You probably don’t need so many lcd.clear statements, just the first one in rain().

Can’t see any other problems in the code.

Much better now. Thanks a lot. I am a noob in coding. Just don’t like it. Will never repeat these mistakes in future. Thanks a ton man :slight_smile:

Just one problem left. I am not able to make a put request to my pin. Mostly it says pin does not exist which is surely does in my app.

Since the server went down last week my PUT requests to the cloud server have stopped working too.

I’ll let you know if the feature returns to my systems.

We will do deploy very soon with possible fix.

Thanks for this @Dmitriy

Thanks a lot @Dmitriy