date from HTTP
Posted: Sun Mar 12, 2017 6:35 am
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:
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 all
String 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"