# wlan_station_server_0: connection Request-Empfang

import network
import socket
from time import time

# Konfiguration des Wlans:
station = network.WLAN(network.STA_IF)
station.active(True)
station.connect('mipamipa', 'Asdfghjkl1234') # hier Ihre WLan-Daten eintragen!
time0 = time()
while (not station.isconnected()) and (time() - time0 < 5):
  pass

if station.isconnected():
  print('Wlan connected')
  print(station.ifconfig()) # zur Information
  s=socket.socket()
  s.bind(('', 80))
  s.listen(5) 
  print('Server listening')
  print('--------------------------------------')

  # Daten holen;  
  while True:
    connection, addr = s.accept()
    print("Client connected: ", addr)
    request = connection.recv(1000)  # HTML-Request hier nicht unbedingt erforderlich!!!
    print(str(request,'UTF-8'))
    html = '<html><body><h1>Hallo Welt</h1></body></html>'
    connection.send(html)
    connection.close()
    print('--------------------------------------')

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




