WordPress.com



# DOMUS 3.2# Sampling Arduino sensors#import smtplibimport httplib2import datetimeimport osh = httplib2.Http(".cache")## Interrogo sonde temperatura e scrivo log#resp, temp0 = h.request("", "post")resp, temp1 = h.request("", "post")fh = open("C:\Domus\Temperature.csv", "a")fh.write (str(datetime.datetime.now().strftime("%y-%m-%d,%H:%M")))fh.write (",")fh.write (str (temp0.decode('utf-8')))fh.write (",")fh.write (str (temp1.decode('utf-8')))fh.write ("\n")fh.close()## Interrogo sonde Emon e scrivo log#resp, emon = h.request("http:// mioserver.:85/Emon", "post")emon = emon.decode('utf-8')fh = open("C:\Domus\Emon.csv", "a")fh.write (str(datetime.datetime.now().strftime("%y-%m-%d,%H:%M")))fh.write (",")fh.write (emon.split(';')[0])fh.write (",")fh.write (emon.split(';')[1])fh.write (",")fh.write (emon.split(';')[2])fh.write ("\n")fh.close()## Interrogo sonde Light e Heating e scrivo log#resp, light = h.request("http:// mioserver.:85/Lux", "post")resp, heating = h.request("http:// mioserver.:85/Alarm", "post")fh = open("C:\Domus\light.csv", "a")fh.write (str(datetime.datetime.now().strftime("%y-%m-%d,%H:%M")))fh.write (",")fh.write (str (light.decode('utf-8')))fh.write (",")fh.write (str (heating.decode('utf-8')))fh.write ("\n")fh.close()## Regolo a 100 valori i file csv dei log#os.system('"C:\\Batch\\tail-temp.bat"')os.system('"C:\\Batch\\tail-temp1.bat"')os.system('"C:\\Batch\\tail-Emon.bat"')## Invio un mail in caso di blocco caldaia (heating=0)#if (str (heating.decode('utf-8'))) == "0": fromaddr = 'miamail1@' toaddrs = 'miamail2@' msg = 'Subject:Caldaia in blocco!' username = 'miamail1 @' password = 'miapassword' server = smtplib.SMTP('smtp.:587') server.starttls() server.login(username,password) server.sendmail(fromaddr, toaddrs, msg) server.quit()print ("*** End sampling ***") ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download