Arduino ESP8266 发送HTTP请求 获取苏宁服务器时间

参考:发送HTTP请求

参考:获取时间

#include <ESP8266WiFi.h>

#include <ESP8266HTTPClient.h>


//在这里输入你家的WiFi名字和密码
const char* ssid     = "hg2020"; 

const char* password = "12345678";   

HTTPClient http;

String GetUrl;

String response;

void setup() {

  // 连接到你家的WiFi

  delay(3000);

  Serial.begin(115200);

  WiFi.mode(WIFI_STA);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {

    delay(500);

    Serial.print(".");

  }


  Serial.println("");

  Serial.println("WiFi connected");

  Serial.println("IP address: ");

  Serial.println(WiFi.localIP());


  // 连接苏宁网站的授时网页

  GetUrl = "http://quan.suning.com/getSysTime.do";

  http.setTimeout(5000);

  http.begin(GetUrl);


}


void loop() {

  // 从网站获得网页内容

  int httpCode = http.GET();

  if (httpCode > 0) {

      Serial.printf("[HTTP] GET... code: %d\n", httpCode);

      if (httpCode == HTTP_CODE_OK) {

        //读取响应内容

        response = http.getString();
 
        Serial.println(response);

      }

  } else {

      Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());

  }

  http.end();

  delay(3000);

}

  

上一篇:智能WIFI灯


下一篇:12864 OLED 0.96寸 液晶显示屏连接Nodemcu显示天气