import socket
import network
import time

def connect_to_wifi():
    ssid = "velop"
    password = "thuissurfer"

    wlan = network.WLAN(network.STA_IF)  # Set to Station mode
    wlan.active(True)  # Enable Wi-Fi interface
    wlan.connect(ssid, password)  # Connect to Wi-Fi

    while not wlan.isconnected():
        print("Connecting to Wi-Fi...")
        time.sleep(1)

    print("Connected! IP Address:", wlan.ifconfig()[0])

def connect_to_socket():
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # Create socket
        sock.connect(("80.200.136.25", 5566))  # Connect
        print("Connected to", socketaddr)
        sock.close()  # Close connection
    except Exception as e:
        print("Connection failed:", e)

connect_to_wifi()
time.sleep(2) 
connect_to_socket()
