http://davidayala.eu/current-time/
The website above offers free Timezone APIs. I have been trying to request the API with my esp8266 NodeMCU, but still, i get no response. Can anyone please demonstrate to me with a code sample how it's supposed to be done? I will be posting my code soon.
The following is my code (In arduino IDE) for my NodeMCU
#include <ESP8266WiFi.h>
String result;
char host[]="script.google.com";
WiFiClient client;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
WiFi.begin("Faiz", "hautepackard");
while(WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(500);
}
Serial.println("Connected!");
Serial.println(WiFi.localIP());
}
void loop() {
Time();
delay(3000);
}
String url = "/macros/s/AKfycbyd5AcbAnWi2Yn0xhFRbyzS4qMq1VucMVgVvhul5XqS9HkAyJY/exec";
void Time(){
if (client.connect(host, 443)) { //starts client connection, checks for connection
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
Serial.println("Server is accessible");
} else {
Serial.println("connection failed"); //error message if no client connect
Serial.println();
}
result = "";
while (client.available()) { //connected or data available
char c = client.read(); //gets byte from ethernet buffer
result = result+c;
}
Serial.println(result);
client.stop(); //stop client
Serial.println("end of function");
}
And this is what i get in the Serial monitor:
........Connected!
Server is accessible
end of function
Am i going wrong anywhere in the code? Please help this burning question.