Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
def light():
	now=datetime.datetime.now()
	lastoff=util.db_getvalue(config.DB_LIGHTSOFF)
	if lastoff is None:
		flash('No Last Lights Out Event.')
		lastoff=now.strftime(config.DBDATEFORMAT)
	# if arrived here by submitting the form, perform the action
	if request.method == 'POST':
		value=request.form['value']
		line=request.form['line'] 
		if line not in config.LINES.keys() or value not in {'on','off'}:
			flash('Internal error. No lights changed.')
			return redirect(url_for('/'))
		s=True if value=='on' else False
		if "Apagar15" in request.form:
			cpid=os.fork()
			if cpid==0:
				time.sleep(15)
				util.setLight(config.LINES[line],s)
				shutdown=request.environ.get('werkzeug.server.shutdown')
				shutdown()
		elif "Apagar60" in request.form:
			cpid=os.fork()
			if cpid==0:
				time.sleep(60)
				util.setLight(config.LINES[line],s)
				shutdown=request.environ.get('werkzeug.server.shutdown')
				shutdown()
		else:
			util.setLight(config.LINES[line],s)
		# write switch off event to db
		if not s:
			util.db_setvalue(config.DB_LIGHTSOFF,now.strftime(config.DBDATEFORMAT))
			lastoff=None
	s1=util.getLight(config.LINES['R1LINE'])
	if lastoff is None:
		delta=None
	else:
		delta=now-datetime.datetime.strptime(lastoff,'%Y-%m-%d %H:%M:%S')
	tData={
		's1':s1,
		'time':now.strftime(config.DATEFORMAT),
		'lastoff':util.prettydelta(delta)
	}
	return render_template('light.html',**tData)