-->
Page 1 of 1

Simple use of minutes and seconds from wifi

PostPosted: Thu Feb 24, 2022 8:34 am
by NAP1947
I am a newbie and trying to setup a simple process to operate 2 servos and and LED based on minutes and seconds like Big Ben. I can get connection to my wifi and print minutes and seconds to the serial screen very simply with this code;


//Getting ESP8266 Time from Internet

#include "NTPClient.h"
#include "ESP8266WiFi.h"
#include "WiFiUdp.h"

const char *ssid = "my wifi name";
const char *password = "my wifi password";

const long utcOffsetInSeconds = -18000;

//char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);

void setup(){
Serial.begin(115200);

WiFi.begin(ssid, password);

while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( "." );
}

timeClient.begin();
}

void loop() {
timeClient.update();

//Serial.print(daysOfTheWeek[timeClient.getDay()]);
Serial.print(", ");
//Serial.print(timeClient.getHours());
Serial.print(":");
Serial.print(timeClient.getMinutes());
Serial.print(":");
Serial.println(timeClient.getSeconds());
//Serial.println(timeClient.getFormattedTime());

delay(1000);
}

Now the part that confuses me, every project I find that uses wifi time to run a sketch function uses a very complex and lengthly process starting with micro-seconds.

Is there not a simple way to just read the minutes and seconds from the wifi to trigger a sketch function at 0 minutes-0 seconds, 15 minutes-0 seconds, 30 minutes-0 seconds, 45 minutes-0 seconds and start again at 0-minutes, 0-seconds?

The minute-seconds combinations appear once every hour in the serial screen, why can I not just pick this time combination and have it trigger an action? My application does not require milli-second accuracy.

I am sure I am over simplifying this but could someone please help me understand.

Thank you

Re: Simple use of minutes and seconds from wifi

PostPosted: Sun Feb 27, 2022 1:14 am
by JurajA
this example f an unrelated library shows how to work with time on esp8266 Arduino with the Arduino Time library
https://github.com/jandrassy/TelnetStre ... 66Test.ino