So I am trying to make an rc plane with the pi pico, so to make it remote controlled, i decided to have it host a little web server, just simply with the controls. And I got that to work. But then I noticed the planes lights stopped blinking. In short, the microcontroller can’t do anything else because it is busy waiting for a web request.
The lights will only blink if I refresh the page, or click a button.
Here is the loop, plane_duties() is all of the other code
while True:
plane_duties(.05)
try:
cl, addr = s.accept()
request = cl.recv(1024)
request = str(request)
tlan_toggle = request.find('tlan=toggle')
blan_toggle = request.find('blan=toggle')
if tlan_toggle == 8:
tlan = not tlan
if blan_toggle == 8:
blan = not blan
print(tlan, blan)
tlanState = 'Landing is OFF' if tlan else 'Landing is ON'
tlanStateClass = 'off' if tlan else 'on'
blanState = 'Cargo is OFF' if blan else 'Cargo is ON'
blanStateClass = 'off' if blan else 'on'
response = html.replace('{{tlanStateClass}}', tlanStateClass).replace('{{blanStateClass}}', blanStateClass) % (
tlanState, blanState)
cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
cl.send(response)
cl.close()
except OSError as e:
cl.close()
print('connection closed')
Is there any way I can run code while waiting for a request?