import network
import socket
from time import time, sleep


station = network.WLAN(network.STA_IF) # Konfiguration des Network-Interfaces
station.active(True)
station.connect('mipa_devolo', 'asdfghjkl1234') # hier Ihre Wlan-Daten eintragen!
time0 = time()
while (station.isconnected() == False) and (time() - time0 < 5):
  pass

if station.isconnected():
  print('WLAN connected')  
  server_addr = ('time.fu-berlin.de', 13)
  while True:
    try:  
      client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      client.connect(server_addr)
      print('----------------------------')
      print('Socket connected')
      data = client.recv(1024) # max. Anz. der Bytes
      print(str(data,'UTF-8'), end = '')
      client.close()
      print('Socket closed')
      sleep(20)
    except:
      print('----------------------------')
      print('Exception: Socket Error')
      break

station.active(False)
print('Wlan deactivated')







