本帖最后由 422234 于 2017-11-22 16:55 编辑
硬件准备:1.raspberry pi 3B 2.8GB以上的TF卡 3.USB麦克风 4.音响 5.电源、数据线、网线等 Amazon ALEXA语音服务首先需要注册Amazon developer账号然后创建产品
填写设备名称,ID之类的
新建配置文件,那些name之类的填自己想的就行了
然后设置网络,在Allowed origins和Allowed return URLs分别输入https://localhost:3000和https://localhost:3000/authresponse
这样alexa语音服务就配置好了 树莓派端:下载raspbian系统然后烧录进TF卡中配置好wifi(注意!!!树莓派的系统必须是jessie版本的!!!一定要注意) 连接好wifi就可以开始搭建alexa了,首先更新一下:
sudo apt-get update && apt-get upgrade -ycd Desktopgit clone https://github/com/alexa/alexa-avs-sample-app.git
等待下载完成后:
cd Desktop/alexa-avs-sample-app/sudo nano automated_install.sh
然后将下面这3个更换为自己的
更换完成后按Ctrl+o保存Ctrl+x退出然后:
. automated_install.sh
安装环境,运行后会有选项,都选y,另外两个一个选US,另一个选3.5mm jack即可,由于源在国外,所以安装环境会比较慢,但不推荐换源,很可能出问题。
安装完成后需要将树莓派插上屏幕,然后打开3个终端:
第一个终端: cd Desktop/alexa-avs-sample-app/samples/companionService/npm start出现listening on port 3000就好了
第二个终端: cd Desktop/alexa-avs-sample-app/samples/javaclient/mvn exec:exec
这时会弹出来个窗口选ok即可
选完后会自动转跳到浏览器界面登录你的亚马逊账号
登录成功就好了 第三个终端:
cd Desktop/alexa-avs-sample-app/samples/wakeWordAgent/src/./wakeWordAgent -e sensory
这样就可以对着麦克风说alexa唤醒了!!! ESP8266端:
首先要准备ESP8266模块,然后在arduino IDE里添加ESP8266板卡(具体参考这里,注意!必须是v2.4.0的那个版本才可以编译过去) 接线图:
然后添加库: ESPAsyncTCP ESPAsyncUDP FauxMoESP library 添加库后复制以下代码: [kenrobot_code]#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "fauxmoESP.h"
/* Network credentials */
#define WIFI_SSID "你的wifi"
#define WIFI_PASS "密码"
#define SERIAL_BAUDRATE 115200
/* Belkin WeMo emulation */
fauxmoESP fauxmo;
/* Set Relay Pins */
#define RELAY_1 D5
#define RELAY_2 D6
#define RELAY_3 D7
#define RELAY_4 D8
void setup()
{
Serial.begin(SERIAL_BAUDRATE);
//setup and wifi connection
wifiSetup();
//Set relay pins to outputs
pinMode(RELAY_1, OUTPUT);
pinMode(RELAY_2, OUTPUT);
pinMode(RELAY_3, OUTPUT);
pinMode(RELAY_4, OUTPUT);
digitalWrite(RELAY_1, HIGH);
delay(500);
digitalWrite(RELAY_2, HIGH);
delay(500);
digitalWrite(RELAY_3, HIGH);
delay(500);
digitalWrite(RELAY_4, HIGH);
delay(500);
fauxmo.addDevice("Light One");
fauxmo.addDevice("Light Two");
fauxmo.addDevice("Outlet One");
fauxmo.addDevice("Outlet Two");
fauxmo.addDevice("Bed Room");
fauxmo.addDevice("Living Room");
fauxmo.onMessage(callback);
}
void loop()
{
fauxmo.handle();
}
/* ---------------------------------------------------------------------------
Device Callback
----------------------------------------------------------------------------*/
void callback(uint8_t device_id, const char * device_name, bool state)
{
Serial.print("Device "); Serial.print(device_name);
Serial.print(" state: ");
if (state)
{
Serial.println("ON");
}
else
{
Serial.println("OFF");
}
//Switching action on detection of device name
if ( (strcmp(device_name, "Light One") == 0) )
{
if (!state)
{
digitalWrite(RELAY_1, HIGH);
}
else
{
digitalWrite(RELAY_1, LOW);
}
}
if ( (strcmp(device_name, "Light Two") == 0) )
{
if (!state)
{
digitalWrite(RELAY_3, HIGH);
}
else
{
digitalWrite(RELAY_3, LOW);
}
}
if ( (strcmp(device_name, "Outlet One") == 0) )
{
if (!state)
{
digitalWrite(RELAY_2, HIGH);
}
else
{
digitalWrite(RELAY_2, LOW);
}
}
if ( (strcmp(device_name, "Outlet Two") == 0) )
{
if (!state)
{
digitalWrite(RELAY_4, HIGH);
}
else
{
digitalWrite(RELAY_4, LOW);
}
}
if ( (strcmp(device_name, "Bed Room") == 0) )
{
if (!state)
{
digitalWrite(RELAY_3, HIGH);
digitalWrite(RELAY_4, HIGH);
}
else
{
digitalWrite(RELAY_3, LOW);
digitalWrite(RELAY_4, LOW);
}
}
if ( (strcmp(device_name, "Living Room") == 0) )
{
if (!state)
{
digitalWrite(RELAY_1, HIGH);
digitalWrite(RELAY_2, HIGH);
}
else
{
digitalWrite(RELAY_1, LOW);
digitalWrite(RELAY_2, LOW);
}
}
}
/* -----------------------------------------------------------------------------
Wifi Setup
-----------------------------------------------------------------------------*/
void wifiSetup()
{
// Set WIFI module to STA mode
WiFi.mode(WIFI_STA);
// Connect
Serial.println ();
Serial.printf("[WIFI] 连接中..... %s ", WIFI_SSID);
Serial.println();
WiFi.begin(WIFI_SSID, WIFI_PASS);
// Wait
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(100);
}
Serial.print(" ==> 连接成功!" );
Serial.println();
// Connected!
Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
Serial.println();
}[/kenrobot_code]
纪念衬衫GET!!!!!
|