基於Wio Terminal的簡易智能家居中控系統(初代版本)

經過不斷地踩坑(學習),初代的簡易智能家居中控系統已經做好了,在申請項目時填寫的功能都做出來了,但是有些功能不是用Wio Terminal實現的(一方面是因爲代碼量太大,會給Wio Terminal的"壓力"也很大,另一方面,我的技術還不太夠,還要繼續學習、尋找解決方法)。

先給大家介紹一下我最初的想法

項目簡介

  Wio Terminal is a highly integrated development board, which comes with an LCD display, three buttons, a five-way switch, as well as microphones, speakers, accelerometers, infrared transmitters, etc., it can even be combined with the Raspberry Pi, Jetson nano! As the “brain” of a home, these hardware are extremely practical, therefore, in the smart home control system, I choose Wio Terminal as the core of this system.
  Wio Terminal是一塊高度集成的開發板,它自帶一塊液晶顯示屏、三個按鈕、一個五向開關以及麥克風、揚聲器、加速度傳感器、紅外發射器等,它甚至可以和樹莓派、Jetson nano結合。而作爲一個家的"大腦",這些硬件都是非常實用的,因此,在智能家居中控系統中,我選擇將Wio Terminal作爲這個系統的核心。

  In the future, there should be a smart housekeeper in the house, and this smart housekeeper is a simple version of what I am doing now. With it, you will be able to get accurate and real-time data of temperature, humidity, light intensity and so on. Not only that, it’s also like a “universal” remote control which can help you control your home’s appliances. Of course, it should be like a smart speaker can understand our instructions, and give us a response!
  未來的家裏,應該有一個智能管家,這個智能管家就是我現在做的簡易版本。有了它,你便可以獲取家裏準確且實時的溫度、溼度、光照強度等數據。不僅如此,它還像一個"萬能"遙控器,能幫助你操控家裏的電器。當然,它應該像智能音箱一樣可以聽懂我們給它的指令,並給我們做出迴應!

系統功能

  1. 在液晶顯示屏上展示溫溼度、光照強度、大氣壓力、可燃氣體含量等數據,爲了省電,當用戶拿起它時,該系統纔會顯示這些數據。
  2. 控制燈的開關,左邊的按鈕能控制燈的開關,中間和右邊的按鈕分別能調亮和調暗。
  3. 對該系統說話時,他會給用戶發送一個包含溫溼度、光照強度、大氣壓力、可燃氣體含量等數據的郵件。
  4. 該系統會在用戶操控燈或是用語音操控其發送郵件時,會給予語音反饋。

前期準備

在做這個項目的過程中,我第一次使用Wio Terminal這一開發板:
給初次使用Wio Terminal的開發者的入門指南

不知道是什麼原因,我在Wio Terminal上使用Grove - Temperature Humidity Pressure Gas Sensor時收不到數據,以至於我不得不繞了彎去實現它:
使用Django搭建簡易數據中臺(基於Grove - Temperature Humidity Pressure Gas Sensor)

重新走回正軌,實現顯示數據的主要功能:
使用Wio Terminal通過HTTP請求獲取並展示傳感器實時數據

下一步就要完善其他三個功能了,這三個功能我主要通過Python實現

完善系統功能

前面我簡單提了一下某些不在Wio Terminal上實現的功能的原因,具體原因就不過多地闡述了,畢竟纔剛開始做,所以我打算先把功能實現了,至於實現方式,我想在二代系統中去改善

通過Wio Terminal輸出狀態

我想表達的狀態,是讀取Configurable Buttons的狀態(是否按下按鈕)和Microphone的數據 (數據也可以代表狀態)

對於Wio Terminal來說,單純地輸出這些數據是比較簡單的

在setup()裏補充引腳定義:

pinMode(WIO_MIC, INPUT);
pinMode(WIO_KEY_A, INPUT_PULLUP);
pinMode(WIO_KEY_B, INPUT_PULLUP);
pinMode(WIO_KEY_C, INPUT_PULLUP);

