Exemplo n.º 1
0
 def readVitals(self):
     try:
         humidity, temperature = Adafruit_DHT.read_retry(
             self.DHT_SENSOR, DHT_PIN)
         return humidity, temperature
     except Exception as ex:
         ApplicationLogger().addError(
             "Failed to initialize humidity sensor")
Exemplo n.º 2
0
 def _iterativeSnap(self, iterations=5):
     try:
         cam = PiCamera()
         for i in range(iterations):
             sleep(5)
             cam.capture('/home/pi/karna/snaps/snap%s.jpg' % i)
     except Exception as ex:
         ApplicationLogger().addError('failed to take snaps.')
Exemplo n.º 3
0
 def flicker(self):
     try:
         self._toggleLights(None)
         sleep(1)
         self._toggleLights(None)
     except Exception as ex:
         ApplicationLogger().addError(
             "Failed to control hue lights. Please check connectivity.")
Exemplo n.º 4
0
 def _initializeClient(self):
     try:
         sid = os.environ['TWILIO_SID']
         auth = os.environ['TWILIO_AUTH']
         return Client(sid, auth)
     except Exception as ex:
         print(ex)
         ApplicationLogger().addError("Failed to initialize twilio")
Exemplo n.º 5
0
 def initialize(self):
     try:
         self._component = Bridge(self._ipAddress)
         self._component.connect()
         return self
     except Exception as ex:
         ApplicationLogger().addError("Failed to initialize Hue bridge.")
         return None
Exemplo n.º 6
0
 def gatherLocationAction(self):
     try:
         os.system('python3 /home/pi/tile.py')
         os.system('js-beautify tileJson.txt > tileJson.js')
         SchedulerManager().removeEvent('location')
     except Exception as ex:
         SchedulerManager().removeEvent('location')
         ApplicationLogger().addError("failed to gather location")
Exemplo n.º 7
0
 def _record(self):
     try:
         cam = PiCamera()
         cam.start_recording('/home/pi/karna/records/record.h264')
         sleep(30)
         cam.stop_recording()
     except Exception as ex:
         print(ex)
         ApplicationLogger().addError("Failed to record video")
Exemplo n.º 8
0
    def cancelEvent(self, name, scheduler):
        if name not in self._events.keys():
            return

        try:
            event = self._events[name]
            scheduler.cancel(event)
        except Exception as ex:
            ApplicationLogger().addError("Failed to remove event")
Exemplo n.º 9
0
 def _initializeLocation(self):
     try:
         location = ephem.Observer()
         lat, lng = Utility.getHomeLocation()
         location.lat = lat
         location.lon = lng
         return location
     except Exception as ex:
         ApplicationLogger().addError("failed to fetch astral location")
         return None
Exemplo n.º 10
0
    def send(self, message):
        if self._client is None:
            return

        try:
            myNumber = os.getenv('myNum')
            fromNumber = os.getenv('fromNum')
            self._client.messages.create(to=myNumber,
                                         body=message,
                                         from_=fromNumber)
        except Exception as ex:
            print(ex)
            ApplicationLogger().addError("Failed to send text")
Exemplo n.º 11
0
    resp.message("The Robots are coming! Head for the hills!")

    return str(resp)


def initialize():
    PeripheralFactory().initialize()
    SpeechAdapter.checkForErrors("All sensors are functional.")
    threading.Thread(target=EventScheduler().initialize).start()


def run():
    threading.Thread(target=app.run).start()
    while True:
        _runEvents()


def _runEvents():
    eventManager = EventManager()
    eventManager.initialize()
    eventManager.run()


if __name__ == "__main__":
    try:
        initialize()
        run()
    except Exception as ex:
        print(ApplicationLogger().getErrors())
        print("Exception caught")
Exemplo n.º 12
0
 def _snap(self):
     try:
         cam = PiCamera()
         cam.capture('/home/pi/karna/snaps/tmp_img.jpg')
     except Exception as ex:
         ApplicationLogger().addError('taking snap failed.')