Skip to content

Commit

Permalink
Add some basic error checking to warn for faulty sensor and cables.
Browse files Browse the repository at this point in the history
  • Loading branch information
alaudet committed Nov 19, 2016
1 parent 164a0d6 commit a9d54ed
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions bin/rsump.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# MIT License -- http://www.linuxnorth.org/raspi-sump/license.html

import time

try:
import ConfigParser as configparser # Python2
except ImportError:
Expand Down
10 changes: 10 additions & 0 deletions raspisump/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,13 @@ def log_alerts(notification):
alert_log.write(notification),
alert_log.write("\n")
alert_log.close()


def log_errors(notification):
'''Log all errors'''
error_log = open("/home/pi/raspi-sump/logs/error_log", 'a')
error_log.write(time.strftime("%Y-%m-%d %H:%M:%S,")),
error_log.write(notification),
error_log.write("\n")
error_log.close()

9 changes: 7 additions & 2 deletions raspisump/reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ def water_reading():
unit = configs['unit']

value = sensor.Measurement(trig_pin, echo_pin, temperature, unit, round_to)
raw_distance = value.raw_distance(sample_wait=0.3)


try:
raw_distance = value.raw_distance(sample_wait=0.3)
except SystemError:
log.log_errors("**ERROR - Signal not received. Possible cable or sensor problem.")
exit(0)

if unit == 'imperial':
return value.depth_imperial(raw_distance, pit_depth)
if unit == 'metric':
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup
import os
version = '1.0.2'
version = '1.0.12b'

homedir = '/home/pi/raspi-sump/'

Expand Down

0 comments on commit a9d54ed

Please sign in to comment.