-1

I have a big fan in my shop that I can control via a quick and dirty Flask API i wrote that runs on the pi that controls my fan.

I have a web app on my main server (also Flask) that I use to control it.

Is it possible to, create a delay before changing the GPIO.output from HIGH to LOW?

Use-case: I want to set an auto-power off after a specified amount of time (that can be changed but for example, 3 hours). So I can set it and forget it? It doubles as an air cleaner (its a woodshop, so the air gets dusty).

I know with Python there are about 1001 ways to do anything but curious about your thoughts here.

Cheers

3
  • delay(60*hours) would be simplest, but that would pause your program and I think it would pause flask... – scitronboy May 1 '18 at 23:22
  • Yea that's what I was afraid of. I was thinking about writing a record to the DB and have it ping the db constantly but that seems excessive. – ProfessionalAmateur May 1 '18 at 23:27
  • It would be nice if people explained why they downvote something instead of downvoting and moving on. It's just not as helpful. – ProfessionalAmateur May 2 '18 at 23:48
1

As @scitronboy mentioned you'd want a solution that would allow the flask portion to hand off to something else. Based on this question, two possible options (as you said, of many) you could use are concurrent.futures or a job/task manager like celery. While I agree that celery would likely be overkill, it certainly provides the chance to view or cancel the pending task, add or subtract time, reschedule, and potentially use the same task system for other things later on.

If viewing or cancelling the shutdown isn't important, you could try a Per-Request After-Request Callback to call another function to shutdown later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.