ルーチン説明 14-static_ip static ip
import network
import socket
import struct
import time
SSID = ""
KEY = ""
TIMESTAMP = 2208988800 + 946684800
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.ifconfig(("192.168.1.200", "255.255.255.0", "192.168.1.1", "192.168.1.1"))
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print('Trying to connect to "{:s}"...'.format(SSID))
time.sleep_ms(1000)
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]))