Beispiel #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)
Beispiel #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)