四博智联产品售后

标题: WiFi连接到路由器,并获取时间 [打印本页]

作者: ycf    时间: 2015-12-9 17:34
标题: WiFi连接到路由器,并获取时间
  1. #include <ESP8266WiFi.h>
  2. #include <time.h>

  3. const char* ssid = "Doit";
  4. const char* password = "doit3305";

  5. int timezone = 3;
  6. int dst = 0;

  7. void setup() {
  8.   Serial.begin(115200);
  9.   Serial.setDebugOutput(true);

  10.   WiFi.mode(WIFI_STA);
  11.   WiFi.begin(ssid, password);
  12.   Serial.println("\nConnecting to WiFi");
  13.   while (WiFi.status() != WL_CONNECTED) {
  14.     Serial.print(".");
  15.     delay(1000);
  16.   }

  17.   configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");
  18.   Serial.println("\nWaiting for time");
  19.   while (!time(nullptr)) {
  20.     Serial.print(".");
  21.     delay(1000);
  22.   }
  23.   Serial.println("");
  24. }

  25. void loop() {
  26.   time_t now = time(nullptr);
  27.   Serial.println(ctime(&now));
  28.   delay(1000);
  29. }
  30. wifi.zip (639 Bytes, 下载次数: 5502)
复制代码







欢迎光临 四博智联产品售后 (http://bbs.doit.am/) Powered by Discuz! X3.2