Ejemplo n.º 1
0
 def __init__(self, host, port):
     self.what = dict()
     self.host = host
     self.port = port
     self.last = None
     self.soc = esp.socket()
     self.soc.onconnect(lambda sock: send_data(self))
     self.soc.onrecv(lambda sock, data: socket_recv(self, sock, data))
Ejemplo n.º 2
0
 def __init__(self, host, port):
     self.what = dict()
     self.host = host
     self.port = port
     self.last = None
     self.soc = esp.socket()
     self.soc.onconnect(lambda sock: send_data(self))
     self.soc.onrecv(lambda sock, data: socket_recv(self, sock, data))
               "<head><h1 align='center'>Python for esp8266 - SciPy India 2015</h1></head>\r\n"
		"<body bgcolor='#ccff99'>\r\n"
	       "<form align='center' action='' method='post'>\r\n"
		"<fieldset>\r\n"
		"<legend style='color:red'>Red LED Control</legend>\r\n"
		"<input type='radio' name='LED' value='ON'> ON\r\n"
		"<input type='radio' name='LED' value='OFF'> OFF<br>\r\n"
		"</fieldset>\r\n"

		"<input type='submit' value='Submit'>\r\n"
		"</form>\r\n"
		"</body>\r\n"
	       	)
    else:
        s.send("HTTP/1.0 404 OK\r\n"
               "Server: Micropython for ESP8266\r\n"
               "Content-Type: text/html\r\n"
               "Connection: close\r\n"
               "\r\n"
               "<h1>:(</h1>")

def onclientsent(s):
    s.close()

network.connect(ssid, passwd)
socket = esp.socket()
socket.onconnect(onnewclient)
gc.collect()
socket.bind(("", 80))
socket.listen(5)
Ejemplo n.º 4
0
 def __init__(self, port=80, data_cb=None):
     self.data_cb = data_cb
     self.socket = esp.socket()
     self.socket.onconnect(lambda sock: self.onconnect(sock))
     self.socket.bind(('0.0.0.0', port))
     self.socket.listen(1)
Ejemplo n.º 5
0
 def __init__(self, port=80, data_cb=None):
     self.data_cb = data_cb
     self.socket = esp.socket()
     self.socket.onconnect(lambda sock: self.onconnect(sock))
     self.socket.bind(("0.0.0.0", port))
     self.socket.listen(1)
Ejemplo n.º 6
0

us = Ultrasonic(13, 15)

def onnewclient(s):
    # print("Client connected!")
    s.onrecv(onclientdata)
    s.onsent(onclientsent)

def onclientdata(s, d):
    if d.startswith(b'GET /dist '):
       s.send("HTTP/1.0 200 OK\r\n"
               "Server: Micropython for ESP8266\r\n"
               "Content-Type: text/plain\r\n"
               "Connection: close\r\n"
               "\r\n" + str(us.dist()))

def onclientsent(s):
    # print("Closing...")
    s.close()

sta = Sta()
sta.connect()


server = esp.socket()

server.onconnect(onnewclient)
server.bind(("", 80))
server.listen(5)
Ejemplo n.º 7
0
 def __init__(self, got_date):
     self.soc = esp.socket()
     self.soc.onconnect(lambda sock: on_connect(self, sock))
     self.soc.onrecv(lambda sock, data: socket_recv(self, sock, data))
     self.mutex = esp.mutex(spin_time=3000)
     self.got_date = got_date