# Complete project details at https://RandomNerdTutorials.com
def web_page():
html = """<html><head> <title>ESP Web Server</title> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="data:,"> <style>html{font-family: Helvetica; display:inline-block; margin: 0px auto; text-align: center;}
h1{color: #0F3376; padding: 2vh;}p{font-size: 1.5rem;}.button{display: inline-block; background-color: #e7bd3b; border: none;
border-radius: 4px; color: white; padding: 16px 30px; text-decoration: none; font-size: 10px; margin: 2px; cursor: pointer;}
.button2{background-color: #4286f4;}.button3{background-color: red;}</style></head><body> <h1>ESP Web Server</h1>
<strong>Commander une voiture</strong></p>
<table>
<tr><td></td><td><p><a href="/?direction=avant"><button class="button button2">AVANT</button></a></p></td><td></td></tr>
<tr><td><p><a href="/?direction=gauche"><button class="button button2">GAUCHE</button></a></p></td><td><p><a href="/?direction=off"><button class="button button3">STOP</button></a></p></td>
<td><p><a href="/?direction=droite"><button class="button button2">DROITE</button></a></p></td></tr>
<tr><td></td><td><p><a href="/?direction=arriere"><button class="button button2">ARRIERE</button></a></p></td><td></td></tr>
</body></html>
</table>
"""
return html
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(5)
while True:
conn, addr = s.accept()
print('Got a connection from %s' % str(addr))
request = conn.recv(1024)
request = str(request)
print('Content = %s' % request)
direction_avant = request.find('/?direction=avant')
direction_stop = request.find('/?direction=off')
direction_droite = request.find('/?direction=droite')
direction_gauche = request.find('/?direction=gauche')
direction_arriere = request.find('/?direction=arriere')
if direction_avant == 6: #si on clique sur le bouton Avant
dc_motor.forward(80) # la voiture avance
dc_motor1.forward(80)
if direction_stop == 6: #si on clique sur le bouton Stop
dc_motor.stop() # la voiture s'arrête
dc_motor1.stop()
if direction_droite == 6: #si on clique sur le bouton droite
dc_motor.forward(10) # la voiture tourne à droite
dc_motor1.forward(80)
if direction_gauche == 6: #si on clique sur le bouton gauche
dc_motor.forward(80) # la voiture tourne à gauche
dc_motor1.forward(10)
if direction_arriere == 6: #si on clique sur le bouton arriere
dc_motor.backwards(80) # la voiture recule
dc_motor1.backwards(80)
response = web_page()
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()