Beispiel #1
0
def main():
  global log, gpio, lirc, ping, db, gammu

  # Parse arguments, use file docstring as a parameter definition
  args = docopt.docopt(__doc__, version='0.1a')
  #print args

  # Create directory if it doesn't exist
  futil = FileUtil("/home/pi/.resq-pi")
  gammu = None

  # Create a logger
  if args["--verbose"]:
    log = Logger.get(verbose = True)
  else:
    log = Logger.get(futil.path + "/resq-pi.log", False)
  log.info("*** Start ResQ-Pi ***")

  # Be sure we have root privileges
  if os.geteuid() != 0:
    exit("You need to have root privileges. Exiting.")
    
  # Ctrl-C and SIGTERM handler
  signal.signal(signal.SIGINT, signal_handler)
  signal.signal(signal.SIGTERM, signal_handler)

  # Get access to the resq-pi database
  db = ResqStore(futil.path + "/resq-pi.db")
  if not db.exist():
    log.info("No database found. Will create one.")
    db.create_tables() # if not already created
    db.reset_tables()  # and initialize

  # Initalize GPIO, Lirc, GooglePing ...
  gpio = ResqGpio()
  gpio.led(0, False) # all LEDs off
  lirc = ResqLirc(log, gpio)
  ping = GooglePing(log, gpio)

  test = False
  if args["--alarm"]:
    test = True

  if args["--resetdb"]:
    log.info("Reset database")
    db.reset_tables()
  elif args["--resetpass"]:
    log.info("Reset password")
    db.reset_password()
  elif args["--credits"]:
    get_sms_credits()
  else:
    resqpi_endless_loop(test)
Beispiel #2
0
        try:
          c = self.__nextcode(self.log)
          signal.alarm(0) # no timeout
        except ResqException:
          signal.signal(signal.SIGALRM, signal.SIG_IGN)
          self.log.info("Pylirc: Nextcode timeout")
          self.enter_pressed = 0
          return 'timeout'

    return "no alarm - and no surprises" # no alarm

if __name__ == "__main__":
  from logger import Logger
  from gpio import ResqGpio

  gpio = ResqGpio()
  gpio.led(0, False) # all LEDs off
  log = Logger.get(verbose=True)
  lirc = ResqLirc(log, gpio)
  print "Press 3 times KEY_ENTER (timeout 20 sec)"
  print lirc.wait_alarm()
  time.sleep(2)
  gpio.led(0, False) # all LEDs off
  print "Press 3 times KEY_ENTER (timeout 20 sec)"
  print lirc.wait_alarm()
  time.sleep(2)
  gpio.led(0, False) # all LEDs off
  print "Press one time KEY_ENTER for at least 5 secs"
  print lirc.wait_alarm("long")
  lirc.cleanup()