Skip to content

Instantly share code, notes, and snippets.

@wgwz
Created August 15, 2015 02:27
Show Gist options
  • Save wgwz/ed278d06f4631b122f4a to your computer and use it in GitHub Desktop.
Save wgwz/ed278d06f4631b122f4a to your computer and use it in GitHub Desktop.
using Flask to make web-app with Rpi for controlling LED's
I asked this question a few weeks ago in the Raspberry Pi Forum's.
Unfortunately no one got back to me.
I am sure there is a simple solution to my problem.
So I am making a really simple webapp, which has two buttons.
One button starts a blink sequence on a multi-colored LED.
The other button turns the multi-LED completely off.
The blink sequence requires a loop.
The loop freezes the webapp.
I can't figure out a way to break out of the loop.
Currently I have two addresses I want to act as the "switch".
http://localhost:8000/22/27/17/on
http://localhost:8000/22/27/17/off
(The numbers are the GPIO pins where LED's are connected, but there can only three right now.)
Again, the problem is that when I request the LED to be "on" it creates an infinite loop.
So that when I go to the "off" address, the loop is still running.
The Flask app cannot pick up the new request, because the page is stuck in the loop.
I can't figure out how to insert a "break" into the loop.
I need some other information from the request that can communicate to the running process.
I don't know how to do this in Flask yet.
Here is a [link](https://github.com/callmeskywalker/tinker-wizrd/tree/master/web-led) to the code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment