#!/usr/bin/python import RPi.GPIO as GPIO import time import glob import os import MySQLdb import time #getVarFromFile(filename) path = '/opt/tempberrypi' def getVarFromFile(filename): import imp f = open(filename) global data data = imp.load_source('data', '', f) f.close() getVarFromFile(path + '/etc/TBp1.conf') # MySQL Connection db = MySQLdb.connect(data.servername,data.username,data.password,data.dbname) cursor = db.cursor() # find the path of a sensor directory that starts with 28 i = 1 devicelist = glob.glob('/sys/bus/w1/devices/*/state') set_sensor_on = "" sensor_interval = 5 print "\n" for sensor in devicelist: sensor_file = sensor sensor_id = sensor_file.split('/') # Select qSQL with id=4. cursor.execute("SELECT * FROM sensors_info WHERE sensor_id = '"+ str(sensor_id[5]) +"'") row = cursor.fetchone() if row: if (row[4] == "on" and row[5] == "yes"): sensor_interval = row[10] set_sensor_on = str(set_sensor_on) + " " + str(sensor_interval) + " " + str(sensor_id[5]) name = row[1] if (row[3] != ''): name = row[3] #print "sensor = "+ str(name) + ", state = "+ str(row[4]) + ", setup = "+ str(row[5]) +"" print "E-Button: \""+ str(name) + "\" is being turned on" if (set_sensor_on != ''): kill = "ps -aef | grep emergency-button-daemon | awk '{print $2}' | xargs -i++ kill -9 ++" os.system(kill) cmd = 'su www-data -c "'+ path + '/bin/emergency-button-daemon ' + str(set_sensor_on) + ' &"' os.system(cmd) else: cmd = "ps -aef | grep emergency-button-daemon | awk '{print $2}' | xargs -i++ kill -9 ++" os.system(cmd)