Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By kolban
#31373 Looking at the document from Espressif called "ESP8266 AT Instruction Set v0.40" I don't see any commands related to Simple Network Time Protocol (SNTP) which is what is used to retrieve the current time. The SNTP APIs are available for SDK applications written in C but I don't believe these have been mapped to the AT command processor.
User avatar
By torntrousers
#31405 The HTTP RFC defines a Date header so pretty much all websites will return the current date/time in all http responses, so you can use that. Here's a sketch function to do that by making an HTTP HEAD request to google.com:
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;
              }
            }
          }
        }
      }
    }
  }
}


That will return a String like "Thu, 15 Oct 2015 08:57:03 GMT"