在loop()裏補充if條件語句:

int val_first = analogRead(WIO_MIC);
int val_next = analogRead(WIO_MIC);

if (abs(val_first - val_next) >= 100){
  Serial.println("send message!");
  }
if (digitalRead(WIO_KEY_A) == LOW) {
  Serial.println("A Key pressed");
 }
if (digitalRead(WIO_KEY_B) == LOW) {
  Serial.println("B Key pressed");
 }
if (digitalRead(WIO_KEY_C) == LOW) {
  Serial.println("C Key pressed");
 }

當Wio Terminal連接PC端時,PC端會讀取串口的數據,讀到對應的輸出就做出相應的動作

到這裏,所有關於Arduino的代碼就講完了,下面把代碼整理一下,分享給大家,這篇文章沒有講到的代碼,請到前期準備裏查看

#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
#include"LIS3DHTR.h"
#include"Free_Fonts.h"
#include"TFT_eSPI.h"


TFT_eSPI tft;
LIS3DHTR<TwoWire> lis;
WiFiClient client;

const char* ssid     = "Your WiFi account";
const char* password = "Your WiFi password";
const char*  server = "192.168.1.102";  // Server URL
String data;
float accelerator_readings[3];

 
void setup() {
  
    //Initialize serial and wait for port to open:
    Serial.begin(115200);
    delay(100);

    pinMode(WIO_MIC, INPUT);
    pinMode(WIO_KEY_A, INPUT_PULLUP);
    pinMode(WIO_KEY_B, INPUT_PULLUP);
    pinMode(WIO_KEY_C, INPUT_PULLUP);
 
    lis.begin(Wire1);
    lis.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
    lis.setFullScaleRange(LIS3DHTR_RANGE_2G);

    float x_raw = lis.getAccelerationX();
    float y_raw = lis.getAccelerationY();
    float z_raw = lis.getAccelerationZ();
    accelerator_readings[0] = x_raw; //store x-axis readings
    accelerator_readings[1] = y_raw; //store y-axis readings
    accelerator_readings[2] = z_raw; //store z-axis readings
 
//    Serial.print("Attempting to connect to SSID: ");
//    Serial.println(ssid);
    WiFi.begin(ssid, password);
 
    tft.begin();
    tft.setRotation(3);
    tft.fillScreen(TFT_BLACK);
    tft.setFreeFont(FMB12);
    tft.setCursor((320 - tft.textWidth("Connecting to Wi-Fi.."))/2, 120);
    tft.print("Connecting to Wi-Fi..");
 
    // attempt to connect to Wifi network:
    while (WiFi.status() != WL_CONNECTED) {
//        Serial.print(".");
        // wait 1 second for re-trying
        delay(1000);
    }
 
//    Serial.print("Connected to ");
//    Serial.println(ssid);
 
    tft.fillScreen(TFT_BLACK);
    tft.setCursor((320 - tft.textWidth("Connected!"))/2, 120);
    tft.print("Connected!");
 
    getFirstData();
}
 
void loop()
{
    int val_first = analogRead(WIO_MIC);
    float x_raw = lis.getAccelerationX();
    float y_raw = lis.getAccelerationY();
    float z_raw = lis.getAccelerationZ();
    int val_next = analogRead(WIO_MIC);

    if (abs(val_first - val_next) >= 100){
      Serial.println("send message!");
      }
    if (digitalRead(WIO_KEY_A) == LOW) {
      Serial.println("A Key pressed");
     }
    if (digitalRead(WIO_KEY_B) == LOW) {
      Serial.println("B Key pressed");
     }
    if (digitalRead(WIO_KEY_C) == LOW) {
      Serial.println("C Key pressed");
     }
    
    if (abs(accelerator_readings[0] - x_raw) >= 0.1 && abs(accelerator_readings[1] - y_raw) >= 0.1 && abs(accelerator_readings[2] - z_raw) >= 0.1){
      // Turning on the LCD backlight
      digitalWrite(LCD_BACKLIGHT, HIGH);
      getFirstData();
      delay(3000);
      getLastData();
      delay(3000);
    }
    else {
      // Turning off the LCD backlight
      digitalWrite(LCD_BACKLIGHT, LOW);
      delay(500);
      }
      
    for (uint8_t i = 0; i<3; i++){
        accelerator_readings[i] = 0.0; //this is used to remove the first read variable
      }
    
    accelerator_readings[0] = x_raw; //store x-axis readings
    accelerator_readings[1] = y_raw; //store y-axis readings
    accelerator_readings[2] = z_raw; //store z-axis readings
}
 
