Store and share experiences about robocon, IoT, Embedded...
  • Home
  • Linux
  • Window
    • Latex
    • Matlab
  • Embedded programming
    • Jetson Tx1
    • Raspberry Pi
    • Raspberry Pico
  • Internet of things
    • HTTP+MySQL cho IoT
    • Websocket+Nodejs
    • ESP32
  • Electronics and robots
    • Robocon
    • Arduino
    • RISCV
    • FPGA
  • Network and devices
    • Basic CCNA
  • IoT Server
  • Q&A (Hỏi đáp)
  • About
No Result
View All Result
  • Home
  • Linux
  • Window
    • Latex
    • Matlab
  • Embedded programming
    • Jetson Tx1
    • Raspberry Pi
    • Raspberry Pico
  • Internet of things
    • HTTP+MySQL cho IoT
    • Websocket+Nodejs
    • ESP32
  • Electronics and robots
    • Robocon
    • Arduino
    • RISCV
    • FPGA
  • Network and devices
    • Basic CCNA
  • IoT Server
  • Q&A (Hỏi đáp)
  • About
No Result
View All Result
Store and share experiences about robocon, IoT, Embedded...
No Result
View All Result
Home Web of things

Điều khiển bật tắt đèn bằng giọng nói với ESP8266 và Alexa Echo Dot

Trong project này, các bạn được hướng dẫn cách điều khiển ESP8266 bằng giọng nói thông qua trợ lý ảo Alexa Echo Dot. Kết quả cuối cùng của project là có thể điều khiển bật tắt bằng giọng nói một chân GPIO nối với LED trên ESP8266.

admin by admin
October 28, 2019
in Web of things
0 0
0

Với project này, tôi chỉ demo cho các bạn bật tắt 1 led trên board mạch ESP8266, còn các bạn có thể tự phát triển thêm theo ý tưởng của mình.

Video demo project

Các thiết bị cần có để thực hiện project này:

  1. Trợ lý ảo Alexa Echo Dot
  2. Điện thoại cài sẵn app Amazon Alexa
  3. ESP8266 ( Node MCU, ..)

Các bước thực hiện

1.Cài đặt thư viện FauxmoESP

Để điều khiển được ESP8266 bằng Alexa Echo Dot, bạn cần phải cài đặt thư viện FauxmoESP. Thư viện này giúp mô phỏng lại các thiết bị smart home Belkin Wemo, cho phép chúng ta điều khiển ESP thông qua giao thức của thiết bị này. Và với thư viện này, Alexa sẽ nhận ra thiết bị ESP của các bạn ngay khi được nạp firmware cũng như kết nối cùng mạng với Alexa mà không cần phải cài đặt thêm một SKILL hoặc dịch vụ bên thứ 3 nào. Chính vì vậy, tốc độ điều khiển của Alexa lên ESP rất nhanh, so với các thiết bị khác dùng qua dịch vụ IFTTT.

– Cách cài đặt thư viện FauxmoESP

1.1 Tải thư viện FauxmoESP tại đây. Các bạn nên tải theo dạng file zip

1.2 Giải nén file zip, chúng ta được folder dạng xoseperez-fauxmoesp-f60c46d80f9b.

1.3 Hãy sửa lại tên thư mục vừa giải nén được thành xoseperez-fauxmoesp ( chú ý bên trong folder ban đầu lại có một folder con, chúng ta sẽ lấy folder con này để đổi tên)

1.4 Copy thư mục này vào vị trí cài đặt libraries của Arduino IDE. Cách tìm thư mục này thì rất đơn giản, các bạn vào File-> References, copy lại đường dẫn mặc định mà ở bên trên cùng, dán vào cửa sổ Window Explorer -> Enter, là ta sẽ mở được vị trí folder libraries.

1.5 Tắt Arduino IDE đi và mở lại, chúng ta sẽ kiểm tra thấy thư viện đã được add vào Arduino IDE thành công

2.Chúng ta cần cài đặt thêm một thư viện nữa đó là ESPAsyncTCP.

Cách cài đặt như sau:

2.1 Tải thư viện dạng file zip tại đây

2.2 Giải nén file zip, chúng ta sẽ có folder ESPAsyncTCP-master.

2.3 Thay đổi tên folder nêu trên thành ESPAsyncTCP, copy vào thư mục libraries như mục 1.4 ở trên. Tắt và khởi động lại Arudino IDE

