diff --git a/CHANGELOG.md b/CHANGELOG.md index 54bfb96e4..ddf411b2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,16 @@ Changelog ========= -(unreleased) ------------- +3.4.0 (2018-02-25) +------------------ **New** ------ +- Add debug for testing. [TheYOSH] +- Add PH indicator. [#108](https://github.com/theyosh/TerrariumPI/issues/108). [TheYOSH] +- Add traduction and minor bug. [nke69] + + Add description for new changes [#87](https://github.com/theyosh/TerrariumPI/issues/87) and minor bug in traduction - Add watertank actions based on sensors or timer data. Enable automatic switchig on water pumps. [#87](https://github.com/theyosh/TerrariumPI/issues/87). [TheYOSH] - Add water tank sensor photos. [TheYOSH] @@ -27,6 +32,11 @@ Changelog **Fixes** ------ +- Fixed gpiozero library installation. [TheYOSH] +- Fix array selecting. [TheYOSH] +- Another fix for PH devices [#108](https://github.com/theyosh/TerrariumPI/issues/108). [TheYOSH] +- Fix missing GPIO to BCM conversion. [#108](https://github.com/theyosh/TerrariumPI/issues/108). [TheYOSH] +- Fix on/off detection with zeor power switches. [TheYOSH] - Fix dashboard js bug. [TheYOSH] - Finetune distance sensor code and fix OWFS sensor scanning. [TheYOSH] - Updates for measurements in centimetre or inches [#87](https://github.com/theyosh/TerrariumPI/issues/87). Various small @@ -46,6 +56,11 @@ Changelog **Updates** ------ +- Update defaults.cfg. [TheYOSH] +- Update README.md. [TheYOSH] +- Update README.md. [TheYOSH] +- Update README.md. [TheYOSH] +- Update changelog. [TheYOSH] - Update documentation and use liters for watertank dashboard. [TheYOSH] - Update UI icons. [TheYOSH] - Update changelog. [TheYOSH] @@ -62,6 +77,18 @@ Changelog **Other** ------ +- Merge branch 'feature/ph' of ssh://github.com/theyosh/TerrariumPI into + feature/ph. [TheYOSH] +- Cleaup debug code. [#108](https://github.com/theyosh/TerrariumPI/issues/108). [TheYOSH] +- We measure in smaller values. [#108](https://github.com/theyosh/TerrariumPI/issues/108). [TheYOSH] +- First attempt for supporting PH device. [#87](https://github.com/theyosh/TerrariumPI/issues/87). [TheYOSH] +- Better export date formatting. [TheYOSH] +- Merge pull request [#107](https://github.com/theyosh/TerrariumPI/issues/107) from nke69/master. [TheYOSH] + + Add traduction and minor bug +- Hide environment part status indicator when there are no switchtes + selected. [TheYOSH] +- Force sensor start time. [TheYOSH] - Found the magic number [#82](https://github.com/theyosh/TerrariumPI/issues/82). [TheYOSH] - Code cleanup. [TheYOSH] - Code Cleanup. [TheYOSH] @@ -1105,5 +1132,3 @@ Changelog - Living on the edge.... use latest beta of Leaflet. [TheYOSH] - Initial release. [TheYOSH] - Initial commit. [TheYOSH] - - diff --git a/README.md b/README.md index 1d1b26e68..b9efd8b34 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# TerrariumPI 3.3.0 +# TerrariumPI 3.4.0 Software for cheap home automation of your reptile terrarium or any other enclosed environment. With this software you are able to control for example a terrarium so that the temperature and humidity is of a constant value. Controlling the temperature can be done with heat lights, external heating or cooling system. As long as there is one temperature sensor available the software is able to keep a constant temperature. For humidity control there is support for a spraying system. The sprayer can be configured to spray for an X amount of seconds and there is a minumal period between two spray actions. Use at least one humitidy sensors to get a constant humidity value. @@ -39,6 +39,8 @@ And all this is controlled with a nice webinterface based on [Gentelella a Boots - Support for ultrasonic sound range sensors - Support for native Raspberry Pi cam out of the box - Support for USB and remote webcams +- Support for analog devices through a MCP3008 + - Support for PH probe SKU SEN0161 - Open door detection (sprayer will not spray when a door is open) - Total power and water usage for costs calculation - Lights control based on sun rise and sun set or timers @@ -111,18 +113,22 @@ This software requires a Raspberry Pi and some extra hardware in order to run an - Raspberry PI - Pi 2 - Pi 3 + - Zero - Power relay board - USB versions (Serial and Bitbang) - GPIO versions - PWM Dimmer versions -- Temperature/humdity/ultrasonic sensors DHT11, DHT22, AM2303, DS1820, HIH4000, HC-SR04 etc through +- Temperature/humdity/ultrasonic/PH sensors DHT11, DHT22, AM2303, DS1820, HIH4000, HC-SR04, SEN0161, etc through - OWFS - GPIO - 1 Wire interface + - MCP3008 ([RasPiO Analog Zero](https://github.com/raspitv/analogzero)) ### GPIO numbering All hardware that connects to the GPIO pins use **Physical GPIO numbering** (1 - 40). The software will translate it to BCM if needed for a supported device or sensor. [More information about GPIO pin numbering](https://pinout.xyz/) +For the analog devices use numbers of the channel on the analog device which is from 0 to 7 (8 channels). Also the software expect the analog MCP3008 on GPIO ports 19,21,23,24 physical (default). [More information about GPIO pin numbering](https://pinout.xyz/) + ### New hardware If there is some other hardware which is not working with TerrariumPI, open an issue on [Github](https://github.com/theyosh/TerrariumPI/issues) and we will try to support it. Raspberry Pi Zero is not tested. diff --git a/defaults.cfg b/defaults.cfg index d9bdd2aee..19518b698 100644 --- a/defaults.cfg +++ b/defaults.cfg @@ -1,7 +1,7 @@ [terrariumpi] host = :: port = 8090 -version = 3.3.0 +version = 3.4.0 title = TerrariumPI %(version)s power_usage = 5 owfs_port = 4304 diff --git a/install.sh b/install.sh index bfd51d7b4..b2825d170 100755 --- a/install.sh +++ b/install.sh @@ -36,7 +36,7 @@ apt-get -y autoremove # Install required packages to get the terrarium software running aptitude -y update aptitude -y safe-upgrade -aptitude -y install libftdi1 screen python-imaging python-dateutil python-ow python-rpi.gpio python-psutil git subversion watchdog build-essential python-dev python-picamera python-opencv python-pip python-pigpio python-requests i2c-tools owfs ow-shell sqlite3 vlc-nox python-mediainfodll libasound2-dev sispmctl +aptitude -y install libftdi1 screen python-imaging python-dateutil python-ow python-rpi.gpio python-psutil git subversion watchdog build-essential python-dev python-picamera python-opencv python-pip python-pigpio python-requests i2c-tools owfs ow-shell sqlite3 vlc-nox python-mediainfodll libasound2-dev sispmctl python-gpiozero # Basic config: #raspi-config diff --git a/terrariumDoor.py b/terrariumDoor.py index 58af016ad..f07bff1c3 100644 --- a/terrariumDoor.py +++ b/terrariumDoor.py @@ -5,6 +5,8 @@ import RPi.GPIO as GPIO import thread from hashlib import md5 +from terrariumUtils import terrariumUtils + from gevent import monkey, sleep monkey.patch_all() @@ -45,7 +47,7 @@ def __checker(self): logger.info('Start terrariumPI door checker for door \'%s\'' % self.get_name()) while True: if self.get_hardware_type() == 'gpio': - current_status = terrariumDoor.OPEN if GPIO.input(int(self.get_address())) else terrariumDoor.CLOSED + current_status = terrariumDoor.OPEN if GPIO.input(terrariumUtils.to_BCM_port_number(self.get_address())) else terrariumDoor.CLOSED logger.debug('Current door \'%s\' status: %s' % (self.get_name(),current_status)) if current_status != self.get_status(): @@ -79,7 +81,7 @@ def get_address(self): def set_address(self,address): self.address = address - GPIO.setup(int(address),GPIO.IN,pull_up_down=GPIO.PUD_UP) # activate input with PullUp + GPIO.setup(terrariumUtils.to_BCM_port_number(address),GPIO.IN,pull_up_down=GPIO.PUD_UP) # activate input with PullUp def get_name(self): return self.name diff --git a/terrariumEngine.py b/terrariumEngine.py index d355c4bd9..89466641a 100644 --- a/terrariumEngine.py +++ b/terrariumEngine.py @@ -3,6 +3,12 @@ logger = terrariumLogging.logging.getLogger(__name__) import RPi.GPIO as GPIO +#GPIO.setwarnings(False) +## set GPIO mode to BCM. This is needed to support analog devices through gpiozero +logger.debug('Setting terrariumPI GPIO Mode to %s' % (GPIO.BCM,)) +GPIO.setmode(GPIO.BCM) +logger.debug('Done setting terrariumPI GPIO Mode to %s' % (GPIO.BCM,)) + import thread import time import uptime @@ -29,16 +35,12 @@ class terrariumEngine(): LOOP_TIMEOUT = 30 def __init__(self): - ## set GPIO mode to BOARD - ## this takes the pin number instead of GPIO mapping pin - logger.debug('Setting terrariumPI GPIO Mode to %s' % (GPIO.BOARD,)) - GPIO.setmode(GPIO.BOARD) - logger.debug('Done setting terrariumPI GPIO Mode to %s' % (GPIO.BOARD,)) # Default system units self.__units = {'temperature' : 'C', 'distance' : 'cm', - 'humidity' : '%'} + 'humidity' : '%', + 'ph' : 'Ph'} # List of queues for websocket communication self.subscribed_queues = [] diff --git a/terrariumSensor.py b/terrariumSensor.py index b5f9ef26c..14a6e6fb8 100644 --- a/terrariumSensor.py +++ b/terrariumSensor.py @@ -13,15 +13,16 @@ import RPi.GPIO as GPIO from hashlib import md5 +from gpiozero import MCP3008 from terrariumUtils import terrariumUtils class terrariumSensor: UPDATE_TIMEOUT = 30 - VALID_SENSOR_TYPES = ['temperature','humidity','distance'] + VALID_SENSOR_TYPES = ['temperature','humidity','distance','ph'] VALID_DHT_SENSORS = { 'dht11' : dht.DHT11, 'dht22' : dht.DHT22, 'am2302': dht.AM2302 } - VALID_HARDWARE_TYPES = ['owfs','w1','remote','hc-sr04'] + VALID_DHT_SENSORS.keys() + VALID_HARDWARE_TYPES = ['owfs','w1','remote','hc-sr04','sku-sen0161'] + VALID_DHT_SENSORS.keys() W1_BASE_PATH = '/sys/bus/w1/devices/' W1_TEMP_REGEX = re.compile(r'(?Pt|f)=(?P[0-9]+)',re.IGNORECASE) @@ -41,6 +42,9 @@ def __init__(self, id, hardware_type, sensor_type, sensor, name = '', callback_i elif 'hc-sr04' == self.get_hardware_type(): # Dirty hack to set sensor address self.set_address(sensor) + elif 'sku-sen0161' == self.get_hardware_type(): + # Dirty hack to set sensor address + self.set_address(sensor) elif 'remote' == self.get_hardware_type(): # Dirty hack to set sensor address self.set_address(sensor) @@ -150,15 +154,16 @@ def update(self, force = False): logger.warning('Remote sensor \'%s\' got error from remote source \'%s\': %s' % (self.get_name(),self.get_address(),data.status_code)) elif 'hc-sr04' == self.get_hardware_type(): - GPIO.output(int(self.sensor_address['TRIG']), False) + GPIO.output(terrariumUtils.to_BCM_port_number(self.sensor_address['TRIG']), False) time.sleep(2) - GPIO.output(int(self.sensor_address['TRIG']), True) + GPIO.output(terrariumUtils.to_BCM_port_number(self.sensor_address['TRIG']), True) time.sleep(0.00001) - GPIO.output(int(self.sensor_address['TRIG']), False) + GPIO.output(terrariumUtils.to_BCM_port_number(self.sensor_address['TRIG']), False) pulse_start = time.time() - while GPIO.input(int(self.sensor_address['ECHO']))==0: + while GPIO.input(terrariumUtils.to_BCM_port_number(self.sensor_address['ECHO']))==0: pulse_start = time.time() - while GPIO.input(int(self.sensor_address['ECHO']))==1: + pulse_end = time.time() + while GPIO.input(terrariumUtils.to_BCM_port_number(self.sensor_address['ECHO']))==1: pulse_end = time.time() pulse_duration = pulse_end - pulse_start @@ -166,6 +171,21 @@ def update(self, force = False): # Measure in centimetre current = round(pulse_duration * 17150,2) + elif 'sku-sen0161' == self.get_hardware_type(): + # Do multiple measurements... + values = [] + for counter in range(5): + analog_port = MCP3008(channel=int(self.get_address())) + # https://github.com/theyosh/TerrariumPI/issues/108 + # We measure the values in volts already, so no deviding by 1000 as original script does + values.append((analog_port.value * ( 5000.0 / 1024.0)) * 3.3 + 0.1614) + time.sleep(0.2) + + # sort values from low to high + values.sort() + # Calculate average. Exclude the min and max value. And therefore devide by 3 + current = round((sum(values[1:-1]) / 3.0),2) + elif 'temperature' == self.get_type(): if self.get_hardware_type() == 'owfs': current = float(self.sensor.temperature) @@ -282,10 +302,10 @@ def set_address(self,address): if 'hc-sr04' == self.get_hardware_type() and ',' in address: sensor = address.split(',') - self.sensor_address = {'TRIG' : int(sensor[0]) , 'ECHO' : int(sensor[1])} + self.sensor_address = {'TRIG' : sensor[0] , 'ECHO' : sensor[1]} try: - GPIO.setup(self.sensor_address['TRIG'],GPIO.OUT) - GPIO.setup(self.sensor_address['ECHO'],GPIO.IN) + GPIO.setup(terrariumUtils.to_BCM_port_number(self.sensor_address['TRIG']),GPIO.OUT) + GPIO.setup(terrariumUtils.to_BCM_port_number(self.sensor_address['ECHO']),GPIO.IN) except Exception, err: logger.warning(err) diff --git a/terrariumSwitch.py b/terrariumSwitch.py index ea9349ddc..dadcc5157 100644 --- a/terrariumSwitch.py +++ b/terrariumSwitch.py @@ -3,7 +3,6 @@ logger = terrariumLogging.logging.getLogger(__name__) import RPi.GPIO as GPIO -GPIO.setwarnings(False) import pigpio import thread import time @@ -110,7 +109,8 @@ def __load_eg_pm_usb_device(self): self.device = 0 def __load_gpio_device(self): - GPIO.setmode(GPIO.BOARD) + pass +# GPIO.setmode(GPIO.BOARD) def __load_pwm_device(self): self.__dimmer_running = False @@ -245,10 +245,10 @@ def set_state(self, state, force = False): logger.error('Could not login to the Energenie LAN device %s at location %s. Error status %s(%s)' % (self.get_name(),self.sensor_address,webstatus['logintxt'],webstatus['login'])) elif self.get_hardware_type() == 'gpio': - GPIO.output(int(self.get_address()), ( GPIO.HIGH if state is terrariumSwitch.ON else GPIO.LOW )) + GPIO.output(terrariumUtils.to_BCM_port_number(self.get_address()), ( GPIO.HIGH if state is terrariumSwitch.ON else GPIO.LOW )) elif self.get_hardware_type() == 'gpio-inverse': - GPIO.output(int(self.get_address()), ( GPIO.LOW if state is terrariumSwitch.ON else GPIO.HIGH )) + GPIO.output(terrariumUtils.to_BCM_port_number(self.get_address()), ( GPIO.LOW if state is terrariumSwitch.ON else GPIO.HIGH )) elif self.get_hardware_type() == 'pwm-dimmer' and self.__pigpio is not False: duration = self.get_dimmer_duration() @@ -403,7 +403,7 @@ def set_address(self,address): elif 'gpio' in self.get_hardware_type(): try: - GPIO.setup(int(self.get_address()), GPIO.OUT) + GPIO.setup(terrariumUtils.to_BCM_port_number(self.get_address()), GPIO.OUT) except Exception, err: logger.warning(err) pass diff --git a/views/inc/menu.tpl b/views/inc/menu.tpl index 7fa459ecc..8723810e3 100644 --- a/views/inc/menu.tpl +++ b/views/inc/menu.tpl @@ -43,6 +43,9 @@
  • {{_('Distance')}}
  • +
  • + {{_('PH')}} +
  • {{_('Settings')}}
  • diff --git a/views/sensor_ph.tpl b/views/sensor_ph.tpl new file mode 100644 index 000000000..2551a579e --- /dev/null +++ b/views/sensor_ph.tpl @@ -0,0 +1,2 @@ +% setdefault('sensor_type', 'ph') +% include('inc/sensor_list.tpl') diff --git a/views/sensor_settings.tpl b/views/sensor_settings.tpl index 790cfc5ac..f32341690 100644 --- a/views/sensor_settings.tpl +++ b/views/sensor_settings.tpl @@ -74,6 +74,7 @@

    {{_('Temperature sensor')}} {{_('new')}}

    +