本站改版新增arduino频道
MicroPython ESP32 通过ntptime模块获取NTP获取网络时间
import time,ntptime,network
def wifi_main():
global inif
wifi=network.WLAN(network.STA_IF) #WIFI模式
if not wifi.isconnected():
print('wifi ing......')
wifi.active(True)
wifi.connect('MERCURY_D268G','pba5ayzk') #连接WIFI
while not wifi.isconnected():
pass
print('Wifi connection succeeded')
print('network config:', wifi.ifconfig())
wifi_main()
while True: #时间校准
try:
ntptime.settime()
print('time ok')
mytime=time.localtime()
mytime='%d-%d-%d %d:%d:%d'%(mytime[0],mytime[1],mytime[2],mytime[3]+8,mytime[4],mytime[5])
print(mytime)
except:
print('time no')
time.sleep(1)
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.009321928024292 seconds