Мой код посвящен управлению двигателями постоянного тока с помощью Raspberry Pi 3 и Alexa.Для этого я использовал ngrok и flask-ask для конечной точки.Код для управления двигателями постоянного тока с помощью raspberrypi3 работает.
Так что я создал Intent на сайте разработчиков Amazon и сделал для управления двигателем постоянного тока с помощью alexa.Код застрял в «текст ответа на Alexa».Я попробовал несколько способов отладки кода. Но я не смог.
Это запрос ввода JSON в Alexa.
"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."
}
}
Файл Python для управления двигателем постоянного тока с помощью Alexa и Raspberry Pi 3:
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()
`