So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By kendoik
#63599 I got this code from the forum and it seems to be working great.

Still I don't understand it.

I want to change the date format, so I can schedule a motor to run from "x" mins every "y" days.

I don't want to set up an internal clock so that in case of power failure I don't run the motor when not supposed to.

here it is:
Code: Select allString getTime() {
  WiFiClient client;
  while (!!!client.connect("google.com", 80)) {
    Serial.println("connection failed, retrying...");
  }

  client.print("HEAD / HTTP/1.1\r\n\r\n");


  while (!!!client.available()) {
    yield();
  }

  while (client.available()) {
    if (client.read() == '\n') {
      if (client.read() == 'D') {
        if (client.read() == 'a') {
          if (client.read() == 't') {
            if (client.read() == 'e') {
              if (client.read() == ':') {
                client.read();
                String theDate = client.readStringUntil('\r');
                client.stop();
                return theDate;
              }
            }
          }
        }
      }
    }
  }
}



//"- See more at: http://www.esp8266.com/viewtopic.php?f=29&t=6007&start=5#sthash.buxmBQQM.dpuf"
User avatar
By torntrousers
#63604 That code you show goes and gets a text string representation of the current time from a google server.

If you need to do time calculations then that text format is not very convenient as you'd need to try to parse the text into the constituent date, hours, minutes, seconds pieces and then do calculations on those.

You don't give many details of exactly what you want to do but maybe using NTP would be easier?

Try this - viewtopic.php?p=48888#p48888 - and then you can do diff calculations like this - https://www.tutorialspoint.com/c_standa ... fftime.htm
User avatar
By kendoik
#63610 The goal is to automate a fertilizer feeder.
I want it to run a peristaltic motor, for some seconds, every "x" days.
I want this to report the last "feed" and be able to adjust the periodicity via browser, also since I'm using the ESP8266 i want to take advantage of being connected to the internet to sync the time from my device, so it wont over or under feed in case of a power fail.

I moved on from the HTTP time, and tried the NTP.
the time.h library seems to have been updated to the Time.h library. Since I'm a noob, i'm first just trying to read the NTP time and show it in the serial monitor, so that from there I can start to "complicate" things.