Answer the question
In order to leave comments, you need to log in
Calling an external program on the Apache server using php with a subsequent response?
I woke up and came up with an idea to send and receive information from the LPT port (I send a byte code to the micro controller, it turns on the relays for me: light, electronic locks, etc., as well as read data: Humidity, temperature, Ph-water sensors)
I decided to stir up all this for the greenhouse.
Answer the question
In order to leave comments, you need to log in
php.net/manual/en/function.exec.php
php.net/manual/en/function.system.php
php.net/manual/en/function.passthru.php
But I would use Python like:
Flask + https http://github.com/pyserial/pyparallel
So is the port serial or parallel? If serial, then the commentator offered you a suitable solution, and if by some miracle parallel, then this:
Write a program in c ++ that can be controlled by command line arguments like this controller.exe /p LPT1 /relay 2
Further in php something like such exec("controller.exe /p LPT1 /relay".$relay); where $relay is the relay that you will turn on. Need help, write https://vk.com/vadimkholodilo
CGI allows you to run your program without php at all.
You need to learn html / http and, accordingly, your program should generate an html page for apache.
Write a console program in C/C++/whatever that interacts with the LPT port and can return results in text or html
Learn html forms (how to create a button that calls up a file)
In Apache, set up cgi support - enable cgi module
LoadModule cgi_module modules/mod_cgi.so
Add cgi handler
AddHandler cgi-script .cgi
or
AddHandler cgi-script .exe Enable
cgi in site directory, or even DocumentRoot
Options ExecCGI
try www.mysite.com/myprogram.exe
Or you can go the other way. You know PHP without knowing other languages and you need to work with a serial port. For example, the same Arduino, although connected via USB, is defined as a COM port. There are libraries for PHP to work with it. For example here: https://github.com/lepiaf/serialport
Using this or a similar library, you either get rid of the bridge or write it in PHP. Good luck.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question