0

I am working on a project which involves reading the temperature and humidity using DHT22 sensor.

I would like to display these values on a GUI, and continuously update the values on the GUI.

Also I would like to have this script start at boot up.

I have achieved getting the script to boot up and the GUI to appear by adding sensorstartup.desktop file to the ~./config/autostart,file consist of a sh script pointing to sudo python /home/pi/GUISENSOR.py

The problem I am running into is that it will not update the GUI at boot up, the GUI appears but no update, but if I run it manually sudo python /home/pi/GUISENSOR.py, it runs and updates correctly.

Any suggestions would be greatly appreciated.

Below is a sample of the code

class App(threading.Thread):

def _init_(self):
    threading.Thread._init_(self)
    self.start()
def callback(self):
    self.root.quit()
def run(self):
    self.root = Tk() #Makes the window
    self.root.wm_title("Temperature Monitor") 
    self.root.minsize(200,100)

    #Left Frame and its contents
    leftFrame = Frame(self.root, width=200, height = 600)
    leftFrame.grid(row=0, column=0, padx=10, pady=2)

    Label(leftFrame, text="Equiptment").grid(row=0, column=0, padx=10, pady=2)

    self.equipTemp = DoubleVar()
    Label(leftFrame, textvariable=self.equipTemp).grid(row=5, column=0, padx=10, pady=2)
    Label(leftFrame, text="deg F").grid(row=5, column=1, padx=10, pady=2)

    self.root.mainloop() #start monitoring and updating the GUI


app = App()
app.start()

# Continuously append data
while(True):

    # Run the DHT program to get the humidity and temperature readings!
    output = subprocess.check_output(["./temp_sensor"]);

    matches = re.search("Temp =\s+([0-9.]+)", output)
    if (not matches):
      time.sleep(3)
      continue
    tempC = float(matches.group(1))
    tempF = tempC * 1.8 + 32
    tempF = round(tempF)
    tempF = int(tempF)

    print "Temperature: %.1f F" % tempF


    if tempC > max_temp:
      oos += 1
    elif tempC < min_temp:
      oos += 1
    else:
      oos = 0

    if oos > bad_readings:
      oos = 0
      emailer(email_addr, room_subject + " " + str(tempF) + " degF " )



    app.equipTemp.set(tempF)


    # Wait 30 seconds before continuing
    time.sleep(30)
  • your indentation is incorrect. How much of the code at the end of the file is inside the `while(True)` block, and how much of the code is inside the class? – Bryan Oakley Sep 12 '13 at 20:16
  • all the code below the while(True) block belongs to it, and code above it belongs to the class. I have corrected the indentation error, thanks – user2773452 Sep 12 '13 at 20:34
  • take a look at [this](https://stackoverflow.com/a/10556698/4226702) answer – Alexander Dmitriev Mar 01 '19 at 14:42

0 Answers0