2

i would like to seek your opinion on this as I have little idea about the whole structure and not sure where to find more information.

Currently I have this problem of having both Apache2 and CherryPy web server on my Raspberry Pi. Apache2 is at port 80 and CherryPy is at port 8080. I have a camera app (http://raspberrypiwonderland.wordpress.com/2014/01/15/awesome-camera-app/) deployed at all time at port 80 -> http://localhost However I have a few servo motors and LEDs that are controlled by the GPIO from the web app. The web app is deployed using CherryPy at port 8080, such as this http://raspberrypiwonderland.wordpress.com/2014/03/14/controlling-led-from-cherrypy-web-app/. I have also installed php and mysql together with Apache2. I have a few problems here:

  1. The camera display is at http://localhost but the "servo controller button" to move the camera left and right is at http://localhost:8080. How to put them together under the same page?

  2. I can access phpmyadmin from http://localhost/phpmyadmin but not http://localhost:8080/phpmyadmin. But I have a form to link to the database from the cherrypy app at port 8080.

  3. I would like to use the data from the database to determine the servo movement. eg, get a number from a field to determine how many times the servo has to repeat a certain movement (action of dispensing a pill). How possible is this?

My camera app files are in /var/www while cherrypy app is in its own directory. I have thought of a few ideas here. Please give me your feedback on which one is the easiest because i have limited time constraint to finish this project (1 week) . 1. get rid of cherrypy. But how can i run the python file from a html? I tried several methods and ppl were suggesting Flask, which turn out worst than cherrypy. 2. access database from camera app (http://localhost) 3. i read something about WSGI for cherrypy but i dunno if it is suitable for my case? I dont really know what is it for?

I have very limited knowledge about all these web servers thing but hope to learn all the necessary things in the shortest time possible. I hope to hear some opinions from you guys. thanks a lot! :D

closed as off-topic by RPiAwesomeness, lenik, Steve Robillard Dec 12 '14 at 19:24

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – RPiAwesomeness, lenik, Steve Robillard
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    There are quite a few ways to solve each your problems, but nginx reverse proxy is the answer to all of them at once – foibs Mar 15 '14 at 11:32
  • 1
    foibs is right, you want a reverse proxy server, of which nginx is one possibility. See How to redirect HTTP request to different local web servers. – goldilocks Mar 15 '14 at 14:06
  • Nothing against nginx, but there's nothing here that requires a third web server. If it can't be consolidated into one, then using mod_proxy under Apache would be simpler. – TomG Sep 13 '14 at 0:53
  • Cross site scripting? You can have hundred servers running and one main one pull data using something like jquery simply by using $.load('url #targetID') just need to add CORS. Not a simple answer though but once you get the hand of it you can do whatever you like, locally. It is possible server side too but a bit more complex – Piotr Kula Nov 10 '14 at 19:36
1

I think the simplest approach from your point of view would be to ditch CherryPy and work in PHP under Apache2. It should make it clearer how you can connect things together if you're working in one environment. For example, you get database access through mysql_connect(), and you can access the GPIO using the exec() function to run shell scripts. Unfortunately I think this starting point is the best I can do. Without knowing how your code is currently constructed and how you want everything to ultimately interact, it's impossible to give you step by step directions. This sort of a project sounds like a really good opportunity to learn so continue to Google and ask questions!

  • Thanks for your suggestions! I actually tried to use exec() from php to run a python script but it doesn't work well (can't exactly recall what was the problem but here's the link to my blog on what i tried raspberrypiwonderland.wordpress.com/2014/02/28/…). Currently my whole web app is in a python file which when run, will start the cherrypy server, show html and javascript at localhost:8080, and even run python functions to control GPIO. so it's rather convenient. – yvonnezoe Mar 15 '14 at 15:54
  • In that case maybe looking into a Python MySQL binding might be in order. Something like this: stackoverflow.com/questions/372885/… – Fred Mar 15 '14 at 18:50
  • hmm thanks for the link. i'm trying to minimize using new stuff again because i have really little time to do so. But will definitely look into it again someday. Currently i am trying to access my DB with php (javascript post to a php when a button is clicked), not sure if that will work? – yvonnezoe Mar 16 '14 at 1:39
  • That sounds reasonable. Use the XMLHttpRequest() function to create a new request object, then use .open('POST', 'http://url', false), then .setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); to make it look like a form, .send('urlencodred=string'), then .responseText can be parsed in Javascript to change HTML elements as necessary. See developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest – Fred Mar 16 '14 at 7:44

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