0

I have a script, in the cgi-bin which generates this page. The intent of which is to serve as an interface for a panning web camera I built. The camera, does the pan, then quickly returns to the center position. I figured out that this is because every time the page loads, all the scripts are called, in succession, ending with z.py. How can I fix this program so that the scripts do not run until a selection occurs? As it is, everything runs when the page loads, which is why It always pans back to center.

#! /bin/sh
echo "content-type: text/html"
echo
echo "<!DOCTYPE html><html><head><title>pan camera</title></head>"
echo "<body>"

echo "<form action=\"g.pt1\" method=\"get\">"
echo "<select name=\"letter\" onchange=\"submit();\">"
echo "  <option value=\"w\">w</option>"
echo "  <option value=\"a\">a</option>"
echo "  <option value=\"s\">s</option>"
echo "  <option value=\"d\">d</option>"
echo "  <option value=\"z\">z</option>"
i=0
for i in a s d w z
        do
                echo  " $i  $(./$i.py)"
        done
echo "</select></form>"
echo "<iframe src=\"localhost:8888/?action=stream\" width=\"330\" height=\"260\">"
echo " <p>Your browser does not support iframes.</p>"
echo "</iframe>"
echo "</body></html>"
  • I don't think "everything runs" as you say. The for/do/echo statement lists a bunch of characters and suggests a Python file, but that's just echoed and not run. All I see here, is that upon changing the select box, `g.pt1` is invoked via CGI. Presumably that thing should pick up whether a w,a,s,d or z got selected and move the camera. If the camera moves back then I think it's due to whatever `g.pt1` is doing. – Karel Kubat Dec 01 '14 at 12:28
  • $() is command substitution, so you can exec via echo. I also have some BS permission for www-data group to be allowed to access /dev/ttyACM0 – Brooke Fogg-Wolfe Dec 07 '14 at 00:48

1 Answers1

0

Note - not a 'web programmer'...

Is the script above 'everything'? (or just the output?)

Also, for this type of use you might want to consider using a 'here document' to avoid 'escaping' all the quotes.

The FOR LOOP with the echo line in the 'middle' is run 'each time' the page loads.

$(./$i.py) will run, in order, a.py, then s.py, ... and then z.py

Remove the loop and Change this logic to 'get user input' and you should be good to go.

Dale_Reagan
  • 1,953
  • 14
  • 11