本站改版新增arduino频道
import ntptime
import network
import machine
import utime
def sync_ntp():
ntptime.NTP_DELTA = 3155644800 # 可选 UTC+8偏移时间(秒),不设置就是UTC0
ntptime.host = 'ntp1.aliyun.com' # 可选,ntp服务器,默认是"pool.ntp.org"
ntptime.settime() # 修改设备时间,到这就已经设置好了
#连接网络
station = network.WLAN(network.STA_IF)
while(not station.isconnected()):
station.active(True)
try:
station.connect("NBWIFI", "z7758521")
utime.sleep(5.0)
except OSError:
print("OSError")
utime.sleep(2.0)
sync_ntp()
# 已经设置好了,随便用
from machine import RTC
rtc = RTC()
print(rtc.datetime())
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.0094351768493652 seconds