Advertisement

Friday, May 23, 2014

Added Array to HESA Python Code

While at the Milwaukee Makerspace tonight I decided to update the python code for my Home Environmental Sensor Array (HESA).  It gives false readings once a week or so -- telling me there is water in the basement when there is not.  I would like to know what readings it is seeing.  Ideally, I would write the readings to a database but for now, I am going to write the most recent readings to a web page.

The first thing the program changes do is record each of the readings for one cycle.  There are 1,000 readings per cycle.  Each reading is added to a list in python.  Here is the code to add the data to the list.
if GPIO.input(pinIn) == GPIO.HIGH:
  retHighCount += 1
  retTestNbr[circuitTimer] = 1
  if retHighCount > 500: 
    retResult = 1
  else:
    retTestNbr[circuitTimer] = 0

circuitTimer += 1
retTestNbr is the list variable.  A value of 1 means power was found.  A value of 0 means nothing was returned.

Every 10 minutes or whenever electricity is detected, the program will write the current data to the web page.  There are 1,000 readings per cycle.  So, the program will write 20 lines of 50 readings.  The readings should either be a 0 or a 1.  The web page is overwritten if if already exists.  Here is the code to do that.

 with open('/var/www/hesaStatus.htm', 'w') as webPage:
        webPage.write('<HTML>\n')
        webPage.write('<HEAD>\n')
        webPage.write('<TITLE>HESA Status</TITLE>\n')
        webPage.write('</HEAD>\n')
        webPage.write('<BODY>\n')
        webPage.write('<H1>Home Environmental Sensor Array Status</H1>\n')
        webPage.write('<b>Start date and time:</b> ' + strSDT + '<br>\n')
        webPage.write('<b>Current date and time:</b> ' + str(datetime.now()) + '\n')
        webPage.write('<p><b>Last water sensing status:</b> ' + str(wSS) + '.<br>\n')
        webPage.write('<b>High count:</b> ' + str(hc) + '.<br>\n')
        webPage.write('<b>Readings:</b><p>\n')
        rLoop = 0
        while (rLoop < 20):
            cLoop = 0
            while (cLoop < 50):
                webPage.write(str(tn[cLoop + (rLoop * 50)]))
                cLoop += 1

            webPage.write('<br>\n')
            rLoop += 1

        webPage.write('</BODY>\n')
        webPage.write('</HTML>\n')
 Next, I need to install the code on the Raspberry Pi that runs the HESA and see if it works.  Maybe I can narrow down why I am getting false readings.

No comments:

Post a Comment