Compare commits
4 Commits
master
...
developmen
Author | SHA1 | Date | |
---|---|---|---|
|
ab847d0c5c | ||
|
627e799142 | ||
|
3a01222dfb | ||
|
3df0308700 |
@ -1,8 +1,14 @@
|
|||||||
CREATE TABLE IF NOT EXISTS `temperatures` (
|
CREATE TABLE IF NOT EXISTS `temperatures` (
|
||||||
`id` int(255) NOT NULL AUTO_INCREMENT,
|
`id` int(255) NOT NULL AUTO_INCREMENT,
|
||||||
`temperature` double NOT NULL,
|
|
||||||
`humidity` varchar(20) NOT NULL,
|
`humidity` varchar(20) NOT NULL,
|
||||||
`dateMeasured` date NOT NULL,
|
`dateMeasured` date NOT NULL,
|
||||||
`hourMeasured` int(128) NOT NULL,
|
`hourMeasured` int(128) NOT NULL,
|
||||||
|
`temperature-1` double NOT NULL,
|
||||||
|
`temperature-2` double NOT NULL,
|
||||||
|
`temperature-3` double NOT NULL,
|
||||||
|
`temperature-4` double NOT NULL,
|
||||||
|
`pressure` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
`pressure-sea` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
`altitude` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
|
||||||
|
1
development.txt
Normal file
1
development.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Branch Development
|
112
scheduler.py
112
scheduler.py
@ -11,79 +11,91 @@ import datetime
|
|||||||
databaseUsername="XXXX"
|
databaseUsername="XXXX"
|
||||||
databasePassword="XXXX"
|
databasePassword="XXXX"
|
||||||
databaseName="XXXX" #do not change unless you named the Wordpress database with some other name
|
databaseName="XXXX" #do not change unless you named the Wordpress database with some other name
|
||||||
|
databaseHost="XXXXX.domain.de"
|
||||||
def saveToDatabase(temperature,humidity):
|
|
||||||
|
|
||||||
con=mdb.connect("localhost", databaseUsername, databasePassword, databaseName)
|
|
||||||
currentDate=datetime.datetime.now().date()
|
|
||||||
|
|
||||||
now=datetime.datetime.now()
|
|
||||||
midnight=datetime.datetime.combine(now.date(),datetime.time())
|
|
||||||
minutes=((now-midnight).seconds)/60 #minutes after midnight, use datead$
|
|
||||||
|
|
||||||
|
|
||||||
with con:
|
idef saveToDatabase(temp1, temp2, temp3, temp4, humidity, pressure, sea_pressure, altitude):
|
||||||
cur=con.cursor()
|
|
||||||
|
|
||||||
cur.execute("INSERT INTO temperatures (temperature,humidity, dateMeasured, hourMeasured) VALUES (%s,%s,%s,%s)",(temperature,humidity,currentDate, minutes))
|
con=mdb.connect(databaseHost, databaseUsername, databasePassword, databaseName)
|
||||||
|
currentDate=datetime.datetime.now().date()
|
||||||
|
print currentDate
|
||||||
|
now=datetime.datetime.now()
|
||||||
|
midnight=datetime.datetime.combine(now.date(),datetime.time())
|
||||||
|
minutes=((now-midnight).seconds)/60 #minutes after midnight, use datead$
|
||||||
|
|
||||||
print "Saved temperature"
|
|
||||||
return "true"
|
with con:
|
||||||
|
cur=con.cursor()
|
||||||
|
query = ("INSERT INTO `temperatures`(`temperature-1`, `temperature-2`, `temperature-3`, `temperature-4`, `humidity`, `dateMeasured`, `hourMeasured`, `pressure`, `pressure-sea`, `altitude`)"
|
||||||
|
"VALUES (%s,%s,%s,%s,%s,'%s',%s,%s,%s,%s)"% (temp1, temp2, temp3, temp4, humidity, currentDate, minutes, pressure, sea_pressure, altitude))
|
||||||
|
cur.execute(query)
|
||||||
|
|
||||||
|
print "Saved temperature"
|
||||||
|
return "true"
|
||||||
|
|
||||||
|
|
||||||
def readInfo():
|
def readInfo():
|
||||||
temperatureSaved="false" #keep on reading till you get the info
|
temperatureSaved="false" #keep on reading till you get the info
|
||||||
|
|
||||||
while(temperatureSaved=="false"):
|
while(temperatureSaved=="false"):
|
||||||
# Run the DHT program to get the humidity and temperature readings!
|
# Run the DHT program to get the humidity and temperature readings!
|
||||||
|
|
||||||
output = subprocess.check_output(["/home/pi/myweather/wetter.py"]);
|
source = "/home/pi/myweather/weather.py"
|
||||||
print output
|
|
||||||
matches = re.search("Temp =\s+([-]?[0-9.]+)", output)
|
|
||||||
if (not matches):
|
|
||||||
time.sleep(3)
|
|
||||||
continue
|
|
||||||
temp = float(matches.group(1))
|
|
||||||
|
|
||||||
# search for humidity printout
|
# search for tempretures , continue to search untill it do not found
|
||||||
matches = re.search("Press =\s+([0-9.]+)", output)
|
temp1 = search_attr('Temp1', source)
|
||||||
if (not matches):
|
temp2 = search_attr('Temp2', source)
|
||||||
time.sleep(3)
|
temp3 = search_attr('Temp3', source)
|
||||||
continue
|
temp4 = search_attr('Temp4', source)
|
||||||
humidity = float(matches.group(1))
|
|
||||||
#humidity=str(humidity)+"%"
|
|
||||||
|
|
||||||
print "Temperature: %.1f C" % temp
|
"scheduler.py" 108 lines, 3613 characters
|
||||||
print "Pressure: %s %%" % humidity
|
|
||||||
|
|
||||||
return saveToDatabase(temp,humidity)
|
print "Temperature-1: %.1f C" % temp1
|
||||||
|
print "Temperature-2: %.1f C" % temp2
|
||||||
|
print "Temperature-3: %.1f C" % temp3
|
||||||
|
print "Temperature-4: %.1f C" % temp4
|
||||||
|
print "Humidity: %s %%" % humidity
|
||||||
|
print "Pressure: %s %%" % pressure
|
||||||
|
print "Pressure-Sea: %s %%" % sea_pressure
|
||||||
|
print "Altitude: %s ft" % altitude
|
||||||
|
return saveToDatabase(temp1, temp2, temp3, temp4, humidity, pressure, sea_pressure, altitude)
|
||||||
|
|
||||||
|
|
||||||
|
def search_attr(val, source):
|
||||||
|
output = subprocess.check_output([source]);
|
||||||
|
matches = re.search(("%s =\s+([-]?[0-9.]+)" % val), output)
|
||||||
|
if (not matches):
|
||||||
|
print "searching for %s"% (val)
|
||||||
|
time.sleep(3)
|
||||||
|
search_attr(val, source)
|
||||||
|
return float(matches.group(1))
|
||||||
|
|
||||||
#check if table is created or if we need to create one
|
#check if table is created or if we need to create one
|
||||||
try:
|
try:
|
||||||
queryFile=file("createTable.sql","r")
|
queryFile=file("createTable.sql","r")
|
||||||
|
|
||||||
con=mdb.connect("localhost", databaseUsername,databasePassword,databaseName)
|
con=mdb.connect(databaseHost databaseUsername,databasePassword,databaseName)
|
||||||
currentDate=datetime.datetime.now().date()
|
currentDate=datetime.datetime.now().date()
|
||||||
|
|
||||||
with con:
|
with con:
|
||||||
line=queryFile.readline()
|
line=queryFile.readline()
|
||||||
query=""
|
query=""
|
||||||
while(line!=""):
|
while(line!=""):
|
||||||
query+=line
|
query+=line
|
||||||
line=queryFile.readline()
|
line=queryFile.readline()
|
||||||
|
|
||||||
cur=con.cursor()
|
cur=con.cursor()
|
||||||
cur.execute(query)
|
cur.execute(query)
|
||||||
|
|
||||||
#now rename the file, because we do not need to recreate the table everytime this script is run
|
#now rename the file, because we do not need to recreate the table everytime this script is run
|
||||||
queryFile.close()
|
queryFile.close()
|
||||||
os.rename("createTable.sql","createTable.sql.bkp")
|
os.rename("createTable.sql","createTable.sql.bkp")
|
||||||
|
|
||||||
|
|
||||||
except IOError:
|
except IOError:
|
||||||
pass #table has already been created
|
pass #table has already been created
|
||||||
|
|
||||||
status="false"
|
status="false"
|
||||||
while(status!="true"):
|
while(status!="true"):
|
||||||
|
|
||||||
status=readInfo()
|
status=readInfo()
|
||||||
|
Loading…
Reference in New Issue
Block a user