I have explained how to control light which is connected to UNO and controlled by Alexa . There are many ways to use Alexa service . First we are going to install dependencies on RPi and then we create Alexa skill .
Raspberry Pi1. Install the required libraries
sudo apt-get install python-pip
sudo
sudo
sudo apt-get install python-serial
sudo apt-get intall libpython2.7-dev
2. Install Arduino IDE on RPi or you can program using your pc and then connect it serially with RPiTo install Arduino in RPi
1. Go to official site and download previous release.
https://www.arduino.cc/en/Main/OldSoftwareReleases#previous
After that unzip it and go to directory of arduino
and start it with ./arduino
Program to be used in Arduino
int led = 13;
void setup() {
// put your setup code here, to run once:
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.read() == 'N') {
digitalWrite(led, HIGH);
}else if(Serial.read() == 'F') {
digitalWrite(led, LOW);
}
}
After uploading program,open serial terminal
when you write N led will turn on
When you write F led will turn off
2. Make a python script
from flask import Flask
from flask_ask import Ask, statement
import requests
import json
import serial
ser = serial.Serial("/dev/ttyACM0", 9600) // pls change here for your serial
app = Flask(__name__)
ask = Ask(app, '/')
@ask.launch
@ask.intent("LightOn")
def on():
ser.write(b'N')
return statement("Hall light turned on.")
@ask.intent("LightOff")
def off():
ser.write(b'F')
return statement("Hall light turned off.")
if __name__ == "__main__":
app.run(debug=True)
Run it using python lighcontrol.py
3. Download Ngrok
Ngrok is secure tunneling platform to make your device online. With this platform you can make your web application or any application goes online with a very simple way. For download go to official site and download for ARM.
Unzip it and go to directory where you extract it. Run it using command
./ngrok http 5000
1. We have to Login to Amazon account.If you have an account then login it, if not signup there and login.
2. Go to Developer Console on top right side.
3. Go to Alexa ==> Alexa skill kit ==> Add new skill
4. You will see page like this. On this page it will ask skill type, name, language and invocation name . You can give any name, in invocation name you have to give name which you say while giving command to Alexa.
Please note select appropriate language which is used in you country if you select different language while creating skill. It will not work.
At the end update it ,save it and press next.
5. On next page, it will ask intents.An intent represents an action that fulfills a user’s spoken request. For more information
https://developer.amazon.com/docs/custom-skills/define-the-interaction-model-in-json-and-text.html
If there is any error you will see in red color.
{
"intents": [
{
"intent": "LightOn"
},
{
"intent": "LightOff"
}
]
}
save it and move to next page.
6. On next page it will ask two option for end point one is AWS and HTTPS
Here i am using HTTPS . The secure link is generated in Ngrok server use that your link is different than mine. Save it and move to next page.
7. For SSL certificate choose second option. Save it and move to next page.
8. To test whether our service is working or not . Make sure your Ngrok server is working and Python script also running otherwise it will not work.
You can see servers are getting request and post it.
You can see video here.
Comments