3.Nạp code sau vào ESP8266

3.1 Chọn board ESP8266 trong Tool của Arduino IDE

3.2 Thay đổi các tham số về kết nối mạng cho đúng với mạng Wifi của bạn

#define WIFI_SSID “xxxx”

#define WIFI_PASS “xxxx”

3.3 Các bạn có thể thay đổi lại tên thiết bị khi ra lệnh cho Alexa bằng cách chỉnh sửa câu lệnh dưới đây.

#define LAMP_1 “lamp one”

#define LAMP_2 “lamp two”

Biên dịch và nạp firmware cho ESP826

Mã nguồn ESP đầy đủ.

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <Arduino.h>
#include <ESP8266WiFi.h>
#define RELAY_PIN_1 14
#define RELAY_PIN_2 16
 
#include "fauxmoESP.h"
 
#define SERIAL_BAUDRATE 115200
 
#define WIFI_SSID "xxxx"
#define WIFI_PASS "xxxx"
 
#define LAMP_1 "lamp one"
#define LAMP_2 "lamp two"
 
fauxmoESP fauxmo;
 
// Wi-Fi Connection
void wifiSetup() {
  // Set WIFI module to STA mode
  WiFi.mode(WIFI_STA);
  // Connect
  Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
 
  // Wait
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(100);
  }
  Serial.println();
 
  // Connected!
  Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
}
 
void setup() {
  // Init serial port and clean garbage
  Serial.begin(SERIAL_BAUDRATE);
  Serial.println();
 
  // Wi-Fi connection
  wifiSetup();
 
  // LED
  pinMode(RELAY_PIN_1, OUTPUT);
  digitalWrite(RELAY_PIN_1, HIGH);
 
  pinMode(RELAY_PIN_2, OUTPUT);
  digitalWrite(RELAY_PIN_2, HIGH);
  
  // You can enable or disable the library at any moment
  // Disabling it will prevent the devices from being discovered and switched
  fauxmo.enable(true);
 
  // Add virtual devices
  fauxmo.addDevice(LAMP_1);
  fauxmo.addDevice(LAMP_2);
 
  // fauxmoESP 2.0.0 has changed the callback signature to add the device_id,
  // this way it's easier to match devices to action without having to compare strings.
   Fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) {
    Serial.printf("Device #%d (%s) state: %s\n", device_id, device_name, state ? "ON" : "OFF");
    if ( (strcmp(device_name, LAMP_1) == 0) ) {
      // this just sets a variable that the main loop() does something about
      Serial.println("LED 1 switched by Alexa");
      //digitalWrite(RELAY_PIN_1, !digitalRead(RELAY_PIN_1));
      if (state) {
        digitalWrite(RELAY_PIN_1, LOW);
      } else {
        digitalWrite(RELAY_PIN_1, HIGH);
      }
    }
    if ( (strcmp(device_name, LAMP_2) == 0) ) {
      // this just sets a variable that the main loop() does something about
      Serial.println("LED 2 switched by Alexa");
      if (state) {
        digitalWrite(RELAY_PIN_2, LOW);
      } else {
        digitalWrite(RELAY_PIN_2, HIGH);
      }
    }
  });
 
  // Callback to retrieve current state (for GetBinaryState queries)
  /*fauxmo.onGetState([](unsigned char device_id, const char * device_name) {
      //return !digitalRead(RELAY_PIN_1);
      return
  });*/
}
 
void loop() {
  // Since fauxmoESP 2.0 the library uses the "compatibility" mode by
  // default, this means that it uses WiFiUdp class instead of AsyncUDP.
  // The later requires the Arduino Core for ESP8266 staging version
  // whilst the former works fine with current stable 2.3.0 version.
  // But, since it's not "async" anymore we have to manually poll for UDP
  // packets
  fauxmo.handle();
 
  /*static unsigned long last = millis();
  if (millis() - last > 5000) {
    last = millis();
    Serial.printf("[MAIN] Free heap: %d bytes\n", ESP.getFreeHeap());
  }*/
 
}

4 Bật Alexa và tìm kiếm ESP của bạn

Sau khi các bạn đã biên dịch và upload thành công mã nguồn vào ESP8266, các bạn có thể ra lệnh cho Alexa tìm kiếm thiết bị mới bằng lệnh sau: “Alexa, discover devices”

Sau đó chúng ta sẽ nghe Alexa trả lời nếu tìm được thiết bị mới như sau:

