Page 1 of 1

WebServer blocking loop

Posted: Tue Nov 08, 2016 3:48 pm
by peon5
Hi everyone,
I set up a webserver on my nodemcu. It works pretty good and I'm able to control LEDs via WiFi connection.
Unfortunately the code is blocking the while loop. It just runs in the moment i give a command over the webpage. That means I'm not able to use this loop for checking GIPO buttonstates or animate my oled. Has anyone an Idea how to use a webserver and not blocking the loop?

Here's the code:
[code]But2 = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_UP)
#Setup Socket WebServer
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(5)
while True:
if not But2.value(): #not working
print("But2")
Lightshow()
conn, addr = s.accept()
print("Got a connection from %s" % str(addr))
request = conn.recv(1024)
print("Content = %s" % str(request))
request = str(request)
LEDON0 = request.find('/?LED=ON0')
LEDOFF0 = request.find('/?LED=OFF0')
LEDON2 = request.find('/?LED=ON2')
LEDOFF2 = request.find('/?LED=OFF2')
#print("Data: " + str(LEDON0))
#print("Data2: " + str(LEDOFF0))
if LEDON0 == 6:
print('TURN LED0 ON')
#LED0.low()
Lightshow()
if LEDOFF0 == 6:
print('TURN LED0 OFF')
#LED0.high()
if LEDON2 == 6:
print('TURN LED2 ON')
LED.low()
if LEDOFF2 == 6:
print('TURN LED2 OFF')
LED.high()
response = html
conn.send(response)
conn.close()[/code]


Best regards!