this is my first post so be gentle pls
i have an issue with 2 skripts. im trying to send temperature readings (dht22 sensor) via email using python.
1 code:
Code: Select all
import smtplib
import Adafruit_DHT
while True:
sensor = Adafruit_DHT.DHT22
pin = 18
humidity, temperature = Adafruit_DHT.read_retry(sensor,pin)
if (temperature > 22.5):
print(temperature)
smtpUser = "email"
smtpPass = "password"
toAdd = "email"
fromAdd = smtpUser
subject = "the temperature is to high"
header = "To: " + toAdd + "\n" + "From:" + fromAdd + "\n" + "Subject:" + subject
body = ("Warning: temp: {0:0.1f} C".format(temperature))
print(header + "\n" + body)
s = smtplib.SMTP("smtp.gmail.com", 587)
s.ehlo()
s.starttls()
s.ehlo()
s.login(smtpUser, smtpPass)
s.sendmail(fromAdd, toAdd, header + "\n\n" + body)
s.quit()
Code: Select all
import Adafruit_DHT
import time
while True:
sensor = Adafruit_DHT.DHT22
pin = 18
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
print("Temp: {1:0.1f} C Humidity: {0:0.1f} %".format(humidity, temperature))
time.sleep(2)into the first one. for that i wrote this:
Code: Select all
import smtplib
import dht22temp
if temperature < 22.0:
smtpUser = "email"
smtpPass = "password"but with the second try(the one with module DHT22temp.py imported): i keep getting the temperature readings in the python shell... the if conditional doesnt make anything and i dont get emails...
I dont know if its somethjing to do with the adafruit library that i used for the temperature code, or i have to difine more variables in email code. i just want to import the part that reads the temperature and add it to the email. just like the first try, but there i had to copy paste the code from the dht22temp.py and well yeah it should be easier that that.
srry for the english, its not my first language :p
THanks a lot!