Looking back at motion detection...
Question: can R'Pints' Motion Detection thing truly be disabled if I wanted that mission to exist outside of R'Pints?
I ask because my current keezer will wake up the display, turn on an LED indicator and play a chosen song - and eventually I was going to use it to trigger a remote light control for my brew space where the keezer lives. All that was easy to do with my original method but I'm not sure I could hook all that functionality to what's inside R'Pints now
Anyway...
This is from /var/www/html/rpints/python/FlowMonitor.py, and I am wondering it there is a conflict here wrt GPIO 07 and 08 assignments. Even after moving my PIR over to GPIO 09 successfully I noticed that GPIO 08 is still doing something and I'm assuming GPIO 07 is also and was all along.
#Following is based on code from day_trippr (coverted to thread and allow configurable pin)
class MotionDetectionPIRThread (threading.Thread):
def __init__(self, threadID, pirPin = 7):
threading.Thread.__init__(self)
self.threadID = threadID
self.pirPin = pirPin
self.shutdown_required = False
def exit(self):
self.shutdown_required = True
def MOTION(self, PIR_PIN):
debug("Motion Detector " + self.threadID + " Detected Motion")
#Wake up every users monitor, need to loop through the users otherwise the command wont know who is currently logged in
#To see full command replace ;'s with new lines
os.system('export DISPLAY=":0.0"; for dir in /home/*/; do export XAUTHORITY=$dir.Xauthority; xscreensaver-command -deactivate > /dev/null 2>&1; done;')
time.sleep(1)
def run(self):
log("Motion Detector " + self.threadID + " is Running")
try:
GPIO.setup(self.pirPin, GPIO.IN)
GPIO.add_event_detect(self.pirPin, GPIO.RISING, callback=self.MOTION)
while not self.shutdown_required:
time.sleep(100)
except:
log("Unable to run Motion Detection")
debug(traceback.format_exc())
return
class LoadCellCheckThread (threading.Thread):
def __init__(self, threadID, dispatch, updateDir, tapId = 1, commandPin = 7, responsePin = 8, delay=1,
updateVariance=.01, unit="lb", logger=None, scaleRatio=1, tareOffset=0):
threading.Thread.__init__(self)
self.threadID = threadID
self.dispatch = dispatch
self.updateDir = updateDir
self.tapId = tapId
self.commandPin = commandPin
self.responsePin = responsePin
self.delay = delay
self.updateVariance = updateVariance
self.unit = unit
self.checkTare = False
self.shutdown_required = False
self.hx711 = HX711(name=threadID, dout_pin=responsePin, pd_sck_pin=commandPin, logger=logger,scale_ratio=scaleRatio,tare_offset=tareOffset)
def exit(self):
self.shutdown_required = True
def setCheckTare(self, checkTare):
self.checkTare = checkTare
def tare(self):
self.hx711.zero()
self.dispatch.setLoadCellTareOffset(self.hx711.get_offset())
return
def getWeight(self):
return self.hx711.get_weight_mean(20)
def run(self):
log("Load Cell Checker " + self.threadID + " is Running")
lastWeight = -1
try:
while not self.shutdown_required:
if self.checkTare:
if self.dispatch.getTareRequest(self.tapId):
self.tare()
self.dispatch.setTareRequest(self.tapId, False)
self.setCheckTare(False)
weight = self.getWeight()
#if weight is valid and the difference between the last read is significant enough to update
if weight > 0 and abs(lastWeight - weight) > self.updateVariance :
#The following 2 lines passes the PIN and WEIGHT to the php script
subprocess.call(["php", self.updateDir + '/admin/updateKeg.php', str(self.tapId), str(weight), self.unit])
lastWeight = weight
time.sleep(self.delay)
except Exception as ex:
log("Unable to run Load Cell Checker")
debug(str(ex))
debug(traceback.format_exc())
return
Cheers!