I wanted to add one output more in the ESP Web Server
I added in boot.py file: leda = Pin(0, Pin.OUT)
In the main.py file I modified to let “leda” go on or off but i get a failure.
I have no idee how to fix it.
Start your code here
# Complete project details at https://RandomNerdTutorials.com def web_page(): html = """<html><head><meta name="viewport" content="width=device-width, initial-scale=1"></head> <body><h1>ESP Web Server</h1><a href=\"?led=on\"><button>ON</button></a> <a href=\"?led=off\"><button>OFF</button></a> <a href=\"?leda=on\"><button>ON</button></a> <a href=\"?leda=off\"><button>OFF</button></a></body></html>""" 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) led_on = request.find('/?led=on') led_off = request.find('/?led=off') leda_on = request.find('/?led=on') leda_off = request.find('/?led=off') if led_on == 6: print('LED ON') led.value(1) if led_off == 6: print('LED OFF') led.value(0) if leda_on == 6: print('LED ON') led.value(1) if leda_off == 6: print('LED OFF') led.value(0) response = web_page() conn.send(response) conn.close()
It looks like you didn’t add the proper leda name (there’s an “a” missing):
leda_on = request.find('/?leda=on')
leda_off = request.find('/?leda=off')
It’s also missing here:
if leda_on == 6:
print('LED ON')
leda.value(1)
if leda_off == 6:
print('LED OFF')
leda.value(0)
However, that doesn’t seem to be the problem. What’s the exact error that you’re having? I need more information about what’s not working for you.
Hello,
I modified the main menu with the missing a. I still get the same error
When I run the file main.py: I get following text in the serial display.
download ok
exec (open(.’mainl.py’).read(),globals())
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “<string>”, line 26
IndentationError: unindent does not match any outer indentation level
>>>
You’re missing a space or you have extra spaces. In Python there’s no { } or ; so all that is done with indentation that you need to respect (2 or 4 spaces). For example:
while True:
if leda_on == 6:
print('LED ON')
leda.value(1)
if leda_off == 6:
print('LED OFF')
leda.value(0)
Basically, the if has 2 spaces, then the print has 4 spaces. How does your line 26 look like?