Advertisement

Saturday, October 18, 2014

Recent Updates to HESA

I've been spending time in small bursts recently working on the code for the Home Environmental Sensor Array.

Status Page Updated with Graphs
First of all, I updated the HESA status web page to display a graph of the current day's settings.  I found some php code called PHPGraphLib that makes it easy to create graphs with PHP.  In order to use PHPGraphLib, I made a new PHP page that reads today's readings from the database and puts them in an array variable.  Then, the data in the array is added to the class for the graph.  Finally, PHPGraphLib dynamically creates the graph as an image file on the server.  The main HESA status page calls the php page with the graphing code.  The PHPGraphLib page has some good documentation and was fairly easy to get going.

I also changed the HESA status web page to have a simple table with the high, low, average, and current readings for each sensor.  There are links to bring up the last 48 readings for each sensor.  In the future, I would like to make graphs for monthly and yearly data.

The final change I made to the Hesa status web page is to show at a glance if the HESA is working or not.  It checks the last time something was written to the database.  If the last update time is over an hour old, the title of the page changes.  Also, the status shows up at the top of the page.  Now, I can tell if the HESA is transmitting or not just by looking at the title of the web page.

Basic Design Failed.  Design Changed.  Backup Pump Added.  
Recently, I was replacing the sump pump in my basement.  While the pump was out, the water softener turned on and started dumping water into the crock.  When the crock filled up, the HESA detected the water and shut off power to the water softener -- exactly as designed.  What I found out, is that the water softener continues dumping water into the sink without electricity.  In other words, shutting off power to the water softener does nothing.  Yar!

In order to fix this design problem, I did a couple of things.  First, I bought a submersible pump and battery powered sump pump but I would prefer to have a battery backup solution for the whole system.

added it to the crock.  The submersible pump will move water from the crock for the basement sink to the crock for the drain tiles.  The sump pump in the second crock will then move the water outside.  This will help when the first sump pump fails for some reason.  I still have a problem when the power in the basement fails.  Yes, I could have a

Finally, I changed the programming on the HESA so the Power Switch Tail is normally off.  When the HESA detects water, it sends a signal to the PST to turn it on and provide power to the submersible pump.  This is the opposite of the way the HESA provided power to the PST originally but it fixes the design flaw.

Send All Clear Message
One small improvement I made is to send an "all clear" message to the email address if the water goes away.  Now, when I am doing some testing, people will get a follow-up email when all is well.

HESA Not Transmitting
I have been having problems with the HESA not transmitting.

First, There were some bugs in the code that would stop the program if it could not reach the internet.  I fixed those.

Next, the GFCI outlet that my network hub was plugged in to would trip on occasion.  The HESA would stay running but it could not send any data to the internet.  I had to fix this because the sump pump was also plugged into the same power outlet.

That GFCI outlet has a freezer plugged in to it, plus the sump pump, and a power strip with my network hub and a small clock.  For some reason, the outlet would trip when the sump pump tried to run sometimes.  Perhaps it was when the freezer motor was also kicking on.  I solved this problem by adding a bigger outlet and a second GFCI outlet.  Now, the freezer has its own 20 amp GFCI outlet.  The sump pump and power strip share the other 20 amp GFCI outlet.  I have not had any more problems with the GFCI outlets tripping since I made this change.

Even after these changes, once or twice a week, the HESA still stops transmitting.  When I check the processes that are running, there is no HESA program.  It appears that some kind of run-time bug causes the program to stop.  I need to start recording everything that happens in a log file so I can see where it stops.  Then, I can fix the code to handle the errors.

Until then, I made a change the /etc/rc.local file to hopefully restart the program if it fails.  Here is the code.

until sudo python /home/pi/python/hesa.py; do                
    echo "HESA crashed with exit code $?.  Respawning.." >&2 
    sleep 1                                                  
done                                                         

The HESA rebooted and started just fine.  We'll see if this change to the rc.local file fixes the HESA from stopping or not.