| 123456789101112131415161718192021222324252627282930313233343536 |
- import machine
- pins = [machine.Pin(i, machine.Pin.IN) for i in (0, 2, 4, 5, 12, 13, 14, 15)]
- html = """<!DOCTYPE html>
- <html>
- <head> <title>ESP8266 Pins</title> </head>
- <body> <h1>ESP8266 Pins</h1>
- <table border="1"> <tr><th>Pin</th><th>Value</th></tr> %s </table>
- </body>
- </html>
- """
- import socket
- addr = socket.getaddrinfo('0.0.0.0', 7180)[0][-1]
- s = socket.socket()
- s.bind(addr)
- s.listen(1)
- print('listening on', addr)
- cnt = 10
- while cnt > 0:
- cl, addr = s.accept()
- print('client connected from', addr)
- cl_file = cl.makefile('rwb', 0)
- while True:
- line = cl_file.readline()
- if not line or line == b'\r\n':
- break
- rows = ['<tr><td>%s</td><td>%d</td></tr>' % (str(p), p.value()) for p in pins]
- response = html % '\n'.join(rows)
- cl.send(response)
- cl.close()
- cnt -= 1
|