Yet Another WebIOPi+
Main Page
Related Pages
Packages
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Macros
Pages
python
webiopi
devices
sensor
__init__.py
Go to the documentation of this file.
1
# Copyright 2012-2013 Eric Ptak - trouch.com
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
# http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14
15
from
webiopi.utils.types
import
toint
16
from
webiopi.utils.types
import
M_JSON
17
from
webiopi.devices.instance
import
deviceInstance
18
from
webiopi.decorators.rest
import
request, response
19
20
class
Pressure
():
21
def
__init__
(self, altitude=0, external=None):
22
self.
altitude
=
toint
(altitude)
23
if
isinstance(external, str):
24
self.
external
=
deviceInstance
(external)
25
else
:
26
self.
external
= external
27
28
if
self.
external
!=
None
and
not
isinstance(self.
external
, Temperature):
29
raise
Exception(
"external must be a Temperature sensor"
)
30
31
def
__family__
(self):
32
return
"Pressure"
33
34
def
__getPascal__
(self):
35
raise
NotImplementedError
36
37
def
__getPascalAtSea__
(self):
38
raise
NotImplementedError
39
40
@
request
(
"GET"
,
"sensor/pressure/pa"
)
41
@
response
(
"%d"
)
42
def
getPascal
(self):
43
return
self.
__getPascal__
()
44
45
@
request
(
"GET"
,
"sensor/pressure/hpa"
)
46
@
response
(
"%.2f"
)
47
def
getHectoPascal
(self):
48
return
float(self.
__getPascal__
()) / 100.0
49
50
@
request
(
"GET"
,
"sensor/pressure/sea/pa"
)
51
@
response
(
"%d"
)
52
def
getPascalAtSea
(self):
53
pressure = self.
__getPascal__
()
54
if
self.
external
!=
None
:
55
k = self.external.getKelvin()
56
if
k != 0:
57
return
float(pressure) / (1.0 / (1.0 + 0.0065 / k * self.
altitude
)**5.255)
58
return
float(pressure) / (1.0 - self.
altitude
/ 44330.0)**5.255
59
60
@
request
(
"GET"
,
"sensor/pressure/sea/hpa"
)
61
@
response
(
"%.2f"
)
62
def
getHectoPascalAtSea
(self):
63
return
self.
getPascalAtSea
() / 100.0
64
65
class
Temperature
():
66
def
__family__
(self):
67
return
"Temperature"
68
69
def
__getKelvin__
(self):
70
raise
NotImplementedError
71
72
def
__getCelsius__
(self):
73
raise
NotImplementedError
74
75
def
__getFahrenheit__
(self):
76
raise
NotImplementedError
77
78
def
Kelvin2Celsius
(self, value=None):
79
if
value ==
None
:
80
value = self.
getKelvin
()
81
return
value - 273.15
82
83
def
Kelvin2Fahrenheit
(self, value=None):
84
if
value ==
None
:
85
value = self.
getKelvin
()
86
return
value * 1.8 - 459.67
87
88
def
Celsius2Kelvin
(self, value=None):
89
if
value ==
None
:
90
value = self.
getCelsius
()
91
return
value + 273.15
92
93
def
Celsius2Fahrenheit
(self, value=None):
94
if
value ==
None
:
95
value = self.
getCelsius
()
96
return
value * 1.8 + 32
97
98
def
Fahrenheit2Kelvin
(self, value=None):
99
if
value ==
None
:
100
value = self.
getFahrenheit
()
101
return
(value - 459.67) / 1.8
102
103
def
Fahrenheit2Celsius
(self, value=None):
104
if
value ==
None
:
105
value = self.
getFahrenheit
()
106
return
(value - 32) / 1.8
107
108
@
request
(
"GET"
,
"sensor/temperature/k"
)
109
@
response
(
"%.02f"
)
110
def
getKelvin
(self):
111
return
self.
__getKelvin__
()
112
113
@
request
(
"GET"
,
"sensor/temperature/c"
)
114
@
response
(
"%.02f"
)
115
def
getCelsius
(self):
116
return
self.
__getCelsius__
()
117
118
@
request
(
"GET"
,
"sensor/temperature/f"
)
119
@
response
(
"%.02f"
)
120
def
getFahrenheit
(self):
121
return
self.
__getFahrenheit__
()
122
123
class
Luminosity
():
124
def
__family__
(self):
125
return
"Luminosity"
126
127
def
__getLux__
(self):
128
raise
NotImplementedError
129
130
@
request
(
"GET"
,
"sensor/luminosity/lux"
)
131
@
response
(
"%.02f"
)
132
def
getLux
(self):
133
return
self.
__getLux__
()
134
135
class
Distance
():
136
def
__family__
(self):
137
return
"Distance"
138
139
def
__getMillimeter__
(self):
140
raise
NotImplementedError
141
142
@
request
(
"GET"
,
"sensor/distance/mm"
)
143
@
response
(
"%.02f"
)
144
def
getMillimeter
(self):
145
return
self.
__getMillimeter__
()
146
147
@
request
(
"GET"
,
"sensor/distance/cm"
)
148
@
response
(
"%.02f"
)
149
def
getCentimeter
(self):
150
return
self.
getMillimeter
() / 10
151
152
@
request
(
"GET"
,
"sensor/distance/m"
)
153
@
response
(
"%.02f"
)
154
def
getMeter
(self):
155
return
self.
getMillimeter
() / 1000
156
157
@
request
(
"GET"
,
"sensor/distance/in"
)
158
@
response
(
"%.02f"
)
159
def
getInch
(self):
160
return
self.
getMillimeter
() / 0.254
161
162
@
request
(
"GET"
,
"sensor/distance/ft"
)
163
@
response
(
"%.02f"
)
164
def
getFoot
(self):
165
return
self.
getInch
() / 12
166
167
@
request
(
"GET"
,
"sensor/distance/yd"
)
168
@
response
(
"%.02f"
)
169
def
getYard
(self):
170
return
self.
getInch
() / 36
171
172
class
Humidity
():
173
def
__family__
(self):
174
return
"Humidity"
175
176
def
__getHumidity__
(self):
177
raise
NotImplementedError
178
179
@
request
(
"GET"
,
"sensor/humidity/float"
)
180
@
response
(
"%f"
)
181
def
getHumidity
(self):
182
return
self.
__getHumidity__
()
183
184
@
request
(
"GET"
,
"sensor/humidity/percent"
)
185
@
response
(
"%d"
)
186
def
getHumidityPercent
(self):
187
return
self.
__getHumidity__
() * 100
188
189
DRIVERS = {}
190
DRIVERS[
"bmp085"
] = [
"BMP085"
,
"BMP180"
]
191
DRIVERS[
"onewiretemp"
] = [
"DS1822"
,
"DS1825"
,
"DS18B20"
,
"DS18S20"
,
"DS28EA00"
]
192
DRIVERS[
"tmpXXX"
] = [
"TMP75"
,
"TMP102"
,
"TMP275"
]
193
DRIVERS[
"tslXXXX"
] = [
"TSL2561"
,
"TSL2561CS"
,
"TSL2561T"
,
"TSL4531"
,
"TSL45311"
,
"TSL45313"
,
"TSL45315"
,
"TSL45317"
]
194
DRIVERS[
"vcnl4000"
] = [
"VCNL4000"
]
195
DRIVERS[
"hytXXX"
] = [
"HYT221"
]
196
DRIVERS[
"bme280"
] = [
"BME280"
]
197
DRIVERS[
"mcptmp"
] = [
"MCP9808"
]
198
DRIVERS[
"htu21d"
] = [
"HTU21D"
]
199
200
201
202
203
webiopi.utils.types
Definition:
types.py:1
webiopi.devices.sensor.Pressure
Definition:
__init__.py:20
coap-client.response
tuple response
Definition:
coap-client.py:9
webiopi.devices.sensor.Temperature.getFahrenheit
def getFahrenheit
Definition:
__init__.py:120
webiopi.devices.sensor.Humidity.__family__
def __family__
Definition:
__init__.py:173
webiopi.devices.sensor.Humidity.getHumidityPercent
def getHumidityPercent
Definition:
__init__.py:186
webiopi.devices.sensor.Pressure.getHectoPascal
def getHectoPascal
Definition:
__init__.py:47
webiopi.devices.sensor.Pressure.__init__
def __init__
Definition:
__init__.py:21
webiopi.devices.sensor.Pressure.external
external
Definition:
__init__.py:24
webiopi.devices.sensor.Distance.getFoot
def getFoot
Definition:
__init__.py:164
webiopi.devices.sensor.Luminosity
Definition:
__init__.py:123
webiopi.devices.sensor.Pressure.getPascal
def getPascal
Definition:
__init__.py:42
webiopi.devices.sensor.Temperature
Definition:
__init__.py:65
webiopi.devices.sensor.Temperature.__getKelvin__
def __getKelvin__
Definition:
__init__.py:69
webiopi.devices.sensor.Humidity.getHumidity
def getHumidity
Definition:
__init__.py:181
webiopi.devices.sensor.Temperature.Fahrenheit2Kelvin
def Fahrenheit2Kelvin
Definition:
__init__.py:98
webiopi.devices.sensor.Humidity.__getHumidity__
def __getHumidity__
Definition:
__init__.py:176
webiopi.devices.instance
Definition:
instance.py:1
webiopi.devices.sensor.Pressure.getHectoPascalAtSea
def getHectoPascalAtSea
Definition:
__init__.py:62
webiopi.devices.sensor.Pressure.altitude
altitude
Definition:
__init__.py:22
webiopi.devices.sensor.Temperature.getKelvin
def getKelvin
Definition:
__init__.py:110
webiopi.devices.sensor.Humidity
Definition:
__init__.py:172
webiopi.devices.sensor.Distance.getInch
def getInch
Definition:
__init__.py:159
webiopi.devices.sensor.Temperature.Celsius2Kelvin
def Celsius2Kelvin
Definition:
__init__.py:88
webiopi.devices.sensor.Distance.getMillimeter
def getMillimeter
Definition:
__init__.py:144
webiopi.devices.sensor.Temperature.__getCelsius__
def __getCelsius__
Definition:
__init__.py:72
webiopi.decorators.rest
Definition:
rest.py:1
webiopi.devices.sensor.Temperature.getCelsius
def getCelsius
Definition:
__init__.py:115
webiopi.devices.sensor.Distance.__family__
def __family__
Definition:
__init__.py:136
webiopi.devices.sensor.Pressure.getPascalAtSea
def getPascalAtSea
Definition:
__init__.py:52
webiopi.devices.sensor.Distance.getCentimeter
def getCentimeter
Definition:
__init__.py:149
webiopi.devices.sensor.Temperature.Fahrenheit2Celsius
def Fahrenheit2Celsius
Definition:
__init__.py:103
webiopi.devices.instance.deviceInstance
def deviceInstance
Definition:
instance.py:2
webiopi.devices.sensor.Distance
Definition:
__init__.py:135
webiopi.devices.sensor.Luminosity.__getLux__
def __getLux__
Definition:
__init__.py:127
webiopi.decorators.rest.request
def request
Definition:
rest.py:1
webiopi.devices.sensor.Pressure.__getPascalAtSea__
def __getPascalAtSea__
Definition:
__init__.py:37
webiopi.devices.sensor.Temperature.Kelvin2Fahrenheit
def Kelvin2Fahrenheit
Definition:
__init__.py:83
webiopi.devices.sensor.Luminosity.__family__
def __family__
Definition:
__init__.py:124
webiopi.devices.sensor.Temperature.__family__
def __family__
Definition:
__init__.py:66
webiopi.devices.sensor.Temperature.__getFahrenheit__
def __getFahrenheit__
Definition:
__init__.py:75
webiopi.devices.sensor.Distance.getYard
def getYard
Definition:
__init__.py:169
webiopi.devices.sensor.Luminosity.getLux
def getLux
Definition:
__init__.py:132
webiopi.devices.sensor.Pressure.__getPascal__
def __getPascal__
Definition:
__init__.py:34
webiopi.devices.sensor.Temperature.Celsius2Fahrenheit
def Celsius2Fahrenheit
Definition:
__init__.py:93
webiopi.devices.sensor.Distance.__getMillimeter__
def __getMillimeter__
Definition:
__init__.py:139
webiopi.devices.sensor.Distance.getMeter
def getMeter
Definition:
__init__.py:154
webiopi.devices.sensor.Pressure.__family__
def __family__
Definition:
__init__.py:31
webiopi.utils.types.toint
def toint
Definition:
types.py:16
webiopi.devices.sensor.Temperature.Kelvin2Celsius
def Kelvin2Celsius
Definition:
__init__.py:78
Generated on Sat Sep 10 2016 09:36:46 for Yet Another WebIOPi+ by
1.8.8