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")
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.')
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.")
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")
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
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")
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")
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")
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
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")
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")
def _snap(self): try: cam = PiCamera() cam.capture('/home/pi/karna/snaps/tmp_img.jpg') except Exception as ex: ApplicationLogger().addError('taking snap failed.')