|
Dimitry Codreanu - 2015-07-13 17:56:00
Using PHP for many applications is something that makes it very versatile, but when it comes to reading sensors that are connected to the host computer that is running windows, how do you access that part, without making use of a compiler?
Manuel Lemos - 2015-07-13 19:11:05 - In reply to message 1 from Dimitry Codreanu
Tom Freund - 2015-07-13 19:11:28 - In reply to message 1 from Dimitry Codreanu
That is the part handled by the executables enabled through popen. The source for them is written usually in C (or C++) and contains the details for interfacing with the sensor or actuator.
The PHP code support network access and (possibly) data analysis functions.
Dimitry Codreanu - 2015-07-13 20:26:24 - In reply to message 2 from Manuel Lemos
So let's think about this, we get an app to remotely do things. Let's say we get a app for a greenhouse, to handle the venting, watering etc? Can we with popen access any file even if not relative to the Apache web server root?
Dimitry Codreanu - 2015-07-13 20:26:48 - In reply to message 2 from Manuel Lemos
Let's say we build a web app so that we can remotely manage multiple greenhouses remotely.
So we will need some scripts that run by cron jobs to do some of the operations automatically like watering, making ventilation adjustments etc, on a server located at the location of the greenhouses but we need to check things remotely and eventually do some manual adjustments and so on, so we will need part of it to be under Apache, so I presume all project will be under Apache root www folder, can files not related to the Apache and php be accessed with the popen be still accessed?
Tom Freund - 2015-07-13 20:51:04 - In reply to message 5 from Dimitry Codreanu
Certainly under Apache. Not sure, if a PHP script in another web server will do.
There is also issues in synchronizing the popen executable stream with the PHP script invoking it.
Found that there is some tweaking involved with the code in the executable in order to synchronize the steam with PHP script.
When multitasking is introduced in PHP, that may become easier.
Tom Freund - 2015-07-13 20:57:45 - In reply to message 5 from Dimitry Codreanu
One more thing.
popen requires the executable to be written in full path format. So, say, SetValve in the article is written as, say, /home/tank/SetValve with the appropriate privileges on the SetValve executable.
Take a look at the documentation on popen in the PHP manual.
Manuel Lemos - 2015-07-13 20:57:52 - In reply to message 6 from Tom Freund
popen will always work regardless of the Web server you use.
As for multitasking, PHP by default will block on fread or fwrite calls to read and write data for the sensor program.
I am not sure of using stream_set_blocking would work with stream opened with popen but it is a possibility.
Another possibility is to fork a process with the pnctl extension, so you can communicate with each sensor in parallel processes that do not block each other.
|