-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweather.py
executable file
·186 lines (154 loc) · 4.71 KB
/
weather.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/python
# Can enable debug output by uncommenting:
#import logging
#logging.basicConfig(level=logging.DEBUG)
import Adafruit_BMP.BMP085 as BMP085
# Default constructor will pick a default I2C bus.
#
# For the Raspberry Pi this means you should hook up to the only exposed I2C bus
# from the main GPIO header and the library will figure out the bus number based
# on the Pi's revision.
#
# 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
# Optionally you can override the bus number:
#sensor = BMP085.BMP085(busnum=2)
# You can also optionally change the BMP085 mode to one of BMP085_ULTRALOWPOWER,
# 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)
# 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