我的代码全部是关于在Raspberry Pi 3和Alexa的帮助下控制直流电动机的。为此,我使用了ngrok和flask-ask作为端点。使用raspberrypi3控制直流电动机的代码已工作。
因此,我在Amazon开发人员站点中创建了一个Intent,并使用Alexa控制直流电动机。该代码被卡在“对Alexa的响应文本”上。我尝试了几种调试代码的方法。但是不能。
这是对Alexa的JSON输入请求。
"request": {
"type": "SessionEndedRequest",
"requestId": "amzn1.echo-api.request.9cf91a8c-c484-41fe-91a8-
9d6b8eb002a1",
"timestamp": "2019-02-07T10:42:06Z",
"locale": "en-IN",
"reason": "ERROR",
"error": {
"type": "INVALID_RESPONSE",
"message": "An exception occurred while dispatching the request to the skill."
}
}
使用Alexa和Raspberry Pi 3进行直流电机控制的Python文件:
from flask import Flask, render_template
from flask_ask import Ask, statement, question
import RPi.GPIO as GPIO #use GPIO library
from time import sleep
#initializing GPIO
GPIO.setwarnings(False)
Motor1A = 24
Motor1B = 23
Motor1E = 25
GPIO.setmode(GPIO.BCM) # GPIO Numbering
GPIO.setup(Motor1A,GPIO.OUT) # All pins as Outputs
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)
#initializing flask ask
app = Flask(__name__)
ask = Ask(app, '/')
@ask.launch
def launch():
welcome_text = render_template('welcome_text')
return question(welcome_text)
@ask.intent('AMAZON.FallbackIntent')
def fallback():
reprompt_text = render_template('command_reprompt')
return question(reprompt_text)
def loop():
# Going forwards
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
GPIO.output(Motor1E,GPIO.HIGH)
@ask.intent('DemoFan')
def control(OnOff):
command = OnOff
if command is None:
#no command was given
reprompt_text = render_template('command_reprompt')
return question(reprompt_text)
elif command == 'on':
loop()
print("working ")
# sleep(5)
**response_text = render_template('Fan_command',
OnCommand=command)
return statement(response_text).simple_card('Fan_command',
response_text)**
elif command == 'off':
# Stop
print("halt")
GPIO.output(Motor1E,GPIO.LOW)
response_text = render_template('Fan_command',
OnCommand=command)
return
statement(response_text).simple_card('Fan_command',response_text)
if __name__ == '__main__':
app.run(debug=True)
GPIO.cleanup()
`