Exemplo n.º 1
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)
Exemplo n.º 2
0
def conf():
	cloud='on' if util.isCloudActive() else 'off'
	now=datetime.datetime.now().strftime(config.DATEFORMAT)
	res=None
	# if arrived here by submitting the form
	if request.method == 'POST':
		# get setting for webcam resolution
		res=request.form['res']
		util.db_setvalue(config.DB_WEBCAMRES,res)
		# get setting for cloud save desired state
		clds=request.form['cloud']
		# and try to start it if it was stopped
		if cloud=='off' and clds=='on':
			ps=subprocess.Popen("sudo /etc/init.d/thingspeak start", shell=True, stdout=subprocess.PIPE)
			flash('ThingSpeak daemon started')
		elif cloud=='on' and clds=='off':
			ps=subprocess.Popen("sudo /etc/init.d/thingspeak stop", shell=True, stdout=subprocess.PIPE)
			flash('ThingSpeak daemon stopped')
		flash('Settings saved')
	else:
		res=util.nvl(util.db_getvalue(config.DB_WEBCAMRES),'640x480')

	db=util.db_get()
	with db:
		c=db.cursor()
		q="SELECT * FROM ACCESS ORDER BY DATETIME DESC LIMIT 100"
		c.execute(q)
		rows=c.fetchall()
		log=''
		for row in rows:
			log=log+row[0]+';'+row[1]+';'+row[2]+';'+row[3]+';'+row[4]+'\n'
	tData={
		'cloud':cloud,
		'res':res,
		'time':now,
		'log':log
	}
	return render_template('conf.html',**tData)