self.config_parser.add_section('door')
self.config_parser.set('door','cmd_socket',"/var/run/tuer/door_cmd.socket")
self.config_parser.add_section('sensors')
- self.config_parser.set('sensors','remote_cmd',"ssh -i /flash/tuer/id_rsa -o PasswordAuthentication=no %RHOST% %RSHELL% %RSOCKET%")
+ self.config_parser.set('sensors','remote_cmd',"ssh -i /flash/tuer/id_rsa -o PasswordAuthentication=no -o StrictHostKeyChecking=no %RHOST% %RSHELL% %RSOCKET%")
self.config_parser.set('sensors','remote_host',"root@slug.realraum.at")
self.config_parser.set('sensors','remote_socket',"/var/run/powersensordaemon/cmd.sock")
self.config_parser.set('sensors','remote_shell',"usocket")
self.config_parser.add_section('tracker')
- self.config_parser.set('tracker','sec_wait_movement_after_door_closed',2.5)
+ self.config_parser.set('tracker','sec_wait_movement_after_door_closed',"15.0")
self.config_parser.set('tracker','sec_general_movement_timeout',3600)
self.config_parser.set('tracker','server_socket',"/var/run/tuer/presence.socket")
self.config_parser.set('tracker','photo_flashlight',950)
- self.config_parser.set('tracker','photo_daylight',500)
self.config_parser.set('tracker','photo_artif_light',150)
self.config_parser.add_section('debug')
self.config_parser.set('debug','enabled',"False")
self.checkConfigUpdates()
def guardReading(self):
- self.lock.acquire()
- while self.currently_writing:
- self.finished_writing.wait()
- self.currently_reading+=1
- self.lock.release()
+ with self.lock:
+ while self.currently_writing:
+ self.finished_writing.wait()
+ self.currently_reading+=1
def unguardReading(self):
with self.lock:
RE_ERROR = re.compile(r'Error: (.+)')
while True:
uwscfg.checkConfigUpdates()
+ sshp = None
try:
cmd = uwscfg.sensors_remote_cmd.replace("%RHOST%",uwscfg.sensors_remote_host).replace("%RSHELL%",uwscfg.sensors_remote_shell).replace("%RSOCKET%",uwscfg.sensors_remote_socket).split(" ")
logging.debug("trackSensorStatusThread: Executing: "+" ".join(cmd))
if not sshp.poll() is None:
raise Exception("trackSensorStatusThread: subprocess %d not started ?, returncode: %d" % (sshp.pid,sshp.returncode))
#sshp.stdin.write("listen movement\nlisten button\nlisten sensor\n")
- logging.debug("trackSensorStatusThread: send: listen all")
- sshp.stdin.write("listen all\n")
+ time.sleep(5) #if we send listen bevor usocket is running, we will never get output
+ #sshp.stdin.write("listen all\n")
+ logging.debug("trackSensorStatusThread: send: listen movement, etc")
sshp.stdin.write("listen movement\n")
sshp.stdin.write("listen button\n")
sshp.stdin.write("listen sensor\n")
+ #sshp.stdin.write("sample temp0\n")
+ sshp.stdin.flush()
while True:
if not sshp.poll() is None:
raise Exception("trackSensorStatusThread: subprocess %d finished, returncode: %d" % (sshp.pid,sshp.returncode))
line = sshp.stdout.readline()
- logging.debug("trackSensorStatusThread:Got Line: " + line)
if len(line) < 1:
raise Exception("EOF on Subprocess, daemon seems to have quit, returncode: %d",sshp.returncode)
+ logging.debug("trackSensorStatusThread: Got Line: " + line)
connection_listener.distributeData(line)
m = RE_MOVEMENT.match(line)
if not m is None:
except Exception, ex:
logging.error("trackSensorStatusThread: "+str(ex))
traceback.print_exc(file=sys.stdout)
- if sshp.poll() is None:
+ if not sshp is None and sshp.poll() is None:
if sys.hexversion >= 0x020600F0:
sshp.terminate()
else:
RE_ERROR = re.compile(r'Error: (.+)')
while True:
uwscfg.checkConfigUpdates()
+ conn=None
+ sockhandle=None
try:
if not os.path.exists(uwscfg.door_cmd_socket):
logging.debug("Socketfile '%s' not found, waiting 5 secs" % uwscfg.door_cmd_socket)
logging.error("main: "+str(ex))
traceback.print_exc(file=sys.stdout)
try:
- sockhandle.close()
+ if not sockhandle is None:
+ sockhandle.close()
except:
pass
conn=None
self.uwscfg=uwscfg
self.status_change_handler = None
#State locked by self.lock
+ self.door_open_previously=None
self.door_open=False
self.door_manual_switch_used=False
self.last_door_operation_unixts=0
self.uwscfg.checkConfigUpdates()
self.lock.acquire()
self.door_open=True
- self.door_manual_switch_used=(who is None or len(who) == 0)
- self.last_door_operation_unixts=time.time()
+ if not self.door_open_previously is None:
+ self.door_manual_switch_used=(who is None or len(who) == 0)
+ self.last_door_operation_unixts=time.time()
+ if self.door_open != self.door_open_previously:
+ self.lock.release()
+ self.checkPresenceStateChangeAndNotify()
+ self.lock.acquire()
+ self.door_open_previously = self.door_open
self.lock.release()
- self.checkPresenceStateChangeAndNotify()
-
+
def doorClosed(self,who):
self.uwscfg.checkConfigUpdates()
self.lock.acquire()
self.door_open=False
- self.door_manual_switch_used=(who is None or len(who) == 0)
- self.last_door_operation_unixts=time.time()
+ if not self.door_open_previously is None:
+ self.door_manual_switch_used=(who is None or len(who) == 0)
+ self.last_door_operation_unixts=time.time()
+ if self.door_open != self.door_open_previously:
+ self.lock.release()
+ self.checkPresenceStateChangeAndNotify()
+ self.lock.acquire()
+ self.door_open_previously = self.door_open
self.lock.release()
- self.checkPresenceStateChangeAndNotify()
def movementDetected(self):
self.uwscfg.checkConfigUpdates()
if somebody_present is None:
somebody_present=self.somebodyPresent()
- if self.last_light_value > self.uwscfg.tracker_photo_flashlight:
+ if self.last_light_value > int(self.uwscfg.tracker_photo_flashlight):
return "Light: flashlight"
- elif self.last_light_value > self.uwscfg.tracker_photo_daylight:
- return "Light: daylight"
- elif self.last_light_value > self.uwscfg.tracker_photo_artif_light:
+ elif self.last_light_value > int(self.uwscfg.tracker_photo_artif_light):
if not somebody_present and self.last_light_unixts > self.last_door_operation_unixts:
return "Light: forgotten"
else:
with self.lock:
if (self.door_open):
return True
- elif (time.time() - self.last_door_operation_unixts <= self.uwscfg.tracker_sec_wait_movement):
+ elif (time.time() - self.last_door_operation_unixts <= float(self.uwscfg.tracker_sec_wait_movement_after_door_closed)):
#start timer, checkPresenceStateChangeAndNotify after tracker_sec_wait_movement
if not self.timer is None:
self.timer.cancel()
- self.timer=threading.Timer(self.uwscfg.tracker_sec_wait_movement, self.checkPresenceStateChangeAndNotify)
+ self.timer=threading.Timer(float(self.uwscfg.tracker_sec_wait_movement_after_door_closed), self.checkPresenceStateChangeAndNotify)
self.timer.start()
return True
- elif (self.last_movement_unixts > self.last_door_operation_unixts and (self.door_manual_switch_used or ( time.time() - self.last_movement_unixts < self.uwscfg.tracker_sec_general_movement_timeout))):
+ elif (self.last_movement_unixts > self.last_door_operation_unixts and (self.door_manual_switch_used or ( time.time() - self.last_movement_unixts < float(self.uwscfg.tracker_sec_general_movement_timeout)))):
return True
else:
return False