void getFirstData() {
//    Serial.println("\nStarting connection to server...");
    if (!client.connect(server, 9000)) {
//        Serial.println("Connection failed!");
        tft.fillScreen(TFT_BLACK);
        tft.setCursor((320 - tft.textWidth("Connection failed!"))/2, 120);
        tft.print("Connection failed!");
    } else {
//        Serial.println("Connected to server!");
 
        // Make a HTTP request:
        String postRequest =(String)("GET ") + "/ HTTP/1.1\r\n" + "Connection: close\r\n\r\n";  
//        Serial.println(postRequest);  
        client.print(postRequest);

        while (client.connected()) {
            String line = client.readStringUntil('\n');
            if (line == "\r") {
//                Serial.println("headers received");
                break;
            }
        }
 
        while(client.available())
        {
          String line = client.readStringUntil('\r');
          data = line;
        }
//        Serial.println(data);
        client.stop();
//        Serial.println("closing connection");
    }
 
    //ArduinoJson to parse data, plesae check ArduinoJson for more info
    const size_t capacity = JSON_OBJECT_SIZE(5) + 100;
    DynamicJsonDocument doc(capacity);
    deserializeJson(doc, data);
 
    float temperature = doc["temperature"];
    float pressure = doc["pressure"];
    float humidity = doc["humidity"];
 
// -----------------LCD---------------------
    tft.setFreeFont(FF17);
    tft.setTextColor(tft.color565(224,225,232));
    tft.drawString("Current Data At Home",20,10);
 
    tft.fillRoundRect(10, 45, 300, 55, 5, tft.color565(40,40,86));
    tft.fillRoundRect(10, 105, 300, 55, 5, tft.color565(40,40,86));
    tft.fillRoundRect(10, 165, 300, 55, 5, tft.color565(40,40,86));
 
    tft.setFreeFont(FM9);
    tft.drawString("temperature:", 75, 50);
    tft.drawString("pressure:",75, 110);
    tft.drawString("humidity:",75, 170);
 
    tft.setFreeFont(FMB12);
    tft.setTextColor(TFT_RED);
    tft.drawFloat(temperature,2 , 140, 75);
    tft.setTextColor(tft.color565(224,225,232));
    tft.drawFloat(pressure,2 , 140, 135);
    tft.setTextColor(TFT_GREEN);
    tft.drawFloat(humidity,2 , 140, 195);

    tft.drawString("℃", 210, 75);
    tft.drawString("KPa",210, 135);
    tft.drawString("%",210, 195);
}

