Rusty
Rusty

Reputation: 389

Use HTML interface to control a running python script on a lighttpd server

I am trying to find out what the best tool is for my project.

I have a lighttpd server running on a raspberry pi (RPi) and a Python3 module which controls the camera. I need a lot of custom control of the camera, and I need to be able to change modes on the fly.

I would like to have a python script continuously running which waits for commands from the lighttpd server which will ultimately come from a user interacting with an HTML based webpage through an intranet (no outside connections).

I have used Flask in the past to control a running script, and I have used FastCGI to execute scripts. I would like to continue using the lighttpd server over rather than switching entirely over to Flask, but I don't know how to interact with the script once it is actually running to execute individual functions. I can't separate them into multiple functions because only one script can control the camera at a time.

Is the right solution to set up a Flask app and have the lighttpd send requests there, or is there a better tool for this?

Upvotes: 0

Views: 184

Answers (2)

gstrauss
gstrauss

Reputation: 2404

I have used Flask in the past to control a running script, and I have used FastCGI to execute scripts.

Given your experience, one solution is to do what you know. lighttpd can execute your script via FastCGI. Python3 supports FastCGI with Flask (or other frameworks). A python3 app which serially processes requests will have one process issuing commands to the camera.

I would like to continue using the lighttpd server over rather than switching entirely over to Flask, but I don't know how to interact with the script once it is actually running to execute individual functions.

Configure your Flask app to run as a FastCGI app instead of as a standalone webserver.

Upvotes: 1

Akib Rhast
Akib Rhast

Reputation: 671

You have several questions merged into one, and some of them are opion based questions as such I am going to avoid answering those. These are the opinion based questions.

  1. I am trying to find out what the best tool is for my project.
  2. Is the right solution to set up a Flask app and have the lighttpd send requests there
  3. Is there a better tool for this?

The reason I point this out is not because your question isnn't valid but because often times questions like these will get flagged and/or closed. Take a look at this for future referece.

Now to answer this question:

" I don't know how to interact with the script once it is actually running to execute individual functions"

Try doing it this way:

  1. Modify your script to use threads and/or processes.
  2. You will have for example a continously running thread which would be the camera.
  3. You would have another non blocking thread listening to IO commands.
  4. Your IO commands would be comming through command line arguments.
  5. Your IO thread upon recieving an IO command would redirect your running camera thread to a specific function as needed.

Hope that helps and good luck!!

Upvotes: 0

Related Questions