def intent_router(event, context): intent = event['request']['intent']['name'] logging.info('Alexa intent: ' + intent) if intent == "ConnectionStatusIntent": if telemetry_data is None or telemetry_data["ISONLINE"] is False: return alexa_response_builder.statement("Drone pilot is offline.") else: return alexa_response_builder.statement("Drone pilot is online.") if telemetry_data is None or telemetry_data["ISONLINE"] is False: logging.info('Drone pilot offline...') return alexa_response_builder.statement("Drone pilot is offline. Cannot complete your request.") # Custom Intents if intent == "StatusIntent": if 'value' in event['request']['intent']['slots']['status']: value = event['request']['intent']['slots']['status']['value'] return handle_status_intent(value) else: return alexa_response_builder.continue_dialog() if intent == "TakeoffIntent": return respond_intent("Drone taking off", "drone/takeoff", None) if intent == "LandIntent": return respond_intent("Drone landing", "drone/land", None) if intent == "DirectionIntent": if 'value' in event['request']['intent']['slots']['direction']: value = event['request']['intent']['slots']['direction']['value'] return respond_intent("Drone going " + value, "drone/direction", value) else: return alexa_response_builder.continue_dialog() if intent == "FlipIntent": return respond_intent("Flip", "drone/flip", None) if intent == "RotateIntent": if 'value' in event['request']['intent']['slots']['direction']: value = event['request']['intent']['slots']['direction']['value'] return respond_intent("Drone rotating " + value, "drone/rotate", value) else: return alexa_response_builder.continue_dialog() # Required Intents if intent == "AMAZON.CancelIntent": return cancel_intent() if intent == "AMAZON.HelpIntent": return help_intent() if intent == "AMAZON.StopIntent": return stop_intent() if intent == "AMAZON.FallbackIntent": return fallback_intent()
def respond_intent(command, topic, value): if telemetry_data["BAT"] < 15: logging.info('Drone pilot battery low...') return alexa_response_builder.statement("Drone battery low. Cannot complete your request.") message = {'value': value} payload = json.dumps(message) awsclient.publish_message(topic, payload) return alexa_response_builder.statement(command)
def intent_router(event, context): intent = event['request']['intent']['name'] logging.info('Alexa intent: ' + intent) # Custom Intents if intent == "temperatureIntent": value = event['request']['intent'] return handle_temperature_intent(value) if intent == "turnoffIntent": logger.info("turn off light") return respond_intent("Turning off light", thing_name + "/turnoff", None) if intent == "turnonIntent": logger.info("turn on light") if 'value' in event['request']['intent']['slots']['color']: value = event['request']['intent']['slots']['color']['value'] if value == 'red': logger.info("turn on red light") return respond_intent("Turning on " + str(value) + " light", thing_name + "/turnonred", value) if value == 'blue': logger.info("turn on blue light") return respond_intent("Turning on " + str(value) + " light", thing_name + "/turnonblue", value) if value == 'green': logger.info("turn on green light") return respond_intent("Turning on " + str(value) + " light", thing_name + "/turnongreen", value) else: return alexa_response_builder.statement("Color not supplied!") else: return alexa_response_builder.statement("Color not supplied!") # Required Intents if intent == "AMAZON.CancelIntent": return cancel_intent() if intent == "AMAZON.HelpIntent": return help_intent() if intent == "AMAZON.StopIntent": return stop_intent() if intent == "AMAZON.FallbackIntent": return fallback_intent()
def handle_status_intent(value): if value.lower() == "battery": televalue = telemetry_data["BAT"] text = str(televalue) + " percent battery left!" return alexa_response_builder.statement(text) elif value.lower() == "wi-fi" or value.lower() == "wifi" or value.lower() == "wireless": televalue = telemetry_data["WIFI"] if televalue > 70: text = "WIFI signal is strong" elif 40 < televalue < 70: text = "WIFI signal is medium" else: text = "WIFI signal is weak" return alexa_response_builder.statement(text) elif value.lower() == "camera": televalue = telemetry_data["CAM"] if televalue == 1: text = "Camera is ON" else: text = "Camera is OFF" return alexa_response_builder.statement(text) else: return alexa_response_builder.statement("Not sure about the status of " + value)
def on_processing_error(event, context, exc): logging.error(exc) return alexa_response_builder.statement( "An error occured while processing your request.")
def on_launch(event, context): logger.info("launch called") return alexa_response_builder.statement( "To start, you should say: Alexa, ask my smarthome to turn on red light." )
def respond_intent(command, topic, value): message = {'value': value} payload = json.dumps(message) awsclient.publish_message(topic, payload) return alexa_response_builder.statement(command)
def handle_temperature_intent(value): televalue = telemetry_data["temperature"] text = "Room temperature is " + str(televalue) + " degrees" return alexa_response_builder.statement(text)
def on_launch(event, context): return alexa_response_builder.statement("To start, you should say: Alexa, ask drone pilot to take off.")