def status(): tData={} ts=[] sw=[] pr=[] # internal temp for i,f in enumerate(config.TEMP_SENSORS): t=util.getTemperature(i) s='N/A' if t is None else "%2.1f" % t ts.append([f,config.TEMP_ALIAS[i],s]) # external temp r=radio.radio() t=r.getTemp(2) s='N/A' if t is None else "%2.1f" % t ts.append(['nrf24l01+','Exterior',s]) for i in config.LINES.items(): t=util.nvl(util.getLight(i[1]),'N/A') sw.append([i[0],i[1],t]) p1=bmp180.BMP180() if p1._device._address: px="0x%x" % p1._device._address p2=util.nvl(util.getPressure(),'N/A') pr.append(['Presion',px,p2]) tData={ 'ts':ts, 'sw':sw, 'pr':pr } return render_template('s.html',**tData)
def index(): now=datetime.datetime.now().strftime(config.DATEFORMAT) # cloud TS service status cloud='on' if util.isCloudActive() else 'off' # temperature fTemp1=util.getTemperature(0) temp1="%2.1f" % fTemp1 # external temp r=radio.radio() t=r.getTemp(2) text='N/A' if t is None else "%2.1f" % t # pressure p1=util.getPressure() # light s1=util.getLight(config.LINES['R1LINE']) # last time the ligth was switched off lastoff=util.db_getvalue(config.DB_LIGHTSOFF) if lastoff is None: loe='<no disponible>' else: loe=lastoff tData={ 'temp1':temp1, 'text':text, 'pres1':p1, 's1':s1, 'time':now, 'loe':loe, 'cloud':cloud } return render_template('index.html',**tData)
def sendData(radio): try: temp1=util.getTemperature(0) temp2=util.getTemperature(1) temp3=util.getTemperature(2) pressure=util.getPressure() temp4=radio.getTemp() if temp4 is None: params = urllib.urlencode({'field1': temp1, 'field2': temp2, 'field3': pressure, 'field4': temp3, 'key':'M3WA24ZHF4KDYM56'}) else: params = urllib.urlencode({'field1': temp1, 'field2': temp2, 'field3': pressure, 'field4': temp3, 'field5': temp4, 'key':'M3WA24ZHF4KDYM56'}) headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"} conn = httplib.HTTPConnection("api.thingspeak.com:80") conn.request("POST", "/update", params, headers) response = conn.getresponse() print response.status, response.reason data = response.read() conn.close() except Exception: pass
params = urllib.urlencode({'field1': temp1, 'field2': temp2, 'field3': pressure, 'field4': temp3, 'field5': temp4, 'key':'M3WA24ZHF4KDYM56'}) headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"} conn = httplib.HTTPConnection("api.thingspeak.com:80") conn.request("POST", "/update", params, headers) response = conn.getresponse() print response.status, response.reason data = response.read() conn.close() except Exception: pass #sleep for 300 seconds (api limit of 15 secs) if __name__ == "__main__": # start checks - print data at startup radio=radio.radio() temp1=util.getTemperature(0) temp2=util.getTemperature(1) temp3=util.getTemperature(2) pressure=util.getPressure() temp4=radio.getTemp() print temp1," degrees" print temp2," degrees" print temp3," degrees" print pressure, " mbar" if radio is None: params = urllib.urlencode({'field1': temp1, 'field2': temp2, 'field3': pressure, 'field4': temp3, 'key':'M3WA24ZHF4KDYM56'}) else: params = urllib.urlencode({'field1': temp1, 'field2': temp2, 'field3': pressure, 'field4': temp3, 'field5': temp4, 'key':'M3WA24ZHF4KDYM56'}) print temp4," degrees" print params # end checks