Time input widget in arduino ide

hello. I’m trying to finish part of a project that consists of capturing a time from blynk, using the “time input” widget and turning on an LED at that time that was established by the user. However, I’m having a lot of difficulties, the code runs but the LED doesn’t light up (I’ve already tested it separately). I’m using the Arduino IDE and the ESP8266 board. the code is like this:

#define BLYNK_TEMPLATE_ID " ******* "
#define BLYNK_TEMPLATE_NAME "  ****** "
#define BLYNK_AUTH_TOKEN " ****** "

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = " ****** ";
char pass[] = " ****** ";

#include <ESP8266WiFi.h>
#include <time.h>
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
#include <NTPClient.h>
#include <WiFiUdp.h>


WiFiUDP ntpUDP;
const long utcOffsetInSeconds = -10800;  // Ajuste para UTC-3
NTPClient timeClient(ntpUDP, "br.pool.ntp.org", utcOffsetInSeconds);

int pinLED = 5;  //

BlynkTimer timer;

String targetTime = "00:00";  

BLYNK_WRITE(V2)
{
  String newTime = param.asStr();
  if (isValidTime(newTime))
  {
    targetTime = newTime;
    Serial.print("Hora definida pelo Blynk: ");
    Serial.println(targetTime);
  }
  else
  {
    Serial.println("Hora inválida.");
  }
}


void checkAndControlLED()
{
  int currentHour = timeClient.getHours();
  int currentMinute = timeClient.getMinutes();

  if (targetTime == (String(currentHour) + ":" + String(currentMinute)))
  {
    digitalWrite(pinLED, LOW);  // Liga o LED se a hora e minuto correspondem
  }
  else
  {
    digitalWrite(pinLED, HIGH); // Desliga o LED caso contrário
  }
}

void setup()
{
  Serial.begin(115200);  // Inicia a comunicação serial para depuração
  pinMode(pinLED, OUTPUT);
  digitalWrite(pinLED, HIGH);  // Garanta que o LED esteja desligado no início

  Blynk.begin(auth, ssid, pass);
  timeClient.begin();
  timer.setInterval(1000L, checkAndControlLED);  // Verifica a hora a cada segundo
}

void loop()
{
  Blynk.run();
  timer.run();
  timeClient.update();
}

I generated a code similar to this example, however it still doesn’t work and nothing even appears on the serial monitor

#define BLYNK_TEMPLATE_ID " ***** "
#define BLYNK_TEMPLATE_NAME " ***** "
#define BLYNK_AUTH_TOKEN " ***** "

// Substitua com suas credenciais de rede e token Blynk
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = " ***** ";
char pass[] = " ***** ";

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>

int timeInputPin = V7;
int ledPin = 4;


BLYNK_WRITE(timeInputPin) {
  TimeInputParam t(param);

  // Obter a hora e o minuto definidos no Time Input
  int selectedHour = t.getStartHour();
  int selectedMinute = t.getStartMinute();

  Serial.print("Hora definida pelo usuário: ");
  Serial.print(selectedHour);
  Serial.print(":");
  Serial.println(selectedMinute);

  // Obter o tempo atual em horas e minutos
  int currentHour = hour();
  int currentMinute = minute();

  Serial.print("Hora atual do RTC: ");
  Serial.print(currentHour);
  Serial.print(":");
  Serial.println(currentMinute);

  // Verificar se a hora e o minuto selecionados correspondem ao tempo atual
  if (selectedHour == currentHour && selectedMinute == currentMinute) {
    // Acender o LED no GPIO 4 (D4)
    digitalWrite(ledPin, HIGH);
    delay(10000); // Manter o LED aceso por 10 segundos
    digitalWrite(ledPin, LOW);
  }
}

void setup() {
  Serial.begin(115200);
  Serial.println("Iniciando o setup...");

  Blynk.begin(auth, ssid, pass);

  Serial.println("Configuração do Blynk concluída.");
  
}

void loop() {
  Blynk.run();
}

Please do not generate any code. Don’t take that trouble. Blynk team has done a wonderful job by giving us the example builder. Just replace/add your template name and device name. Get this working. Understand how things work line by line.

Then you can start generating.

Your code should be producing some serial output when the board boots and connects to Blynk, and when you change the value of the start time in the V7 widget. If its not (and assuming that you have the serial monitor set to the correct baud rate) your board may be faulty.

Your code is structured incorrectly.
It has no way to obtain the current time, which is needed to compare with the start time set in the Time Input widget.
Also, the code that checks if the current time matches the start time in the widget is only called once, when you change the value of the time input widget.

You also use a long blocking delay…

which you cant do with Blynk.

Pete.

to cotrol led on off, where can i find the simple code, i see a lot and none are worked

@night rather than hijacking an existing topic, you’d be far better creating your own “need help…” topic and explaining more about your hardware and the overall aim(s) of your project. That way, you’ll get much more meaningful answers.

Pete.