anh2ah
Posts: 3
Joined: Thu Jun 06, 2019 1:51 am

How to internal website send command to terminal raspbian

Thu Jun 06, 2019 2:04 am

I have created a website to control the car using Rasp pi 3+.
Also created a python program to control it, it has a name: AutorunCar.py
When I run: sudo python AutorunCar.py in the terminal, it's working normally
but I don't know how to call that program on my website with HTML code
Please help me solve this problem, thank in advance :)

scotty101
Posts: 3718
Joined: Fri Jun 08, 2012 6:03 pm

Re: How to internal website send command to terminal raspbian

Thu Jun 06, 2019 10:08 am

Perhaps you could share your code?

As an example, I created something a while back to send IR commands via a python script from a web page. This allowed me to control my TV from a web browser on my phone.
https://github.com/scotty3785/pi_tv_remote
It uses python-flask, a framework for creating dynamic web content with python. Pressing a button on the webpage, sends a command back to the python code running on the pi to send the different IR signals.
Something like this could be modified quite easily to control a car/robot.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

anh2ah
Posts: 3
Joined: Thu Jun 06, 2019 1:51 am

Re: How to internal website send command to terminal raspbian

Fri Jun 07, 2019 10:30 am

Thanks, Scotty!
Your post is working well,
but when I run .py file on startup it doesn't work (sudo nano /etc/rc.local)
Do you have any idea to solve it,
Thanks and I wish you have a good day!

User avatar
omegaman477
Posts: 148
Joined: Tue Feb 28, 2017 1:13 pm
Location: Sydney, Australia

Re: How to internal website send command to terminal raspbian

Sat Jun 08, 2019 5:17 pm

In Python, there are many ways to execute external programs. The easiest one is to import the os package. It provides the popen(), system(), startfile() methods.

But it is dependant on your local O/S.

os.popen() should solve your needs.
..the only thing worse than a stupid question is a question not asked.

klricks
Posts: 6587
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: How to internal website send command to terminal raspbian

Sat Jun 08, 2019 7:05 pm

anh2ah wrote:
Fri Jun 07, 2019 10:30 am
Thanks, Scotty!
Your post is working well,
but when I run .py file on startup it doesn't work (sudo nano /etc/rc.local)
Do you have any idea to solve it,
Thanks and I wish you have a good day!
If your script requires Desktop (GUI) then you can't start it with rc.local.
Use autostart instead:

Code: Select all

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

anh2ah
Posts: 3
Joined: Thu Jun 06, 2019 1:51 am

Re: How to internal website send command to terminal raspbian

Tue Jun 11, 2019 12:50 am

Thanks klricks!
Now, my program working well
Thanks for your help and I wish you have a good day!

Return to “Other projects”