Compare commits
4 Commits
master
...
developmen
Author | SHA1 | Date | |
---|---|---|---|
|
ab847d0c5c | ||
|
627e799142 | ||
|
3a01222dfb | ||
|
3df0308700 |
33
README.md
33
README.md
@ -1,33 +1,2 @@
|
||||
# myweather
|
||||
My Weather for Raspberry Pi with BMP180 / BMP085 / DS18B20<br/>
|
||||
<img src="http://blog.unixweb.de/wp-content/uploads/2015/05/bmp180.jpg">
|
||||
<img src="http://blog.unixweb.de/wp-content/uploads/2015/05/BMP085.jpg"><br/>
|
||||
<img src="http://blog.unixweb.de/wp-content/uploads/2015/05/ds18b20-pinout.jpg">
|
||||
<img src="http://blog.unixweb.de/wp-content/uploads/2015/05/DS18B20-e1431072161767.png"><br/>
|
||||
|
||||
<img src="https://raw.githubusercontent.com/unixweb/myweather/master/weather-app.png"><br/>
|
||||
|
||||
Installation for Adafruit Python-Modules needed:<br/>
|
||||
<br/>
|
||||
sudo apt-get update<br/>
|
||||
sudo apt-get install git build-essential python-dev python-smbus<br/>
|
||||
git clone https://github.com/adafruit/Adafruit_Python_BMP.git<br/>
|
||||
cd Adafruit_Python_BMP<br/>
|
||||
sudo python setup.py install<br/>
|
||||
<br/>
|
||||
sudo apt-get install python-mysqldb<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
Insert the required database parameter in "scheduler.py" for WordPress Plugin <br/>
|
||||
databaseUsername="XXXXX"<br/>
|
||||
databasePassword="XXXXX"<br/>
|
||||
databaseName="XXXXX" #do not change unless you named the Wordpress database with some other name<br/>
|
||||
databaseHost="www.xxx.de"<br/>
|
||||
Install the WordPress Plugin <br/>
|
||||
<br/>
|
||||
Start "./scheduler.py" manually and check if there any errors.<br/>
|
||||
<br/>
|
||||
vi /etc/cron.d/weather <br/>
|
||||
*/15 * * * * pi /home/pi/myweather/scheduler.py > /dev/null<br/>
|
||||
<br/>
|
||||
Demo: http://blog.joachimhummel.de/category/wetter<br/>
|
||||
My Weather for Raspberry Pi with BMP180 / BMP085
|
||||
|
@ -1,15 +1,14 @@
|
||||
CREATE TABLE IF NOT EXISTS `temperatures` (
|
||||
`id` int(255) NOT NULL AUTO_INCREMENT,
|
||||
`humidity` varchar(20) NOT NULL,
|
||||
`dateMeasured` date 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,
|
||||
`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,
|
||||
`humidity` varchar(20) NOT NULL,
|
||||
`pressure-sea` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`altitude` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
|
||||
|
||||
|
1
development.txt
Normal file
1
development.txt
Normal file
@ -0,0 +1 @@
|
||||
Branch Development
|
@ -1,37 +0,0 @@
|
||||
+++++++++++++++++++++++
|
||||
Version 1.3 January 2017
|
||||
|
||||
Added Locale Altitude for display correct Sea-Pressure and Barometric Altitude
|
||||
|
||||
+++++++++++++++++++++++
|
||||
Version 1.2 June 5 2015
|
||||
|
||||
Support now 1 * BMP180 Sensors
|
||||
Support now 3 * DS18B20 Sensors
|
||||
|
||||
+++++++++++++++++++++++
|
||||
Version 1.1 May 21 2015
|
||||
|
||||
Update for scheduler.py, createTable.sql , weather.py
|
||||
|
||||
Changes for scheduler.py:
|
||||
|
||||
Update new database design for input temp1,temp2,temp3,temp4,humidity,pressure,pressure_sea,altitude
|
||||
|
||||
Changes for createTabe.sql:
|
||||
|
||||
New database design for input temperature_11,temperature_12,temperature_13,temperature_14,humidity,pressure,pressure_sea,altitude
|
||||
|
||||
Changes for weather.py:
|
||||
Remove print for new import with scheduler.py
|
||||
|
||||
++++++++++++++++++++++++
|
||||
Version 1.0 May 5 2015
|
||||
|
||||
Upload basic files
|
||||
|
||||
scheduler.py
|
||||
createTable.sql
|
||||
weather.py
|
||||
status.py
|
||||
|
116
scheduler.py
Executable file → Normal file
116
scheduler.py
Executable file → Normal file
@ -7,19 +7,74 @@ import sys
|
||||
import time
|
||||
import MySQLdb as mdb
|
||||
import datetime
|
||||
from weather import *
|
||||
|
||||
databaseUsername="XXXXX"
|
||||
databasePassword="XXXXX"
|
||||
databaseName="XXXXX" #do not change unless you named the Wordpress database with some other name
|
||||
databaseHost="www.xxx.de"
|
||||
databaseUsername="XXXX"
|
||||
databasePassword="XXXX"
|
||||
databaseName="XXXX" #do not change unless you named the Wordpress database with some other name
|
||||
databaseHost="XXXXX.domain.de"
|
||||
|
||||
|
||||
idef saveToDatabase(temp1, temp2, temp3, temp4, humidity, pressure, sea_pressure, altitude):
|
||||
|
||||
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$
|
||||
|
||||
|
||||
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():
|
||||
temperatureSaved="false" #keep on reading till you get the info
|
||||
|
||||
while(temperatureSaved=="false"):
|
||||
# Run the DHT program to get the humidity and temperature readings!
|
||||
|
||||
source = "/home/pi/myweather/weather.py"
|
||||
|
||||
# search for tempretures , continue to search untill it do not found
|
||||
temp1 = search_attr('Temp1', source)
|
||||
temp2 = search_attr('Temp2', source)
|
||||
temp3 = search_attr('Temp3', source)
|
||||
temp4 = search_attr('Temp4', source)
|
||||
|
||||
"scheduler.py" 108 lines, 3613 characters
|
||||
|
||||
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
|
||||
try:
|
||||
queryFile=file("createTable.sql","r")
|
||||
|
||||
con=mdb.connect(databaseHost,databaseUsername,databasePassword,databaseName)
|
||||
con=mdb.connect(databaseHost databaseUsername,databasePassword,databaseName)
|
||||
currentDate=datetime.datetime.now().date()
|
||||
|
||||
with con:
|
||||
@ -40,52 +95,7 @@ try:
|
||||
except IOError:
|
||||
pass #table has already been created
|
||||
|
||||
def saveToDatabase(temp1, temp2, temp3, temp4, humidity, pressure, sea_pressure, altitude):
|
||||
#print "SaveToDatabase Hit"
|
||||
|
||||
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 "Minutes",minutes
|
||||
|
||||
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 "false"
|
||||
|
||||
|
||||
def readInfo():
|
||||
#print "ReadInfo Hit"
|
||||
temperatureSaved="false"
|
||||
while(temperatureSaved=="false"):
|
||||
temp1 = Temp1
|
||||
temp2 = Temp2
|
||||
temp3 = Temp3
|
||||
temp4 = Temp4
|
||||
humidity=Humidity
|
||||
altitude = Altitude
|
||||
pressure = Pressure
|
||||
sea_pressure = Sea_pressure
|
||||
print "Temp1 : ",temp1
|
||||
print "Temp2 : ",temp2
|
||||
print "Temp3 : ",temp3
|
||||
print "Temp4 : ",temp4
|
||||
print "Humidity : ",humidity
|
||||
print "Altitude : ",altitude
|
||||
print "Pressure : ",pressure
|
||||
print "Sea Pressure : ",sea_pressure
|
||||
#return "false"
|
||||
#temperatureSaved="true"
|
||||
return saveToDatabase(temp1, temp2, temp3, temp4, humidity, pressure, sea_pressure, altitude)
|
||||
status="false"
|
||||
while(status!="true"):
|
||||
|
||||
status=readInfo()
|
||||
|
||||
|
||||
|
||||
|
@ -1,3 +0,0 @@
|
||||
PRESS1=`python /home/pi/myweather/pressure.py`
|
||||
|
||||
mosquitto_pub -h mqtt.unixweb.de -p 1883 -t abcde/p1 -m $PRESS1
|
@ -1,3 +0,0 @@
|
||||
TEMP=`python /home/pi/myweather/temperature.py |head -1`
|
||||
|
||||
mosquitto_pub -h mqtt.unixweb.de -p 1883 -t abcde/temp1 -m $TEMP
|
18
status.py
18
status.py
@ -10,7 +10,7 @@ import Adafruit_BMP.BMP085 as BMP085
|
||||
#
|
||||
# For the Beaglebone Black the library will assume bus 1 by default, which is
|
||||
# exposed with SCL = P9_19 and SDA = P9_20.
|
||||
#sensor = BMP085.BMP085()
|
||||
sensor = BMP085.BMP085()
|
||||
|
||||
# Optionally you can override the bus number:
|
||||
#sensor = BMP085.BMP085(busnum=2)
|
||||
@ -19,19 +19,9 @@ import Adafruit_BMP.BMP085 as BMP085
|
||||
# BMP085_STANDARD, BMP085_HIGHRES, or BMP085_ULTRAHIGHRES. See the BMP085
|
||||
# datasheet for more details on the meanings of each mode (accuracy and power
|
||||
# consumption are primarily the differences). The default mode is STANDARD.
|
||||
sensor = BMP085.BMP085(mode=BMP085.BMP085_ULTRAHIGHRES)
|
||||
|
||||
# Please set your locale altitude
|
||||
# http://www.latlong.net/ Helps to find your Langitude and Latitude
|
||||
# http://www.mapcoordinates.net/ Helps to Find the Data in Meter
|
||||
locale_altitude = 570
|
||||
|
||||
|
||||
seapFloat = sensor.read_sealevel_pressure(locale_altitude)
|
||||
pressure = sensor.read_pressure()
|
||||
psea = pressure / pow(1.0 - locale_altitude/44330.0, 5.255)
|
||||
#sensor = BMP085.BMP085(mode=BMP085.BMP085_ULTRAHIGHRES)
|
||||
|
||||
print 'Temp = {0:0.2f} *C'.format(sensor.read_temperature())
|
||||
print 'Altitude = {0:0.2f} m'.format(sensor.read_altitude(seapFloat))
|
||||
print 'Altitude = {0:0.2f} m'.format(sensor.read_altitude())
|
||||
print 'Pressure = {0:0.2f} hPa'.format(sensor.read_pressure()/100)
|
||||
print "Pressure NN =%8.2f hPa" % (psea / 100.0)
|
||||
print 'Pressure NN = {0:0.2f} hPa'.format(sensor.read_sealevel_pressure()/100)
|
||||
|
@ -1,57 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Creation: 02.01.2013
|
||||
# Last Update: 07.04.2015
|
||||
#
|
||||
# Copyright (c) 2013-2015 by Georg Kainzbauer <http://www.gtkdb.de>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
|
||||
# import sys module
|
||||
import sys
|
||||
|
||||
# open 1-wire slaves list for reading
|
||||
file = open('/sys/devices/w1_bus_master1/w1_master_slaves')
|
||||
|
||||
# read 1-wire slaves list
|
||||
w1_slaves = file.readlines()
|
||||
|
||||
# close 1-wire slaves list
|
||||
file.close()
|
||||
|
||||
# print header for results table
|
||||
|
||||
# repeat following steps with each 1-wire slave
|
||||
for line in w1_slaves:
|
||||
|
||||
# extract 1-wire slave
|
||||
w1_slave = line.split("\n")[0]
|
||||
|
||||
# open 1-wire slave file
|
||||
file = open('/sys/bus/w1/devices/' + str(w1_slave) + '/w1_slave')
|
||||
|
||||
# read content from 1-wire slave file
|
||||
filecontent = file.read()
|
||||
|
||||
# close 1-wire slave file
|
||||
file.close()
|
||||
|
||||
# extract temperature string
|
||||
stringvalue = filecontent.split("\n")[1].split(" ")[9]
|
||||
|
||||
# convert temperature value
|
||||
temperature = float(stringvalue[2:]) / 1000
|
||||
|
||||
# print temperature
|
||||
print(str() + "%.1f" % temperature)
|
||||
#print temperature
|
||||
|
||||
|
||||
# quit python script
|
||||
sys.exit(0)
|
163
weather.py
Executable file → Normal file
163
weather.py
Executable file → Normal file
@ -14,16 +14,7 @@ import Adafruit_BMP.BMP085 as BMP085
|
||||
#
|
||||
# For the Beaglebone Black the library will assume bus 1 by default, which is
|
||||
# exposed with SCL = P9_19 and SDA = P9_20.
|
||||
sensor1 = BMP085.BMP085()
|
||||
sensor2 = "/sys/bus/w1/devices/w1_bus_master1/28-041470306aff/w1_slave"
|
||||
sensor3 = "/sys/bus/w1/devices/w1_bus_master1/28-0414709c63ff/w1_slave"
|
||||
sensor4 = ""
|
||||
|
||||
# Please set your locale altitude
|
||||
# http://www.latlong.net/ Helps to find your Langitude and Latitude
|
||||
# http://www.mapcoordinates.net/ Helps to Find the Data in Meter
|
||||
locale_altitude = 570
|
||||
|
||||
sensor = BMP085.BMP085()
|
||||
|
||||
# Optionally you can override the bus number:
|
||||
#sensor = BMP085.BMP085(busnum=2)
|
||||
@ -34,153 +25,5 @@ locale_altitude = 570
|
||||
# consumption are primarily the differences). The default mode is STANDARD.
|
||||
#sensor = BMP085.BMP085(mode=BMP085.BMP085_ULTRAHIGHRES)
|
||||
|
||||
# getSeaLelvelPres
|
||||
# Sensor = BMP180
|
||||
# Output = SeaPresFloat
|
||||
SeaPresFlot = sensor1.read_sealevel_pressure(locale_altitude)
|
||||
|
||||
# getTemp1() method
|
||||
# Sensor1 = BMP085
|
||||
# Output= Temp1
|
||||
def getTemp1():
|
||||
temperature1 = format(sensor1.read_temperature())
|
||||
if(temperature1==0):
|
||||
return 0
|
||||
else:
|
||||
return temperature1
|
||||
|
||||
# getTemp2() method
|
||||
# Sensor2 = DS18B20
|
||||
# Output= Temp2
|
||||
|
||||
def getTemp2():
|
||||
while 1:
|
||||
if sensor2:
|
||||
tempfile=open(sensor2)
|
||||
thetext=tempfile.read()
|
||||
tempfile.close()
|
||||
tempdata=thetext.split("\n")[1].split(" ")[9]
|
||||
temperature2=float(tempdata[2:])
|
||||
temperature2=temperature2/1000
|
||||
temperature2=round(temperature2, 1)
|
||||
else:
|
||||
temperature2=0
|
||||
if(temperature2==0):
|
||||
return 0
|
||||
else:
|
||||
return temperature2
|
||||
|
||||
# getTemp3() method
|
||||
# Sensor3 = DS18B20
|
||||
# Output= Temp3
|
||||
|
||||
def getTemp3():
|
||||
while 1:
|
||||
if sensor3:
|
||||
tempfile=open(sensor3)
|
||||
thetext=tempfile.read()
|
||||
tempfile.close()
|
||||
tempdata=thetext.split("\n")[1].split(" ")[9]
|
||||
temperature3=float(tempdata[2:])
|
||||
temperature3=temperature3/1000
|
||||
temperature3=round(temperature3, 1)
|
||||
else:
|
||||
temperature3=0
|
||||
if(temperature3==0):
|
||||
return 0
|
||||
else:
|
||||
return temperature3
|
||||
|
||||
# getTemp4() method
|
||||
# Sensor4 = DS18B20
|
||||
# Output = Temp4
|
||||
|
||||
def getTemp4():
|
||||
while 1:
|
||||
if sensor4:
|
||||
tempfile=open(sensor4)
|
||||
thetext=tempfile.read()
|
||||
tempfile.close()
|
||||
tempdata=thetext.split("\n")[1].split(" ")[9]
|
||||
temperature4=float(tempdata[2:])
|
||||
temperature4=temperature4/1000
|
||||
temperature4=round(temperature4, 1)
|
||||
else:
|
||||
temperature4=0
|
||||
if(temperature4==0):
|
||||
return 0
|
||||
else:
|
||||
return temperature4
|
||||
|
||||
# getPressure() method
|
||||
# Sensor1 = BMP085
|
||||
# Output = Pressure
|
||||
|
||||
def getPressure():
|
||||
pressure=format(sensor1.read_pressure()/100)
|
||||
pressure = round((sensor1.read_pressure()/100))
|
||||
if(pressure==0):
|
||||
return 0
|
||||
else:
|
||||
return pressure
|
||||
|
||||
# getSeaPressure() method
|
||||
# Sensor1 = BMP085
|
||||
def getSeaPressure():
|
||||
#sea_pressure = format(sensor1.read_sealevel_pressure()/100)
|
||||
#sea_pressure = round((sensor1.read_sealevel_pressure()/100))
|
||||
pressure = round((sensor1.read_pressure()/100))
|
||||
sea_pressure = round(pressure / pow(1.0 - locale_altitude/44330.0, 5.255))
|
||||
if(sea_pressure==0):
|
||||
return 0
|
||||
else:
|
||||
return sea_pressure
|
||||
|
||||
# getAltitude() method
|
||||
# Sensor1 = BMP085
|
||||
# Output = Altitude
|
||||
|
||||
def getAltitude():
|
||||
#altitude = format(sensor1.read_altitude())
|
||||
altitude = round((sensor1.read_altitude(SeaPresFlot)))
|
||||
if(altitude==0):
|
||||
return 0
|
||||
else:
|
||||
return altitude
|
||||
|
||||
# getHumidity() method
|
||||
# Sensor1 = BMP085
|
||||
# Output = Humidity
|
||||
|
||||
def getHumidity():
|
||||
humidity= 57
|
||||
|
||||
if(humidity==0):
|
||||
return 0
|
||||
else:
|
||||
return humidity
|
||||
|
||||
Temp1=getTemp1()
|
||||
print Temp1
|
||||
|
||||
Temp2=getTemp2()
|
||||
print Temp2
|
||||
|
||||
Temp3=getTemp3()
|
||||
print Temp3
|
||||
|
||||
Temp4=getTemp4()
|
||||
print Temp4
|
||||
|
||||
Pressure=getPressure()
|
||||
print Pressure
|
||||
|
||||
Sea_pressure=getSeaPressure()
|
||||
print Sea_pressure
|
||||
|
||||
Altitude =getAltitude()
|
||||
print Altitude
|
||||
|
||||
Humidity=getHumidity()
|
||||
print Humidity
|
||||
|
||||
print 'Temp = {0:0.2f} *C'.format(sensor.read_temperature())
|
||||
print 'Press = {0:0.2f} hPa'.format(sensor.read_pressure()/100)
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user