This is a good option:
You have only to fill YOUR_WIFI_SSID and YOUR_WIFI_PASSWORD with the connection data of your wifi network.
>>>def do_connect(wifi_ssid,wifi_passwd): #useful function for connecting to your local WiFi network
>>>"nbsp" import network, time
>>> wlan = network.WLAN(network.STA_IF)
>>> wlan.active(True)
>>> if not wlan.isconnected():
>>> print('\nConnecting to network', end='')
>>> wlan.connect(wifi_ssid, wifi_passwd)
>>> while not wlan.isconnected():
>>> print('.', end='')
>>> time.sleep(0.5)
>>> pass
>>> import ubinascii
>>> print()
>>> print("Interface's MAC: ", ubinascii.hexlify(network.WLAN().config('mac'),':').decode()) # print the interface's MAC
>>> print("Interface's IP/netmask/gw/DNS: ", wlan.ifconfig(),"\n") # print the interface's IP/netmask/gw/DNS addresses
>>>do_connect("YOUR_WIFI_SSID","YOUR_WIFI_PASSWORD")
>>>import ntptime #NTP-time (from pool.ntp.org)
>>>ntptime.settime() #
https://github.com/micropython/micropyt ... ntptime.py
>>>from machine import RTC
>>>(year, month, mday, week_of_year, hour, minute, second, milisecond)=RTC().datetime()
>>>RTC().init((year, month, mday, week_of_year, hour+2, minute, second, milisecond)) # GMT correction. GMT+2
>>>print ("Fecha/Hora (year, month, mday, week of year, hour, minute, second, milisecond):", RTC().datetime())
>>>print ("{:02d}/{:02d}/{} {:02d}:{:02d}:{:02d}".format(RTC().datetime()[2],RTC().datetime()[1],RTC().datetime()[0],RTC().datetime()[4],RTC().datetime()[5],RTC