Esempio n. 1
0
    def execute(self):
        log.info("Starting up AlarmPi")

        log.debug("Loading settings")
        settings = Settings.Settings()
        settings.setup()

        log.debug("Loading weather")
        weather = WeatherFetcher()

        log.debug("Loading media")
        media = MediaPlayer.MediaPlayer()
        media.playVoice('Starting up')

        log.debug("Loading clock")
        clock = ClockThread.ClockThread()
        clock.setDaemon(True)

        log.debug("Loading alarm control")
        alarm = AlarmThread.AlarmThread(weather)
        alarm.setDaemon(True)

        log.debug("Loading LCD")
        lcd = LcdThread.LcdThread(alarm, self.stop, weather)
        lcd.setDaemon(True)
        lcd.start()

        log.debug("Loading brightness control")
        bright = BrightnessThread.BrightnessThread()
        bright.setDaemon(True)
        bright.registerControlObject(clock.segment.disp)
        bright.registerControlObject(lcd)
        bright.start()

        # If there's a manual alarm time set in the database, then load it
        manual = settings.getInt('manual_alarm')
        if manual == 0 or manual is None:
            alarm.autoSetAlarm()
        else:
            alarmTime = datetime.datetime.utcfromtimestamp(manual)
            log.info("Loaded previously set manual alarm time of %s",
                     alarmTime)
            alarm.manualSetAlarm(alarmTime)

        log.debug("Starting clock")
        clock.start()

        log.debug("Starting alarm control")
        alarm.start()

        log.debug("Starting web application")
        web = WebApplication(alarm)
        web.setDaemon(True)
        web.start()

        # Main loop where we just spin until we receive a shutdown request
        try:
            while (self.stopping is False):
                time.sleep(1)
        except (KeyboardInterrupt, SystemExit):
            log.warn("Interrupted, shutting down")

        log.warn("Shutting down")
        media.playVoice('Shutting down. Goodbye')
        time.sleep(2)

        log.info("Stopping all services")
        web.stop()
        alarm.stop()
        clock.stop()
        lcd.stop()
        bright.stop()

        log.info("Shutdown complete, now exiting")

        time.sleep(2)  # To give threads time to shut down
Esempio n. 2
0
   def execute(self):
      #~ global lancheck
      global iplist
      log.info("Starting up PiClock")
      #log.info("cwd=%s", os.getcwd())

      iplist = []
      NetworksIP = self.GetIPForNetwork("eth0")
      if (NetworksIP != ""):
        log.debug("Have LAN Connection %s" , NetworksIP)
        iplist.append(NetworksIP)

      self.GetIPForNetwork("wlan0")
      if (NetworksIP != ""):
        log.debug("Have Wifi Connection %s" , NetworksIP)
        iplist.append(NetworksIP)
        # have lan and wifi
        #~ if (nolancheck == False):
            #~ log.info("add '--nolancheck' to the command line to run with two networks connected")
            #~ sys.exit()

      log.info("Loading settings")
      self.settings = Settings.Settings()
      self.settings.setup()

      # Set Log level from settings
      log.setLevel(self.settings.getInt('DEBUGLEVEL'))

      log.info("Starting mqtt application")
      self.mqttbroker = mqtt.MQTTThread(self.settings)
      self.mqttbroker.setDaemon(True)
      self.mqttbroker.start()
      self.settings.setmqttbroker(self.mqttbroker)

      log.info("Loading brightness control")
      self.bright = brightnessthread.BrightnessThread(self.settings, self.mqttbroker)
      self.bright.setDaemon(True)
      # bright.registerControlObject(clock.segment.disp)
      # bright.registerControlObject(self.lcd)
      self.bright.start()

      log.info("Loading TFT") # its started later
      self.lcd = tftthread.TFTThread(self, self.settings)
      self.lcd.setDaemon(True)

      log.info("Loading weather")
      weather = WeatherFetcher()

      log.info("Loading media")
      self.media = MediaPlayer.MediaPlayer(self.mqttbroker, self.settings)
      self.media.setDaemon(True)
      self.media.start()

      log.info("Loading alarm control")
      self.alarm = AlarmThread.AlarmThread(weather, self.media, self.settings, self.mqttbroker)
      self.alarm.setDaemon(True)

      log.info("Starting TFT")
      #self.lcd = tftthread.TFTThread(alarm, self,  self.media, weather)
      # tel lcd thread what we didnt know when we loaded it
      self.lcd.SetConfig(self.alarm, self.media, weather, self.bright, self.mqttbroker)
      #self.lcd.setDaemon(True)
      # and start lcdthread
      self.lcd.start()
      
      # new trial of webserver class
      #self.webserver = WebServer.WebServer(self.mqttbroker, self.alarm, self.media, self.bright, self.lcd, self.settings)
      # which failed

      # Tell mqtt broker about things setup after it was
      #self.mqttbroker.set_radio(self.media)  
      #self.mqttbroker.set_alarm(self.alarm)  
      #self.mqttbroker.set_display(self.lcd) 

      self.Menus = self.lcd.menu

      #~ this is done in the tftthread where its required

      log.info("Starting alarm control")
      self.alarm.start()

      # Start webserver thread
      #self.webserver.setDaemon(True)
      #self.webserver.start() # fails

      log.info("Starting HTTP web application")
      webhttp = WebApplicationHTTP(self.alarm, self.settings, self.media, self, self.bright, self.lcd, self.mqttbroker)
      webhttp.setDaemon(True)
      webhttp.start()

      log.info("Starting HTTPS web application")
      web = WebApplication(self.alarm, self.settings, self.media, self, self.bright, self.mqttbroker)
      web.setDaemon(True)
      web.start()

      loopcount = 0
      self.clockMessage(self.alarm.getMenuLine())

      # Main loop where we just spin until we receive a shutdown request
      try:
         lastpos = (-1,-1)
         dragstart = -1
         newvolume = -1
         oldvolume = -1
         log.info("Running")

         # If we crash or have power loss restart quietly
         self.settings.set("quiet_reboot","1")
         lastclocktemp = 0

         while(self.stopping == False):
            time.sleep(5) #0.1)
            clocktemp = int(open('/sys/class/thermal/thermal_zone0/temp').read()) / 1e3
            if clocktemp != lastclocktemp:
                self.mqttbroker.publish("Temperature",str(clocktemp))
                lastclocktemp = clocktemp


      except (KeyboardInterrupt, SystemExit):
         log.warn("Interrupted, shutting down")

      self.pauseclock  (True)


      if self.rebootAction == 2: #self.shutdownnow == True:
        self.lcd.setMessage("Shutting Down",True)
        self.media.playSpeech('Shutting down.')
        log.warn("Shutting down")
      elif self.rebootAction == 1: #self.rebootnow == True:
        self.lcd.setMessage("Rebooting now",True)
        # Lets do it quietly
        #~ self.media.playSpeech('Rebooting now.')
        log.warn("Rebooting now")
      else:
        self.lcd.setMessage("Stopping now",True)
        self.media.playSpeech('Stopping now.')
        log.warn("Stopping now")

      #~ time.sleep(1)

      log.info("Stopping all services")
      #self.webserver.stop()
      web.stop()
      webhttp.stop()
      
      self.lcd.stop()
      self.bright.stop()
      self.media.stopPlayer()
      if self.Menus.isActive():
          self.Menus.exitMenu()

      log.info("Shutdown complete, now exiting")

      time.sleep(2) # To give threads time to shut down

      if self.rebootnow == True:
          subprocess.Popen("sudo /sbin/reboot now", stdout=subprocess.PIPE, shell=True)
      elif self.shutdownnow == True:
          subprocess.Popen("sudo /sbin/shutdown now", stdout=subprocess.PIPE, shell=True)
