Açıklama
|
#boot.py____________________________try: import usocket as socketexcept: import socket from machine import Pinimport networkimport espesp.osdebug(None)import gcgc.collect()ssid='HUAWEI P smart 2019'password='12345687'station = network.WLAN(network.STA_IF)station.active(True)station.connect(ssid,password)while station.isconnected()==False: passprint ('baglanti kuruldu')print (station.ifconfig())relay=Pin(5,Pin.OUT)#main.py_________________________import machinefrom machine import Pinled=Pin(2,Pin.OUT)html = """<!DOCTYPE html><html> <head> <title>ESP8266 Led Yak Sondur</title> </head> <body> <p>Led Yakma Sondurme Sayfasi #{}</p> <form action="/" method="POST" Content-Type="multipart/form-data" > <input type="text" name="islem"><br><br> <input type="submit" value="Gonder" /> </form> </table> </body></html>""".format(led.value())import sockets = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.bind(('', 80))s.listen(5)while True: try: if gc.mem_free() < 102000: gc.collect() conn, addr = s.accept() conn.settimeout(3.0) print('Got a connection from %s' % str(addr)) #Request_____________________________________ request = conn.recv(1024) conn.settimeout(None) request = str(request) print('Cevap uzunlugu:'+str(len(request))) print('Content = %s' % request) on = request.count('Yak') off = request.count('Sondur') if on > 0:#sayfanin iceriginde donen bilgiye led yak ya da sondur print('led ON') led.value(0) if off > 0: print('led OFF') led.value(1)#Response_____________________________________ if led.value()==1: response = html.replace("#0","#1") if led.value()==0: response = html.replace("#1","#0") conn.send('HTTP/1.1 200 OK\n') conn.send('Content-Type: text/html\n') conn.send('Connection: close\n\n') conn.sendall(response) conn.close() except OSError as e: conn.close() print('Connection closed') Proje Videosu:https://www.youtube.com/watch?v=ecoDVAQeC44
|
|