Sending Blynk notifications at a specific time

Hi all,

I have an esp8266 linked to blynk in which I have established an rtc and an LED to display the time and I want to receive a blynk notification at a specific time. It should be a simple fix as all I need is an if statement, however I am unsure on what to put in the if statement. Everything I have tried so far has been an error. any ideas? thanks.

Here is the code;


#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

char auth[] = "*******";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*******";
char pass[] = "*********";

BlynkTimer timer;

WidgetRTC rtc;



void clockDisplay()
{
  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentDate = String(day()) + "/" + month() + "/" + year();
  Serial.print ("Current time: ");
  Serial.print(currentTime);
  Serial.print(" ");
  Serial.print(currentDate);
  Serial.println();
  
  Blynk.virtualWrite(V1, currentTime);
  Blynk.virtualWrite(V2, currentDate);
}

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

  Blynk.begin(auth, ssid, pass);
  
 rtc.begin();

 timer.setInterval(1000L, clockDisplay);
   
   
}

void loop()
{

  Blynk.run();
 
  timer.run();

if (IDK WHAT TO PUT HERE) {
Blynk.notify("Ready")

}

String currentTime = String(hour()) + ":" + minute() + ":" + second();
You already have the current time in a String. There are better ways to do it, but you could compare that String with the required time

I have written the following statement:

if (String currentTime = String(hour(17)) + ":" + minute(30) + ":" + second(0) {
Blynk.notify("Ready")
}

and it worked. Thanks! I can't believe I didn't try that not gonna lie....

What I had in mind was more like
if (currentTime = "17:30:00") but I don't use Strings

I tried that and it had a bunch of errors. I thought this code worked originally however its sending the notification a million times and im unsure why. Do you have any ideas? I have it in void loop right now

However you do the comparison, if you do it in loop() then it will happen thousands of times a second

You need to detect when the comparison becomes true rather than when it is true

How do I do this?

Here is the code:

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

char auth[] = "*****";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "****";
char pass[] = "***";

BlynkTimer timer;

WidgetRTC rtc;



void clockDisplay()
{
  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentDate = String(day()) + "/" + month() + "/" + year();
  Serial.print ("Current time: ");
  Serial.print(currentTime);
  Serial.print(" ");
  Serial.print(currentDate);
  Serial.println();
  
  Blynk.virtualWrite(V1, currentTime);
  Blynk.virtualWrite(V2, currentDate);
}

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

  Blynk.begin(auth, ssid, pass);
  
 rtc.begin();

 timer.setInterval(1000L, clockDisplay);
   
   
}

void loop()
{

  Blynk.run();
 
  timer.run();
 
  if (String currentTime = String(hour(17)) + ":" + minute(35) + ":" + second(0)){

Blynk.notify("Ready");

}

Read the current time in setup() and save it as the previous time. In loop() read the current time.

If the current time does not equal the previous time and the current time equals the target time then send the message.

At the end of loop() save the current time as the previous time ready for the next check

Unless you want/need accuracy to the second than I suggest you remove seconds from the test.

If you do need to use seconds then only do the target time test when the seconds change