我正在尝试遵循this very basic tutorial的方法来使Alexa打开与Raspberry Pi相连的LED,但是我没有成功地使用该技能。我总是收到“请求的技能响应有问题”。我检查了设备日志,并且InvocationResponse始终为空。
我遵循了本教程中的所有步骤,除了必须在Intent Schema框上粘贴代码的部分。我认为该部分已经在最新的开发者控制台中自动处理了,对吗?我检查了JSON编辑器选项卡,并且本教程给出的大多数Intent Schema代码已经编写。我尝试编辑JSON编辑器,但没有成功-仍然显示响应错误。
我看过其他论坛,他们说我在Pi上本地运行的python脚本可能是问题所在。该脚本是本教程建议的this code的精确副本。 Ngrok似乎正在工作,因为它在终端上给出了200 OK。
我真的不知道如何开始调试此问题。希望有人可以帮助我!谢谢!
这是我在Pi上运行的python脚本:
from flask import Flask
from flask_ask import Ask, statement, convert_errors
import RPi.GPIO as GPIO
import logging
GPIO.setmode(GPIO.BCM)
app = Flask(__name__)
ask = Ask(app, '/')
logging.getLogger("flask_ask").setLevel(logging.DEBUG)
@ask.intent('GPIOControlIntent', mapping={'status': 'status'})
def gpio_status(status):
if status in ['on','high' ]:
GPIO.setup(21, GPIO.IN)
state = GPIO.input(21)
if (state == True):
GPIO.setup(21, GPIO.OUT)
GPIO.output(21,GPIO.HIGH)
return statement('Lights are already on')
else:
GPIO.setup(21, GPIO.OUT)
GPIO.output(21,GPIO.HIGH)
return statement('Turning lights {}'.format(status))
if status in ['off','low' ]:
GPIO.setup(21, GPIO.IN)
state = GPIO.input(21)
print('status of light',state)
if (state == False):
GPIO.setup(21, GPIO.OUT)
GPIO.output(21,GPIO.LOW)
return statement('Lights are already off')
else:
GPIO.setup(21, GPIO.OUT)
GPIO.output(21,GPIO.LOW)
return statement('Turning lights {}'.format(status))
if __name__ == '__main__':
port = 5000 #the custom port you want
app.run(host='0.0.0.0', port=port)
这就是AWS开发人员控制台中JSON编辑器上的内容
{
"interactionModel": {
"languageModel": {
"invocationName": "raspberry pi",
"intents": [
{
"name": "AMAZON.FallbackIntent",
"samples": []
},
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples": []
},
{
"name": "GPIOControlIntent",
"slots": [
{
"name": "status",
"type": "GPIO_Control"
}
],
"samples": [
"turn the light {status}",
"turn {status} the light"
]
}
],
"types": [
{
"name": "GPIO_Control",
"values": [
{
"name": {
"value": "off"
}
},
{
"name": {
"value": "on"
}
}
]
}
]
}
}
}