void getLastData() {
//    Serial.println("\nStarting connection to server...");
    if (!client.connect(server, 9000)) {
//        Serial.println("Connection failed!");
        tft.fillScreen(TFT_BLACK);
        tft.setCursor((320 - tft.textWidth("Connection failed!"))/2, 120);
        tft.print("Connection failed!");
    } else {
//        Serial.println("Connected to server!");

        // Make a HTTP request:
        String postRequest =(String)("GET ") + "/ HTTP/1.1\r\n" + "Connection: close\r\n\r\n";  
//        Serial.println(postRequest);  
        client.print(postRequest);

        while (client.connected()) {
            String line = client.readStringUntil('\n');
            if (line == "\r") {
//                Serial.println("headers received");
                break;
            }
        }
 
        while(client.available())
        {
          String line = client.readStringUntil('\r');
          data = line;
        }
//        Serial.println(data);
        client.stop();
//        Serial.println("closing connection");
    }
 
    //ArduinoJson to parse data, plesae check ArduinoJson for more info
    const size_t capacity = JSON_OBJECT_SIZE(5) + 100;
    DynamicJsonDocument doc(capacity);
    deserializeJson(doc, data);

    float humidity = doc["humidity"];
    float gas = doc["gas"];
    String updataTime = doc["updataTime"];
 
// -----------------LCD---------------------
    tft.setFreeFont(FF17);
    tft.setTextColor(tft.color565(224,225,232));
    tft.drawString("Current Data At Home",20,10);
 
    tft.fillRoundRect(10, 45, 300, 55, 5, tft.color565(40,40,86));
    tft.fillRoundRect(10, 105, 300, 55, 5, tft.color565(40,40,86));
    tft.fillRoundRect(10, 165, 300, 55, 5, tft.color565(40,40,86));
 
    tft.setFreeFont(FM9);
    tft.drawString("humidity:", 75, 50);
    tft.drawString("gas:",75, 110);
    tft.drawString("updataTime:",75, 170);
 
    tft.setFreeFont(FMB12);
    tft.setTextColor(TFT_RED);
    tft.drawFloat(humidity,2 , 140, 75);
    tft.setTextColor(tft.color565(224,225,232));
    tft.drawFloat(gas,2 , 140, 135);
    tft.setTextColor(TFT_GREEN);
    tft.drawString(updataTime , 30, 195);

    tft.drawString("%", 210, 75);
    tft.drawString("Kohms",210, 135);
}

成功上傳後,打開串口監視器:
在這裏插入圖片描述

下面,我們來看看Python的具體實現

使用Python讀取串口數據並做出相應決策

WEB端增加保存數據的功能

因爲需要發送郵件,所以我把傳感器接收到的數據先存放到一個txt文本文件裏,發送郵件時,直接發送這個文本文件即可

在views.py裏:

def index(request):
    datas = getDatas()
    content = {
        'temperature':datas[0],
        'pressure':datas[1],
        'humidity':datas[2],
        'gas':datas[3],
        'updataTime':datas[4],
    }
    jsonData = json.dumps(content)
    with open("D:\TemperatureHumidityPressureGasData.txt", "w") as fp:
        fp.write(jsonData)
    return HttpResponse(jsonData)

主要改動的地方就是:

with open("D:\TemperatureHumidityPressureGasData.txt", "w") as fp:
        fp.write(jsonData)

文件存放的路徑可以修改成自己的路徑

打開該文本文件,看一下是否可以成功保存:
在這裏插入圖片描述

通過紅外模塊控制小夜燈

小夜燈是在某寶買的,可以用遙控器控制的那種:
在這裏插入圖片描述

因爲Wio Terminal沒有紅外解碼功能,所以我另外買了一個紅外模塊,編碼和解碼合在一起那種,當然還需要一個USB-TTL串口轉換器:
在這裏插入圖片描述

思路其實很簡單,讀取遙控器上對應按鍵發送的數據,再用紅外模塊發射出去即可

解碼可以用串口調試助手,比較方便:
在這裏插入圖片描述
串口收到什麼就發送什麼,接收的時候最好找個暗一點的地方,多試幾次

下面是我收集到的各個按鍵應該發送的數據(十六進制):

開燈
send_data = 'FD FD 30 03 53 4B 00 34 17 01 3B 02 65 00 26 00 1E 00 27 00 D9 09 26 00 8A 00 40 02 C3 17 26 00 00 00 21 00 FF FF FF FF 01 22 22 22 22 11 11 11 11 12 11 22 22 21 22 11 13 45 46 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 76 00 22 DF DF'
調亮
send_data = 'FD FD 30 03 52 47 00 34 16 01 3A 02 66 00 27 00 20 00 27 00 D9 09 25 00 8A 00 41 02 00 00 21 00 FF FF FF FF FF FF FF FF 01 22 22 22 22 11 11 11 12 21 11 22 21 12 22 11 13 45 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 76 3F 6D DF DF '   
調暗
send_data = 'FD FD 30 03 53 4B 00 34 16 01 3C 02 63 00 27 00 1F 00 27 00 DA 09 25 00 8B 00 3D 02 C4 17 24 00 00 00 20 00 FF FF FF FF 01 22 22 22 22 11 11 11 12 11 11 22 21 22 22 11 13 45 46 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 76 3F 2E DF DF '

