But how do you read the sensors?

Recommend this page to a friend!

      PHP Classes blog  >  Controlling Autonomou...  >  All threads  >  But how do you read the sensors?  >  (Un) Subscribe thread alerts  
Subject:But how do you read the sensors?
Summary:Using PHP for many applications is something that makes it very
Messages:8
Author:Dimitry Codreanu
Date:2015-07-13 17:22:38
Update:2015-07-13 20:57:52
 

  1. But how do you read the sensors?   Reply   Report abuse  
Picture of Dimitry Codreanu 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?

  2. Re: But how do you read the sensors?   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2015-07-13 19:11:05 - In reply to message 1 from Dimitry Codreanu
I guess that question was answered in the previous article:

phpclasses.org/blog/post/287-PHP-In ...

  3. Re: But how do you read the sensors?   Reply   Report abuse  
Picture of Tom Freund 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.

  4. Re: But how do you read the sensors?   Reply   Report abuse  
Picture of Dimitry Codreanu 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?

  5. Re: But how do you read the sensors?   Reply   Report abuse  
Picture of Dimitry Codreanu 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?


  6. Re: But how do you read the sensors?   Reply   Report abuse  
Picture of Tom Freund 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.

  7. Re: But how do you read the sensors?   Reply   Report abuse  
Picture of Tom Freund 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.

  8. Re: But how do you read the sensors?   Reply   Report abuse  
Picture of Manuel Lemos 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.

 

For more information send a message to info at phpclasses dot org.