1

I've been working on a Obstacle avoidance robot using Ultrasonic and IR sensors.

The scope of my project is to execute my program over the air.

  • Control the robot's movement using mouse or touch screen.
  • Execute the obstacle avoidance program

The program for "robot movements" is written in very basic cgi scripts (just by controlling the GPIO pins and thus the respective motors)

gpio -g write 13 1

The second program is written in Python.

My Question :

  1. Can a HTML page directly execute .py files?
  2. If not please guide some tutorials about .cgi programming or Python scripts in such a file. Or just how should i proceed, do i need to learn PHP or HTML programming?

Basically This is the code, making a button.

<button style="height: 75px; width: 75px" onclick="forward()"><img style="height: 65px"src="/images/forward.png"></button>

This is suppose to call the function below, but the .py file is not executed

function forward()
{
xmlhttp.open("GET","cgi-bin/forward.py",true);
xmlhttp.send();
}

I'm new to this kind of over the air controlling. Any help would be appriciated

4
  • You've not mentioned what your "movements" CGI have been written in: how do you control the GPIO? If it has a system()-like command can you use that to start (or stop?) your python script as a background process? Beware though, using system() is frowned upon in some circles (EDIT: one expansion on why it's frowned upon) Commented Dec 5, 2018 at 13:03
  • It is written as a Script CGI file. Wiring Pi GPIO access library 'gpio -g write 5 0' (Which basically means then give a logic 0 to pin 5) Should i post the code to make things more clean? Commented Dec 5, 2018 at 13:51
  • That's OK, I misunderstood your question and thought you had the "movements" stuff already working from the web server and wanted to expand it to also run your Python script. I now see that the "movement" part runs of the Pi's interface, not on the web server. Sorry. Commented Dec 5, 2018 at 15:48
  • the basic movements do work. "gpio -g write 5 0" is written with the normal #!/bin/bash . I'm using the wiring PI library to directly access the GPIO pins. The problem is when i want to run a .py file. It doesn't execute the code Commented Dec 6, 2018 at 10:18

1 Answer 1

2

Since you are looking for a way to control your robot remotely via a browser, one framework to look at is node.js.

Node.js is a java-script runtime environment that allows you to run java-script code both on browser and server side.

There are excellent tutorials from w3schools on how to control/read the GPIO-pins of the Raspberry Pi via node.js.

4
  • The server is actually established. I can access the web page from the Web browser and execute .cgi files as well. It's just that i'm not able to execute .py files. I do not know scripting language to an extent that i can write the whole pro gram i wrote in Python in Scripting language Commented Dec 5, 2018 at 14:09
  • I got that. I wanted to point you to an alternative to your AJAX calls. Node.js is not hard to learn IMO. Commented Dec 5, 2018 at 15:32
  • Thank you the response. I found your answer helpful. It's either Node.js or Flask for Python. Which can run the back-end server. Commented Dec 7, 2018 at 16:31
  • Best of luck with your project! Commented Dec 8, 2018 at 5:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.