I'm programming an website to control my Raspberry Pi robot. I'm driving two stepper motor using .py script I call it:
sudo ./GPS.py forward 100 30
Fist argument is way to go, second is how many steps to do, and the last is delay between steps.
The script open location.txt file (it looks like "100/50/18") and take coordinations x=100, y=50 and Alpha=18 degress. Then make a move, calculate new coordination and write it into this file.
Read part at the top of script:
fo = open("location.txt", "r")
data = fo.read()
fo.close()
coordinates= data.split("/")
temp1 = coordinates[0]
temp2 = coordinates[1]
temp3 = coordinates[2]
Alpha= float(temp3)
X = float(temp1)
Y = float(temp2)
Then it make all requested moves and calculations, and then at the end save new X,Y,Alpha back to file:
fo =open("location.txt", "w")
fo.write(str(X)+"/"+str(Y)+"/"+str(Alpha))
fo.close
Allright, this works perfect in Putty, but now I wanted to drive my robot through website, so I've made website to control it.
But now I have a problem. Now I have site like this:
HTTP --> Javascript --> PHP --> .PY script to move robot.
This works, but I have no idea how refresh X,Y,Alpha coordinates from location.txt on my website. I have an idea:
Javascript run .PY and wait it finishes, then JS open .txt and get data and finally set new coordinates to my webpage. But I don't know how to do it. This waiting to .PY finishes is killing me.
Thanks for your help! Yacked2
PS.
I have apache installed on my Raspberry Pi, and I can donwload my .py script though webpage and I can open .txt file.