Skip to content

Commit

Permalink
Merge pull request #109 from theyosh/feature/ph
Browse files Browse the repository at this point in the history
Feature/ph
  • Loading branch information
theyosh authored Feb 25, 2018
2 parents 6ac2a82 + 663e2cb commit 2047ddf
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 31 deletions.
33 changes: 29 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -1105,5 +1132,3 @@ Changelog
- Living on the edge.... use latest beta of Leaflet. [TheYOSH]
- Initial release. [TheYOSH]
- Initial commit. [TheYOSH]


10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion defaults.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions terrariumDoor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions terrariumEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = []
Expand Down
40 changes: 30 additions & 10 deletions terrariumSensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'(?P<type>t|f)=(?P<value>[0-9]+)',re.IGNORECASE)
Expand All @@ -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)
Expand Down Expand Up @@ -150,22 +154,38 @@ 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
# https://www.modmypi.com/blog/hc-sr04-ultrasonic-range-sensor-on-the-raspberry-pi
# 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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions terrariumSwitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
logger = terrariumLogging.logging.getLogger(__name__)

import RPi.GPIO as GPIO
GPIO.setwarnings(False)
import pigpio
import thread
import time
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions views/inc/menu.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
<li>
<a href="sensor_distance.html">{{_('Distance')}}</a>
</li>
<li>
<a href="sensor_ph.html">{{_('PH')}}</a>
</li>
<li>
<a href="sensor_settings.html">{{_('Settings')}}</a>
</li>
Expand Down
2 changes: 2 additions & 0 deletions views/sensor_ph.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
% setdefault('sensor_type', 'ph')
% include('inc/sensor_list.tpl')
3 changes: 3 additions & 0 deletions views/sensor_settings.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<h2 class="temperature"><span aria-hidden="true" class="glyphicon glyphicon-fire"></span> {{_('Temperature sensor')}} <span class="title">{{_('new')}}</span></h2>
<h2 class="humidity" style="display:none"><span aria-hidden="true" class="glyphicon glyphicon-tint"></span> {{_('Humidity sensor')}} <span class="title">{{_('new')}}</span></h2>
<h2 class="distance" style="display:none"><span aria-hidden="true" class="glyphicon glyphicon-signal"></span> {{_('Distance sensor')}} <span class="title">{{_('new')}}</span></h2>
<h2 class="ph" style="display:none"><span aria-hidden="true" class="glyphicon glyphicon-scale"></span> {{_('PH sensor')}} <span class="title">{{_('new')}}</span></h2>
<ul class="nav navbar-right panel_toolbox">
<li>
<a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
Expand All @@ -97,6 +98,7 @@
<option value="w1">{{_('1Wire')}}</option>
<option value="remote">{{_('Remote')}}</option>
<option value="hc-sr04">{{_('HC-SR04')}}</option>
<option value="sku-sen0161">{{_('PH SKU-SEN0161')}}</option>
</select>
</div>
</div>
Expand All @@ -113,6 +115,7 @@
<option value="temperature">{{_('Temperature')}}</option>
<option value="humidity">{{_('Humidity')}}</option>
<option value="distance">{{_('Distance')}}</option>
<option value="ph">{{_('PH')}}</option>
</select>
</div>
</div>
Expand Down

0 comments on commit 2047ddf

Please sign in to comment.