Skip to content

Commit

Permalink
New way of reading out MH_Z19 sensor. #247
Browse files Browse the repository at this point in the history
  • Loading branch information
theyosh committed Feb 24, 2019
1 parent 3f5cf78 commit d7eac3b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ if [ -f /etc/modules ]; then
fi
fi


# Make sure pigpiod is started at boot, and that user PI can restart it with sudo command
echo "${SCRIPT_USER} ALL=(ALL) NOPASSWD: /usr/sbin/service pigpiod restart" > /etc/sudoers.d/terrariumpi
# https://github.com/UedaTakeyuki/mh-z19/blob/master/pypi/mh_z19/__init__.py#L18
Expand Down
5 changes: 5 additions & 0 deletions terrariumNotification.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@ def stop(self):
if self.telegram is not None:
self.telegram.stop()

for messagetype in self.__notification_leds:
if self.__notification_leds[messagetype]['pin'] is not None:
GPIO.cleanup(self.__notification_leds[messagetype]['pin'])
self.__notification_leds[messagetype]['pin'] = None

def set_profile_image(self,imagefile):
self.__profile_image = imagefile
if self.__profile_image is None:
Expand Down
9 changes: 6 additions & 3 deletions terrariumSensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import os.path
import re
import mh_z19
import subprocess
import json
from glob import iglob
from time import time
from pyownet import protocol
Expand Down Expand Up @@ -350,7 +351,6 @@ def scan_sensors(callback = None):
os.path.basename(address),
callback_indicator = callback)


class terrariumOWFSSensor(terrariumSensorSource):
TYPE = 'owfs'
VALID_SENSOR_TYPES = ['temperature','humidity']
Expand Down Expand Up @@ -425,7 +425,10 @@ def set_address(self,address):
def load_data(self):
data = None
if self.get_address() is not None:
data = mh_z19.read()
try:
data = json.loads(subprocess.check_output(['sudo', 'python', '-m', 'mh_z19']).decode('utf-8').replace("'",'"'))
except Exception as ex:
print(ex)

if data is None:
return None
Expand Down

0 comments on commit d7eac3b

Please sign in to comment.