Getting time from NPT

hello guys I am using esp32 and getting time form server.
The program is working. All I want is to have it as unixtime, or any other form so that I can store it in and send it in a packet. or can compare it with something.

#include <WiFi.h>
#include "time.h"

const char* ssid       = "UTF_LABS";
const char* password   = "UTF_LABS_1234";

const char* ntpServer = "pool.ntp.org";
const long  gmtOffset_sec = 9000;
const int   daylightOffset_sec = 9000;

void printLocalTime()
{
  struct tm timeinfo;
  if(!getLocalTime(&timeinfo)){
    Serial.println("Failed to obtain time");
    return;
  }
  Serial.println(&timeinfo, "%H:%M:%S");
  Serial.println(&timeinfo);
}

void setup()
{
  Serial.begin(9600);
  
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED); 
  Serial.println(" CONNECTED");
  
  //init and get the time
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
  printLocalTime();

}

void loop()
{
  
  delay(1000);
  printLocalTime();
  
}

that's what the mktime() function is for if you have a valid struct tm

What’s a time form server? Also NPT is a type of train in Australia...

Accuracy is important.

I guessed OP meant “Network Time Protocol” and got the acronym wrong… but sure accuracy can’t hurt

So what you want is Epoch time.

The time lib should have a now function. This will return you the number of seconds from the start of 1970. This can be saved, stored or transmitted.

Basically my program requires to send data every 5 min. So I want to check whether 5 min have passed, so that I can send the data. The current program is only giving me the result but I want to do something useful with it.

Workaholic: Basically my program requires to send data every 5 min. So I want to check whether 5 min have passed, so that I can send the data. The current program is only giving me the result but I want to do something useful with it.

Millis can do that for you. Do you care what the actual time is or just whether 5 minutes have passed since you last did your thing?

Actually I want to send the data at 12.45 (say), then at 12.50, then 12.55 ..... so on.

I donot think millis() can do that for me.

Where is your 'getLocalTime()' function defined?

Workaholic: I donot think millis() can do that for me.

You are right of course. If you actually care that the data is sent at a particular time, millis can't help you. For interests sake though, why does it matter?

For interests sake though, why does it matter?

because at the receiving side which is a cloud server, it takes data at a particular time to sync all the devices. If my approach is wrong, kindly give better suggestion to accomplish it. Although my data packet contains time as well. and I want to send the data every 5 mins. Is millis() a better approach?

@Workaholic:

Why haven't you responded to Reply #1 or Reply #8?

quote]it takes data at a particular time[/quote]

By particular means every 5 minutes. Or eventually we will make this parameter settable by the application.[