Skip to content

Commit

Permalink
Add support for MLX90614 sensor. #247
Browse files Browse the repository at this point in the history
  • Loading branch information
theyosh committed Feb 5, 2019
1 parent 4048fef commit fa9901c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
[submodule "hls-proxy"]
path = hls-proxy
url = https://github.com/Viblast/hls-proxy.git
[submodule "python-MLX90614"]
path = python-MLX90614
url = https://github.com/CRImier/python-MLX90614.git
1 change: 1 addition & 0 deletions python-MLX90614
Submodule python-MLX90614 added at 715b84
42 changes: 42 additions & 0 deletions terrariumI2CSensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# https://github.com/ageir/chirp-rpi
sys.path.insert(0, './chirp-rpi')
import chirp
sys.path.insert(0, './python-MLX90614')
from mlx90614 import MLX90614

from gevent import monkey, sleep
monkey.patch_all()
Expand Down Expand Up @@ -522,3 +524,43 @@ def get_data(self):
data['temp_offset'] = self.get_temperature_offset_calibration()

return data

class terrariumMLX90614Sensor(terrariumSensorSource):
TYPE = 'mlx90614'
VALID_SENSOR_TYPES = ['temperature']

def set_address(self,address):
super(terrariumMLX90614Sensor,self).set_address(address)
data = self.get_address().split(',')
self.i2c_address = int('0x' + data[0],16)
self.i2c_bus = 1
self.temp_type = 'object'
if len(data) == 3:
_, self.i2c_bus, self.temp_type = data
elif len(data) == 2:
if 'a' == data[1]:
self.temp_type = 'ambient'
elif 'o' == data[1]:
self.temp_type = 'object'
else:
self.i2c_bus = data[1]

def load_data(self):
data = None

try:
data = {}
sensor = MLX90614(self.i2c_address,int(self.i2c_bus))

# we cannot cache data here.... as both are 'temperature' values
if 'object' == self.temp_type:
data['temperature'] = float(sensor.get_obj_temp())
elif 'ambient' == self.temp_type:
data['temperature'] = float(sensor.get_amb_temp())
else:
data = None

except Exception as ex:
print(ex)

return data
5 changes: 3 additions & 2 deletions terrariumSensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def load_data(self):
from terrariumAnalogSensor import terrariumSKUSEN0161Sensor
from terrariumBluetoothSensor import terrariumMiFloraSensor
from terrariumGPIOSensor import terrariumYTXXSensorDigital, terrariumDHT11Sensor, terrariumDHT22Sensor, terrariumAM2302Sensor, terrariumHCSR04Sensor
from terrariumI2CSensor import terrariumSHT2XSensor, terrariumHTU21DSensor, terrariumSi7021Sensor, terrariumBME280Sensor, terrariumChirpSensor, terrariumVEML6075Sensor, terrariumSHT3XSensor
from terrariumI2CSensor import terrariumSHT2XSensor, terrariumHTU21DSensor, terrariumSi7021Sensor, terrariumBME280Sensor, terrariumChirpSensor, terrariumVEML6075Sensor, terrariumSHT3XSensor, terrariumMLX90614Sensor

# Not sure if this is needed here again....?
monkey.patch_all()
Expand Down Expand Up @@ -464,7 +464,8 @@ class terrariumSensor(object):
terrariumVEML6075Sensor,
terrariumChirpSensor,
terrariumSHT3XSensor,
terrariumMHZ19Sensor}
terrariumMHZ19Sensor,
terrariumMLX90614Sensor}

def __new__(self, sensor_id, hardware_type, sensor_type, address, name = '', callback_indicator = None):
for sensor in terrariumSensor.SENSORS:
Expand Down
1 change: 1 addition & 0 deletions views/sensor_settings.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<option value="veml6075">{{_('VEML6075')}}</option>
<option value="miflora">{{_('MiFlora')}}</option>
<option value="mh-z19">{{_('mh-z19')}}</option>
<option value="mlx90614">{{_('MLX90614')}}</option>
</select>
</div>
</div>
Expand Down

0 comments on commit fa9901c

Please sign in to comment.