ルーチン説明 14-WiFi-Shield->ntp 現在時刻を取得
import network
import socket
import struct
import time
SSID = ""
KEY = ""
TIMESTAMP = 2208988800
if time.gmtime(0)[0] == 2000:
TIMESTAMP += 946684800
print("Trying to connect... (This may take a while)...")
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print('Trying to connect to "{:s}"...'.format(SSID))
time.sleep_ms(1000)
print("WiFi Connected ", wlan.ifconfig())
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
addr = socket.getaddrinfo("pool.ntp.org", 123)[0][4]
client.sendto("\x1b" + 47 * "\0", addr)
data, address = client.recvfrom(1024)
t = struct.unpack(">IIIIIIIIIIII", data)[10] - TIMESTAMP
print("Year:%d Month:%d Day:%d Time: %d:%d:%d" % (time.localtime(t)[0:6]))
Singtown Technology OpenMV
公式中国語ドキュメント機能説明: