I have attended Alexa Hackathon in Phoenix. Along with Alexa, Drew Alden introduced me Particle and iftt.com. I found it very useful and powerful, hence I have decided to do a sample project using the skills I learned in the hackathon.
This project has 2 parts.
- Connecting RGB with Particle
- Integrating Alexa with Particle
I have used following code in Particle and tested the code by using the following simple CURL:
https://api.particle.io/v1/devices/<YOUR-DEVICE-ID>/ctrlled -d access_token=<YOUR-ACCESS-TOKEN> -d "args= green"
int led1 = D0; // BLUE
int led3 = D1; // GREEN
int led2 = D2; //RED
int controlled(String strPin){
Serial.println();
Serial.print("argument: ");
Serial.println(strPin);
Spark.publish("args",strPin);
if(strPin.equalsIgnoreCase("RED")){
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
}
else if(strPin.equalsIgnoreCase("GREEN")){
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
}else if(strPin.equalsIgnoreCase("BLUE")){
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
}
else{
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
}
return 1;
}
void setup() {
Serial.begin(115200);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
Particle.function("ctrlled", controlled);
}
void loop() {
delay(1000);
}
Once everything is working with Particle, I started integrating Alexa.
2. Alexa Configuration:I have created following intent schema for possible color options.
{
"intents": [
{
"intent": "ParticleIntent",
"slots": [
{
"name": "light",
"type": "LIST_OF_ANSWERS"
}
]
},
{
"intent": "HelpIntent",
"slots": []
}
]
}
I have given following values for LIST_OF_ANSWERS
GREEN | RED | BLUE
Sample utterance for Alexa:
ParticleIntent turn on {light} light
ParticleIntent switch on {light} light
ParticleIntent turn on {light}
ParticleIntent switch on {light}
ParticleIntent {light}
ParticleIntent {light} light on
HelpIntent help
HelpIntent help me
HelpIntent what can I ask you
HelpIntent get help
HelpIntent to help
HelpIntent to help me
HelpIntent what can you do
HelpIntent what do you do
HelpIntent how do I use you
HelpIntent how can I use you
HelpIntent what can you tell me
Complete code for integrating Alexa and Particle:
https://github.com/selvakumarvr/alexaparticleRGB/blob/master/Alexa/src/index.js
Learning:This is my first project using Alexa and Particle and I have learned lots of things about Particle as well as Alexa. Initially I have tested with Particle with URL Query string but it didn't work and finally I came to know that query string won't work and it require POST parameter. Then I have decided to test with Postman chrome plugin. But it didn't work. The only way useful and easy was using CURL. CURL is so powerful.
I have also setup Alexa in RaspberryPI and connected to big amplified speaker with push button. Now my daughters are using it everyday for lots of funny questions.







Comments