發送紅外只需要再加兩行即可:

send_data = bytes.fromhex(send_data) #先編碼,再發送
infrared_ser.write(send_data)

通過語音控制PC端發送郵件

語音這塊不是真正意義上的語音識別,當Wio Terminal識別到環境音頻信號有起伏時,會向串口發送"send message!",PC端讀取到後就會發送郵件

說話時,音頻信號會有明顯的起伏:
在這裏插入圖片描述
發送郵件不難,我把他封裝成了一個方法 ,用到時直接調用即可:

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header

def send():
    # 第三方 SMTP 服務
    mail_host="smtp.qq.com"  #設置服務器
    mail_user=""    #用戶名
    mail_pass=""   #口令

    sender = ''
    receivers = ['']  # 接收郵件,可設置爲你的QQ郵箱或者其他郵箱

    #創建一個帶附件的實例
    message = MIMEMultipart()
    message['From'] = Header("Wio Terimal", 'utf-8')
    message['To'] =  Header("溫溼度、大氣壓力、可燃氣體檢測數據", 'utf-8')
    subject = '當前溫溼度、大氣壓力、可燃氣體檢測數據'
    message['Subject'] = Header(subject, 'utf-8')

    #郵件正文內容
    message.attach(MIMEText('溫溼度、大氣壓力、可燃氣體檢測數據', 'plain', 'utf-8'))

    # 構造附件,傳送當前目錄下的 test.txt 文件
    att = MIMEText(open('D:\TemperatureHumidityPressureGasData.txt', 'rb').read(), 'base64', 'utf-8')
    att["Content-Type"] = 'application/octet-stream'
    # 這裏的filename可以任意寫,寫什麼名字,郵件中顯示什麼名字
    att["Content-Disposition"] = 'attachment; filename="TemperatureHumidityPressureGasData.txt"'
    message.attach(att)
    server = smtplib.SMTP_SSL(mail_host, 465) # SMTP協議默認端口是25
    server.set_debuglevel(1)
    server.login(mail_user, mail_pass)

    try:
        server.sendmail(sender, receivers, message.as_string())
        print ("郵件發送成功")
    except smtplib.SMTPException:
        print ("Error: 無法發送郵件")

這裏的發送方和接收方都可以寫成自己的郵箱 ,試着發送一封郵件測試一下:
在這裏插入圖片描述
預覽一下這個txt文件:
在這裏插入圖片描述

通過語音合成給予用戶回覆

在Windows系統下,可以直接調用系統的語音包:

import win32com.client

speaker = win32com.client.Dispatch("SAPI.SpVoice")
text = "輸入要語音合成的內容"
speaker.Speak(text)

下面來看一下完整的程序

完整的程序

代碼裏的串口需要改成自己的串口 :
在這裏插入圖片描述

  • COM14是Wio Terminal開發板
  • COM15是紅外模塊
  • COM19是Seeeduino V4.2開發板

每次插拔後,串口可能會發生改變,因爲電腦上的USB接口不夠用,我買了一個USB擴展塢

import serial
import re

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header

import win32com.client

speaker = win32com.client.Dispatch("SAPI.SpVoice")

