loading
This is the second part of my sumppump water level sensor.  

You can find the first part on how to built a water level sensor, here:

http://www.instructables.com/id/Sump-pump-water-level-The-hardware/


Needed:

-Raspberry Pi with
        Apache
        PHP
        Sendmail or postfix if you want a email warning.





What the software will do:

The command part
This part is invisible to the user and is (and should be ) independent of the webpage.
Using cron, it will read the water level every minute and save the information to a file. If the water level reaches a certain level, an email will be sent. This is the most important part.


The Web page
In this part, the web page reads the information from the file written by the cron job and displays an image of your pit.

Step 1: Download and copy the software

Download the zip file and uncompress it to the webfolder of your Raspberry. I recommend creating a subfolder at the root of your www folder. Typically, the folder path is /var/www/sumppump.

<p>Hi Luc,</p><p>Thanks for posting this guide! I'm having trouble with the code. Could you help me? I'm having many issues, but I'm currently troubleshooting. When I try to run chklevel.php directly I get the following message</p><p><a href="mailto:pi@raspberrypi" rel="nofollow">pi@raspberrypi</a> /var/www/sumppump $ sudo php chklevel.php<br>sh: 1: /var/www/sumppump/sensor.py: Permission denied<br>PHP Notice: Undefined offset: 0 in /var/www/sumppump/chklevel.php on line 13<br><br>Mesure final -11cm <br><br>Mesure final -4.3pouce <br>0<br>0 have been send sh: 1: /usr/sbin/sendmail: not found<br>Message cannot be send</p>
<p>Change permission of sensor.py to 777 or 755. All other error are because sensor.py cannot execute. </p>
<p>And make sure you can write to result.php</p>
<p>Now that I have been able to measure, I don't think it's measuring correctly. I measured about 7 inches of water, but it displays 11.4 inches. </p>
<p>Substract 4,4 from $compensation</p>
<p>Line now reads: $compensation=-4.4;</p><p>But it is still about 4-5inches too high. </p>
<p>Thanks, that clears some stuff up. For my cron I would run:</p><p>3 * * * * /path/to/php /var/www/html/chklevel.php</p><p>I tried running the script manually, and it puked out some errors:</p><p>pi@pi /var/www/html $ ./chklevel.php</p><p>./chklevel.php: line 1: ?php: No such file or directory</p><p>./chklevel.php: line 2: //: Is a directory</p><p>./chklevel.php: line 3: syntax error near unexpected token `'/var/www/html/''</p><p>./chklevel.php: line 3: `chdir('/var/www/html/');'</p><p>is the $deep in cm? Is that from sensor to bottom of pit? Also, what does compensation equate to? Should that be preset as well from 11? Is that in cm or inches? </p>
<p>Hi Anthony,<br></p><p>chklevel.php is a php file, not a bash. If you want to run it manually, do:</p><p>php chklevel.php</p><p>I assume you have apache and php install on your rasp.</p>
<p>Yeah, that worked, thanks. </p><p>Shouldn't this work as a cron? 3 * * * * /etc/php5/apache2 /var/www/html/chklevel.php</p><p>I also moved the sensor, and it never changed depth, it always said this:</p><p>pi@pi /var/www/html $ php chklevel.php</p><p> sh: 1: /var/www/html/sensor.py: Permission denied</p><p>PHP Notice: Undefined offset: 0 in /var/www/html/chklevel.php on line 13</p><p> Mesure final -11cm</p><p> Mesure final -4.3pouce</p><p>4</p><p>4 have been send .The maximum of email have been reach</p>
<p>Change permission of sensor.py to 777 or 755. All other error are becasue sensor.py cannot execute.<br><br>for cron, instead of </p><p>/etc/php5/apache2 /var/www/html/chklevel.php</p><p>try:<br><br>php /var/www/html/chklevel.php<br><br><br>If you can run php /var/www/html/chklevel.php ,then cron can do it to.</p>
<p>That worked, thanks! Also, any idea on these?</p><p>is the $deep in cm? Is that from sensor to bottom of pit? Also, what does compensation equate to? Should that be preset as well from 11? Is that in cm or inches?</p><p>Do you know how accurate the sensor is? I will get crazy readings like: </p><p> Measure final 585cm</p><p>Then I re run and it's 53cm, which is closer to accurate. Do I need to do anything so it will start measuring the depth of water? Have you found a way to retain results, so I can track trends and retain a little history? </p>
<p>Check the image at step 2. It will give you the meaning of all the variables. If, for some reason, it's not acurate, add or substract the difference of reading you got. Also, You can set the unit of measure to cm or inches in the preference file.<br><br>Once you measure in real life an modify the $compensation variable, it should be pretty acurate.</p><p><br><br><br></p>
<p>There we go, that is working well now. Any chance of keeping any history? Say for the last 24 hours? That would be cool to see.</p><p>My last question is this value:</p><p>$compensation=-11;</p><p>What is the compensation for? Is that the # for how low the water will get once the water is pumped out? OR is it the distance from the top of the pit (or $deep) minus where the sensor sits? Is it in inches or cm as well? </p><p>I also noticed $deep needed to be in inches, not cm. </p>
<p>$compensation is ithe distance from the top of the pit minus where the sensor sits. -11 was my own. And you can add or retreive in case it's not acurate.<br><br>I cannot test what is the error of the $deep value, my system is not fonctionnal, I need my rasp for other project.</p>
<p>no worries, was compensation -11 in cm or inches? I assume cm :D .. so far looks to be working great now that I added it as root cron. </p><p>Would be cool if you could add some historical graphs of data. My programming is probably not good enough to be able to retain the data, and then display it in a nice graph. </p>
<p>Hi anthony,<br><br>Cron is require to run the file chklevel.php. every minutes. The procees is not heavy on the processor, so, run it every minutes.</p><p>What chklevel.php does is:</p><p>- run a python script to read the water level.</p><p>-Compare the result with the max level you enter in the pref files.</p><p>-Write the result to the files result.php (make sure the file is R/W 777)</p><p>-Send an email if you have reach the maximum water level.<br><br><br>you have to edit:<br></p><p>-line 3 of the chklevel.php file. It have to reflect where the php files are.</p><p>-You should edit all the variables in preference.php. If the reading is incorrect, ajust the $compensation variable.<br><br><br></p>
<p>I am a little confused here, what do I need to edit? I have gone through all of the files, edited what I think I should, GPIO trig/echo, directories, etc. What needs to be cron'd? How often? Where does the data go? </p>
<p>I am not having any luck. My Measurements are 24&quot; deep pit, My Sensor is 20 inches above the pit. And, currently my water level is 4.5 inches. When I load up the page, those number are in no way reflected or translated. </p>

About This Instructable

4,795views

21favorites

License:

More by Luc Moreau:Precise glass bottle cutting jig Sump pump water level: The software Sump pump water level: The hardware 
Add instructable to: