NTPclient librairy implementation problem

Hello,
This is a suit to this thread, but since it’s not the same problem anymore, figured I’dd change the topic name.
I’ve got my circuit running good, but apprently my code isn’t

Here is the code

#include <SPI.h>                   
#include <ESP8266WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>

byte buzzer = 2;
char ssid[] =                    "Alladin";
char pass[] =               "Flying Carpet";
WiFiServer server(80);              

const long utcOffsetInSeconds = 7200;


WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);

int Hours = timeClient.getHours();
int Minutes = timeClient.getMinutes();
int Seconds = timeClient.getSeconds();

WiFiClient client;

void setup() {
Serial.begin(115200);                   // only for debug
  WiFi.begin(ssid, pass);                 // connects to the WiFi router
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
  }
  server.begin();                         // starts the server
 }
void loop () {
  timeClient.update();
 if (Hours == 18 && Minutes == 39 && Seconds == 00)//;
  {
       if (client) {
         if (client.connected()) {
            String request = client.readStringUntil('\r');
            while((request)==("He is still sleeping")) ;
               {
                Serial.println("Waking him up");
                String request = client.readStringUntil('\r');    
                client.flush();
                client.println("Waking him up\r"); 
                digitalWrite(buzzer, LOW);  
                delay(500);
                digitalWrite(buzzer, HIGH);
                delay(500);
          
               }
         
            if ((request)==("He is awake !"));
                {
                client.stop();
                digitalWrite(buzzer, LOW);
                }
            client.flush();
        }
    
   }
    
}
  delay(500);
  }

The problem seems to be with the Hours,Minutes and Seconds variables, I tried a code to serial print the time, it displays 0, I’m not shure but I think there is a problem with my variables, but can’t figure out what ! I use a librairy that enable the use of ntp hours as variables : NTPClient/NTPClient.h at master · arduino-libraries/NTPClient · GitHub

Any advice ?

Thanks :slight_smile:

After you call update on your timeclient instance, you will need to get hours minutes and seconds from it again. Those variables won't change automatically.

Hello,
I moved the variables in the loop, seems to work better, but there is still a problem !
When the specified time comes, it only bips one time, but it is supposed to bip until the button on the other board is pressed.

Here is the “buzzer” code

#include <NTPClient.h>
#include <SPI.h>                   
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

byte buzzer = 2;
char ssid[] ="mywifi";
char pass[] ="supersecurepassword";
WiFiServer server(80);              

const long utcOffsetInSeconds = 7200;


WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);

int Hours = timeClient.getHours();
int Minutes = timeClient.getMinutes();
int Seconds = timeClient.getSeconds();

WiFiClient client;

void setup() {
Serial.begin(115200);                   // only for debug
  WiFi.begin(ssid, pass);                 // connects to the WiFi router
  while (WiFi.status() != WL_CONNECTED) {
      delay(1000);
  }
  pinMode(buzzer, OUTPUT);
  server.begin();                         // starts the server
 }
void loop () {
  WiFiClient client = server.available();
timeClient.update();
int Hours = timeClient.getHours();
int Minutes = timeClient.getMinutes();
int Seconds = timeClient.getSeconds();
String request = client.readStringUntil('\r');
 if (Hours == 19 && Minutes == 53 && Seconds == 30)//;
  {
    while((request)!=("He is awake"));
        {    
             digitalWrite(buzzer, HIGH);
             delay(500);
             digitalWrite(buzzer, LOW);  
             delay(500);
             digitalWrite(buzzer, HIGH);
             delay(500);
             digitalWrite(buzzer, LOW);  
             delay(500);
             digitalWrite(buzzer, HIGH);
             delay(500);
             digitalWrite(buzzer, LOW);  
             delay(500);
             digitalWrite(buzzer, HIGH);
             delay(500);
             digitalWrite(buzzer, LOW);  
             delay(500);
             String request = client.readStringUntil('\r'); 
                 }
          
               
              }
       if ((request)==("He is awake"));
                
                {
                digitalWrite(buzzer, LOW);
                
                }
            
        
    
   
    

  delay(500);
  }

Here is the button code

#include <SPI.h>
#include <ESP8266WiFi.h>

byte button = 2;
char ssid[] =                "alladin";           
char pass[] =            "flyingcarpet";          

unsigned long askTimer = 0;

IPAddress server(192,168,0,80);       
WiFiClient client;

void setup() {
  Serial.begin(115200);               
  WiFi.begin(ssid, pass);             
  while (WiFi.status() != WL_CONNECTED) {
  
    delay(1000);
  }
  pinMode(button, INPUT);
}

void loop () {
  client.connect(server, 80);   
  if (digitalRead(button)==LOW);
     {
           client.println("He is awake\r");
           
     }
  delay(500);                  
}

Any Idea what’s going on ?

Thank you very much