def send():
    # 第三方 SMTP 服務
    mail_host="smtp.qq.com"  #設置服務器
    mail_user="[email protected]"    #用戶名
    mail_pass=""   #口令

    sender = '[email protected]'
    receivers = ['[email protected]']  # 接收郵件,可設置爲你的QQ郵箱或者其他郵箱

    #創建一個帶附件的實例
    message = MIMEMultipart()
    message['From'] = Header("Wio Terimal", 'utf-8')
    message['To'] =  Header("溫溼度、大氣壓力、可燃氣體檢測數據", 'utf-8')
    subject = '當前溫溼度、大氣壓力、可燃氣體檢測數據'
    message['Subject'] = Header(subject, 'utf-8')

    #郵件正文內容
    message.attach(MIMEText('溫溼度、大氣壓力、可燃氣體檢測數據', 'plain', 'utf-8'))

    # 構造附件,傳送當前目錄下的 test.txt 文件
    att = MIMEText(open('D:\TemperatureHumidityPressureGasData.txt', 'rb').read(), 'base64', 'utf-8')
    att["Content-Type"] = 'application/octet-stream'
    # 這裏的filename可以任意寫,寫什麼名字,郵件中顯示什麼名字
    att["Content-Disposition"] = 'attachment; filename="TemperatureHumidityPressureGasData.txt"'
    message.attach(att)
    server = smtplib.SMTP_SSL(mail_host, 465) # SMTP協議默認端口是25
    server.set_debuglevel(1)
    server.login(mail_user, mail_pass)

    try:
        server.sendmail(sender, receivers, message.as_string())
        print ("郵件發送成功")
        speaker = win32com.client.Dispatch("SAPI.SpVoice")
        text = "Message sent successfully"
        speaker.Speak(text)
    except smtplib.SMTPException:
        print ("Error: 無法發送郵件")




infrared_ser = serial.Serial('COM10', 9600, timeout=0.2)
Wio_terminal = serial.Serial('COM14', 115200, timeout=0.2)

# 接收返回的信息
while True:
    strs = Wio_terminal.readline().decode('utf-8')
    if strs.strip()!='':
        print(strs)
        if (re.match(r"C",strs)):
            send_data = 'FD FD 30 03 53 4B 00 34 17 01 3B 02 65 00 26 00 1E 00 27 00 D9 09 26 00 8A 00 40 02 C3 17 26 00 00 00 21 00 FF FF FF FF 01 22 22 22 22 11 11 11 11 12 11 22 22 21 22 11 13 45 46 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 76 00 22 DF DF'
            send_data = bytes.fromhex(send_data)
            infrared_ser.write(send_data)
            text = "OK executed"
            speaker.Speak(text)
        elif (re.match(r"B",strs)):
            send_data = 'FD FD 30 03 52 47 00 34 16 01 3A 02 66 00 27 00 20 00 27 00 D9 09 25 00 8A 00 41 02 00 00 21 00 FF FF FF FF FF FF FF FF 01 22 22 22 22 11 11 11 12 21 11 22 21 12 22 11 13 45 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 76 3F 6D DF DF '
            send_data = bytes.fromhex(send_data)
            infrared_ser.write(send_data)
            text = "Brightness up"
            speaker.Speak(text)
        elif (re.match(r"A",strs)):
            send_data = 'FD FD 30 03 53 4B 00 34 16 01 3C 02 63 00 27 00 1F 00 27 00 DA 09 25 00 8B 00 3D 02 C4 17 24 00 00 00 20 00 FF FF FF FF 01 22 22 22 22 11 11 11 12 11 11 22 21 22 22 11 13 45 46 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 76 3F 2E DF DF '
            send_data = bytes.fromhex(send_data)
            infrared_ser.write(send_data)
            text = "Brightness down"
            speaker.Speak(text)
        elif (re.match(r"send",strs)):
            try:
                send()
            except:
                text = "Failed to send mail. Please try again later"
                speaker.Speak(text)


infrared_ser.close()
Wio_terminal.close()

項目展示

基於Wio Terminal的簡易智能家居中控系統

後期想法

  目前的系統只是非常簡易的初代版本,後期會考慮使用雲平臺來存儲傳感器收集的溫溼度、光照強度、紫外線強度等數據,並製作一個app,讓用戶出門在外也能對家裏的情況瞭如指掌。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章