” Starting discovering… I found two new devices. Try saying “Alexa, turn on lamp one”

5. Cuối cùng là ra lệnh cho Alexa để kiểm tra hoạt động

“Alexa, turn on lamp 1”

“Alexa, turn off lamp 1”

“Alexa, turn on lamp 2”

“Alexa, turn off lamp 2”

Nếu Alexa nhận diện xong lệnh, sau đó trả lời “OK” là xong rồi. 🙂

Nguồn tham khảo:

1.https://bitbucket.org/xoseperez/fauxmoesp/src/master/

2.https://randomnerdtutorials.com/alexa-echo-with-esp32-and-esp8266/

 

Số lượt xem: 897
Tags: Amazon Alexa esp8266điều khiển bằng giọng nói ESP8266esp 8266esp 8266 Alexa Echo Dot

Related Posts

Đăng ký sử dụng và thiết lập ban đầu cho Web based MQTT client

Đăng ký sử dụng và thiết lập ban đầu cho Web based MQTT client

February 27, 2023
46
A MQTT web client over websocket for testing ESP8266, ESP32-CAM, Raspberry Pi, Pico..etc

A MQTT web client over websocket for testing ESP8266, ESP32-CAM, Raspberry Pi, Pico..etc

February 9, 2023
207
How to connect Raspberry Pico W to a wireless network?

How to connect Raspberry Pico W to a wireless network?

January 4, 2023
73

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Bài viết đọc nhiều

IoT Webserver- ESP8266/ESP32 gửi dữ liệu lên Cloud, hiển thị ra trình duyệt web với MySQL và PHP

IoT Webserver- ESP8266/ESP32 gửi dữ liệu lên Cloud, hiển thị ra trình duyệt web với MySQL và PHP

February 9, 2023
17.6k
Điều khiển ESP8266/ESP32 từ xa qua internet, không cần mở Port modem

Điều khiển ESP8266/ESP32 từ xa qua internet, không cần mở Port modem

November 7, 2019
10.7k
ESP32-CAMERA: Cài đặt môi trường Arduino IDE và nạp chương trình

ESP32-CAMERA: Cài đặt môi trường Arduino IDE và nạp chương trình

December 27, 2019
7.4k
IoT webserver- Gửi thông báo bằng email từ ESP8266 không dùng IFTTT

IoT webserver- Gửi thông báo bằng email từ ESP8266 không dùng IFTTT

November 19, 2020
5.8k
Store and share experiences about robocon, IoT, Embedded…

Lưu và chia sẻ những gì đã đọc, đã làm, đã nghiên cứu về vi điều khiển, hệ thống nhúng, internet of things, kiến trúc máy tính và hệ điều hành.

Liên hệ với quản trị viên

Chủ đề

  • Arduino
  • CCNA cơ bản
  • Cisco
  • Điện tử- Robot
  • ESP32
  • FPGA
  • HTTP+MySQL cho IoT
  • IoT Server
  • Jetson Tx1
  • Lập trình nhúng
  • Latex
  • Linux
  • Mạng và thiết bị mạng
  • Raspberry Pi
  • Raspberry Pico
  • RISCV
  • Robocon
  • Web of things
  • Websocket+Nodejs
  • Window
  • WordPress

Quản trị trang

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

© 2019- 2023 luuvachiase.net - Phát triển và quản trị bởi Đỗ Ngọc Tuấn và Nguyễn Văn Tuấn ***Vui lòng ghi rõ nguồn khi trích dẫn bài viết từ Website này. DMCA.com Protection Status

No Result
View All Result
  • Trang chủ
  • Linux
  • Window
  • Lập trình nhúng
    • Jetson Tx1
    • Raspberry Pi
  • Web of things
    • HTTP+MySQL cho IoT
    • Websocket+Nodejs
  • Điện tử- Robot
    • Robocon
    • Arduino
    • RISCV
    • FPGA
  • Mạng và thiết bị mạng
    • CCNA cơ bản
  • IoT Server
  • Giới thiệu
  • Q&A (Hỏi đáp)

© 2019- 2023 luuvachiase.net - Phát triển và quản trị bởi Đỗ Ngọc Tuấn và Nguyễn Văn Tuấn ***Vui lòng ghi rõ nguồn khi trích dẫn bài viết từ Website này. DMCA.com Protection Status

Login to your account below

Forgotten Password?

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In