These are chat archives for esp8266/Arduino

23rd
Apr 2017
Martin Sloup
@arcao
Apr 23 2017 05:33
@brutzler Something like this?
#include <time.h> 

// time zone
#define TIME_ZONE_DST 1
#define TIME_ZONE (1 + TIME_ZONE_DST) 

void setup() {
  ...
  configTime(TIME_ZONE * 3600, 0, "pool.ntp.org", "time.nist.gov");
  Serial.println("\nWaiting for time");
  while (!time(nullptr)) {
    Serial.print(".");
    delay(1000);
  }
  Serial.println("");  
}

void loop() {
  time_t rawtime;
  struct tm *info;

  time(&rawtime);
  info = localtime(&rawtime);

  if ((info->tm_min % 5) == 0 && info->tm_sec == 0) {
    // send data
    // make sure that send data takes at least one second, otherwise you have improve this if statement
    // to not be called more than once per second (e.g. compare old rawtime with current rawtime)
  }
}
brutzler
@brutzler
Apr 23 2017 12:53

@arcao yes, thought about this possibility, and you are absolutely right with the improvement of calling twice or more in one second.
I took nearly the same way. As I already have a ticker instance with 1 minute:

Ticker tick_1min;
...
  tick_1min.attach(60, T_1min);
...
void T_1min() {
  if (myTime.tm_min % 5 == 0) enableSendData = true;  
  // myTime.tm_min is the minute-value of the actual unix-timestamp. 
}

And with this I do not have to take care of the multiple calling :-)