It looks like you're new here. If you want to get involved, click one of these buttons!Sign In Register
It looks like you're new here. If you want to get involved, click one of these buttons!
# stream for serial activity import streams # socket module to TCP import socket # generic wifi APIs from wireless import wifi # esp8266 wifi driver from espressif.esp8266wifi import esp8266wifi as wifi_driver # constants ap_name = 'AHS' ap_pass = '12345687' tcp_srv_port = 80 tcp_srv_max_clnt = 2 # init serial streams.serial() # connect to access point print('Connect to Access Point: ' + ap_name) # init esp8266 wifi driver print('Init ESP8266 WiFi driver...') wifi_driver.auto_init() # try to connect to Access Point tries = 0 while not wifi.is_linked() and tries < 5: try: wifi.link(ap_name, wifi.WIFI_WPA2, ap_pass) except Exception as e: pass tries += 1 ip = wifi.link_info() print('IP Address: ' + ip) print('Starting TCP server.') # create a tcp socket sock = socket.socket() # bind the socket to port sock.bind(tcp_srv_port) # set the socket in listening mode sock.listen() print('Server Listening on ' + tcp_srv_port + '...') while True: # accept incoming connections from clients client,addr = sock.accept() # send something to the client and close client.sendall("Hello!") client.close()