Esempio n. 3
0
   def execute(self):
      log.info("Starting up AlarmPi")

      log.debug("Loading settings")
      settings = Settings.Settings()
      settings.setup()

      log.debug("Loading weather")
      weather = WeatherFetcher()

      log.debug("Loading media")
      media = MediaPlayer.MediaPlayer()
      media.playVoice('Starting up')

      log.debug("Loading clock")
      clock = ClockThread.ClockThread()
      clock.setDaemon(True)

      log.debug("Loading alarm control")
      alarm = AlarmThread.AlarmThread(weather)
      alarm.setDaemon(True)

      log.debug("Loading LCD")
      lcd = LcdThread.LcdThread(alarm, self.stop, weather)
      lcd.setDaemon(True)
      lcd.start()

      log.debug("Loading brightness control")
      bright = BrightnessThread.BrightnessThread()
      bright.setDaemon(True)
      bright.registerControlObject(clock.segment.disp)
      bright.registerControlObject(lcd)
      bright.start()

      # If there's a manual alarm time set in the database, then load it
      manual = settings.getInt('manual_alarm')
      if manual==0 or manual is None:
         alarm.autoSetAlarm()
      else:
         alarmTime = datetime.datetime.utcfromtimestamp(manual)
         log.info("Loaded previously set manual alarm time of %s",alarmTime)
         alarm.manualSetAlarm(alarmTime)

      log.debug("Starting clock")
      clock.start()

      log.debug("Starting alarm control")
      alarm.start()

      log.debug("Starting web application")
      web = WebApplication(alarm)
      web.setDaemon(True)
      web.start()

      # Main loop where we just spin until we receive a shutdown request
      try:
         while(self.stopping is False):
            time.sleep(1)
      except (KeyboardInterrupt, SystemExit):
         log.warn("Interrupted, shutting down")

      log.warn("Shutting down")
      media.playVoice('Shutting down. Goodbye')
      time.sleep(2)

      log.info("Stopping all services")
      web.stop()
      alarm.stop()
      clock.stop()
      lcd.stop()
      bright.stop()

      log.info("Shutdown complete, now exiting")

      time.sleep(2) # To give threads time to shut down
Esempio n. 4
0
 def initWeb(self, settings, alarm):
     log.debug("Starting web application")
     web = WebApplication(alarm, settings)
     web.setDaemon(True)
     web.start()
     return web