四博智联产品售后

 找回密码
 立即注册
搜索
查看: 16786|回复: 0

WiFi连接到路由器,并获取时间

[复制链接]

252

主题

302

帖子

1817

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1817
发表于 2015-12-9 17:34:54 | 显示全部楼层 |阅读模式
  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, 下载次数: 5430)
复制代码


相关帖子

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|四博智联 Inc. ( 粤ICP备15034758号-1

GMT+8, 2024-3-29 21:00 , Processed in 0.063253 second(s), 30 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表