該項(xiàng)目具有檢測(cè)室內(nèi)環(huán)境數(shù)據(jù)和發(fā)送電子郵件、開(kāi)燈按鈕、體感照明屏等功能。
經(jīng)過(guò)不斷的踩坑學(xué)習(xí),初代簡(jiǎn)易智能家居中控系統(tǒng)已經(jīng)完成,大部分功能已經(jīng)完成,但是有些功能WIO終端沒(méi)有實(shí)現(xiàn)。一方面是因?yàn)榇a量太大,會(huì)給WIO終端帶來(lái)很大的“壓力”;另一方面,我的技術(shù)還不夠,還得繼續(xù)學(xué)習(xí),尋找解決方案。
首先介紹一下我最初的想法:
WIO終端是一款高度集成的開(kāi)發(fā)板。它配備了液晶顯示屏、三個(gè)按鈕、一個(gè)五向開(kāi)關(guān)、麥克風(fēng)、揚(yáng)聲器、加速度傳感器、紅外發(fā)射器等,甚至可以與樹(shù)莓派和 Jetson nano 結(jié)合使用。作為家居的“大腦”,這些硬件非常實(shí)用。因此,在智能家居的中控系統(tǒng)中,我選擇WIO終端作為這個(gè)系統(tǒng)的核心。
未來(lái),家里應(yīng)該有一個(gè)智能管家。這個(gè)智能管家就是我現(xiàn)在做的簡(jiǎn)單版。有了它,您就可以在家中獲取準(zhǔn)確實(shí)時(shí)的溫度、濕度、光照強(qiáng)度等數(shù)據(jù)。不僅如此,它還像一個(gè)“萬(wàn)能”遙控器,可以幫助你控制家中的電器。當(dāng)然,它應(yīng)該像智能音箱一樣,能夠理解我們給它的指令并響應(yīng)我們!
提前準(zhǔn)備
在這個(gè)項(xiàng)目的過(guò)程中,我第一次使用了開(kāi)發(fā)板WIO終端:
不知為何,在WIO終端上使用grow-temperature 濕度壓力氣體傳感器時(shí),接收不到數(shù)據(jù),只好轉(zhuǎn)身實(shí)現(xiàn):
使用Django搭建一個(gè)簡(jiǎn)單的數(shù)據(jù)中心(基于Grove——溫度濕度壓力氣體傳感器)
重回正軌,實(shí)現(xiàn)數(shù)據(jù)展示的主要功能:
使用WIO終端通過(guò)HTTP請(qǐng)求獲取并顯示傳感器實(shí)時(shí)數(shù)據(jù)
下一步就是完善其他三個(gè)功能,我主要通過(guò)python實(shí)現(xiàn)
完善系統(tǒng)功能
前面我簡(jiǎn)單提到了一些WIO終端上沒(méi)有實(shí)現(xiàn)的功能的原因,具體原因我沒(méi)有細(xì)說(shuō)。畢竟剛開(kāi)始做,所以打算先實(shí)現(xiàn)功能。至于實(shí)現(xiàn)方式,我想在二代系統(tǒng)中改進(jìn)一下
通過(guò) WIO 端子輸出狀態(tài)
我要表達(dá)的狀態(tài)是讀取可配置按鈕的狀態(tài)(是否按下按鈕)和麥克風(fēng)的數(shù)據(jù)(數(shù)據(jù)也可以代表狀態(tài))
對(duì)于WIO終端來(lái)說(shuō),簡(jiǎn)單的輸出這些數(shù)據(jù)還是比較簡(jiǎn)單的
補(bǔ)充 setup() 中的管腳定義:
pinMode(WIO_MIC, INPUT);
pinMode(WIO_KEY_A, INPUT_PULLUP);
pinMode(WIO_KEY_B, INPUT_PULLUP);
pinMode(WIO_KEY_C, INPUT_PULLUP);
補(bǔ)充loop()中的if條件語(yǔ)句:
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");
}
當(dāng)WIO終端連接PC時(shí),PC會(huì)讀取串口的數(shù)據(jù),并在讀取相應(yīng)的輸出時(shí)采取相應(yīng)的動(dòng)作
至此,我們已經(jīng)完成了關(guān)于 Arduino 的所有代碼。整理一下代碼,分享給大家。
#include
#include
#include"LIS3DHTR.h"
#include"Free_Fonts.h"
#include"TFT_eSPI.h"
TFT_eSPI tft;
LIS3DHTR 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);
}
上傳成功后,打開(kāi)串口監(jiān)視器:
接下來(lái)我們來(lái)看看Python的具體實(shí)現(xiàn)
使用Python讀取串口數(shù)據(jù)并做出相應(yīng)決策
web端增加了保存數(shù)據(jù)的功能
因?yàn)槲倚枰l(fā)送郵件,所以我先將傳感器接收到的數(shù)據(jù)存儲(chǔ)在一個(gè)TXT文本文件中。發(fā)送郵件時(shí),我可以直接發(fā)送這個(gè)文本文件
在視圖中在 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)
文件存放路徑可以修改為自己的路徑
打開(kāi)文本文件,看能否保存成功:
通過(guò)紅外模塊控制小夜燈
小夜燈可以遙控控制:
因?yàn)閃IO終端沒(méi)有紅外解碼功能,所以我又買(mǎi)了一個(gè)紅外模塊,編解碼合二為一。當(dāng)然,我還需要一個(gè)usb-ttl串口轉(zhuǎn)換器:
其實(shí)這個(gè)想法很簡(jiǎn)單。讀取遙控器對(duì)應(yīng)按鍵發(fā)送的數(shù)據(jù),然后用紅外模塊發(fā)送出去
可以使用串口調(diào)試助手進(jìn)行解碼,更方便:
串行端口發(fā)送它接收到的任何內(nèi)容。收貨時(shí)最好找個(gè)比較暗的地方多試幾次
以下是我收集的每個(gè)密鑰應(yīng)該發(fā)送的數(shù)據(jù)(十六進(jìn)制):
開(kāi)燈
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 '
調(diào)光
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 '
要發(fā)送紅外線,只需再添加兩行:
send_data = bytes.fromhex(send_data) #先編碼,再發(fā)送
infrared_ser.write(send_data)
通過(guò)語(yǔ)音控制PC發(fā)送郵件
語(yǔ)音不是真正的語(yǔ)音識(shí)別。當(dāng)WIO終端識(shí)別到環(huán)境音頻信號(hào)有波動(dòng)時(shí),會(huì)發(fā)送“send message!” 到串口,PC讀取后發(fā)送郵件
說(shuō)話時(shí),音頻信號(hào)會(huì)有明顯的波動(dòng):
發(fā)送電子郵件并不難。我把它封裝成一個(gè)方法,當(dāng)時(shí)可以直接調(diào)用
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
def send():
# 第三方 SMTP 服務(wù)
mail_host="smtp.qq.com" #設(shè)置服務(wù)器
mail_user="" #用戶名
mail_pass="" #口令
sender = ''
receivers = [''] # 接收郵件,可設(shè)置為你的QQ郵箱或者其他郵箱
#創(chuàng)建一個(gè)帶附件的實(shí)例
message = MIMEMultipart()
message['From'] = Header("Wio Terimal", 'utf-8')
message['To'] = Header("溫濕度、大氣壓力、可燃?xì)怏w檢測(cè)數(shù)據(jù)", 'utf-8')
subject = '當(dāng)前溫濕度、大氣壓力、可燃?xì)怏w檢測(cè)數(shù)據(jù)'
message['Subject'] = Header(subject, 'utf-8')
#郵件正文內(nèi)容
message.attach(MIMEText('溫濕度、大氣壓力、可燃?xì)怏w檢測(cè)數(shù)據(jù)', 'plain', 'utf-8'))
# 構(gòu)造附件,傳送當(dāng)前目錄下的 test.txt 文件
att = MIMEText(open('D:\TemperatureHumidityPressureGasData.txt', 'rb').read(), 'base64', 'utf-8')
att["Content-Type"] = 'application/octet-stream'
# 這里的filename可以任意寫(xiě),寫(xiě)什么名字,郵件中顯示什么名字
att["Content-Disposition"] = 'attachment; filename="TemperatureHumidityPressureGasData.txt"'
message.attach(att)
server = smtplib.SMTP_SSL(mail_host, 465) # SMTP協(xié)議默認(rèn)端口是25
server.set_debuglevel(1)
server.login(mail_user, mail_pass)
try:
server.sendmail(sender, receivers, message.as_string())
print ("郵件發(fā)送成功")
except smtplib.SMTPException:
print ("Error: 無(wú)法發(fā)送郵件")
此處的發(fā)送者和接收者可以編寫(xiě)自己的電子郵件。嘗試發(fā)送電子郵件進(jìn)行測(cè)試:
預(yù)覽此 TXT 文件:
通過(guò)語(yǔ)音合成回復(fù)用戶
Windows系統(tǒng)下,可以直接調(diào)用系統(tǒng)的語(yǔ)音包:
import win32com.client
speaker = win32com.client.Dispatch("SAPI.SpVoice")
text = "輸入要語(yǔ)音合成的內(nèi)容"
speaker.Speak(text)
完整的程序
代碼中的串口需要改成自己的串口:
Com14是WIO終端開(kāi)發(fā)板
Com15是紅外模塊
Com19是seeeduino v4 2開(kāi)發(fā)板
每次插上后,可能會(huì)因?yàn)?a href="http://www.www27dydycom.cn/v/tag/1247/" target="_blank">電腦上的USB接口不夠,導(dǎo)致串口發(fā)生變化。我買(mǎi)了一個(gè) USB 擴(kuò)展塢
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 服務(wù)
mail_host="smtp.qq.com" #設(shè)置服務(wù)器
mail_user="2733821739@qq.com" #用戶名
mail_pass="" #口令
sender = '2733821739@qq.com'
receivers = ['2733821739@qq.com'] # 接收郵件,可設(shè)置為你的QQ郵箱或者其他郵箱
#創(chuàng)建一個(gè)帶附件的實(shí)例
message = MIMEMultipart()
message['From'] = Header("Wio Terimal", 'utf-8')
message['To'] = Header("溫濕度、大氣壓力、可燃?xì)怏w檢測(cè)數(shù)據(jù)", 'utf-8')
subject = '當(dāng)前溫濕度、大氣壓力、可燃?xì)怏w檢測(cè)數(shù)據(jù)'
message['Subject'] = Header(subject, 'utf-8')
#郵件正文內(nèi)容
message.attach(MIMEText('溫濕度、大氣壓力、可燃?xì)怏w檢測(cè)數(shù)據(jù)', 'plain', 'utf-8'))
# 構(gòu)造附件,傳送當(dāng)前目錄下的 test.txt 文件
att = MIMEText(open('D:\TemperatureHumidityPressureGasData.txt', 'rb').read(), 'base64', 'utf-8')
att["Content-Type"] = 'application/octet-stream'
# 這里的filename可以任意寫(xiě),寫(xiě)什么名字,郵件中顯示什么名字
att["Content-Disposition"] = 'attachment; filename="TemperatureHumidityPressureGasData.txt"'
message.attach(att)
server = smtplib.SMTP_SSL(mail_host, 465) # SMTP協(xié)議默認(rèn)端口是25
server.set_debuglevel(1)
server.login(mail_user, mail_pass)
try:
server.sendmail(sender, receivers, message.as_string())
print ("郵件發(fā)送成功")
speaker = win32com.client.Dispatch("SAPI.SpVoice")
text = "Message sent successfully"
speaker.Speak(text)
except smtplib.SMTPException:
print ("Error: 無(wú)法發(fā)送郵件")
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()
未來(lái)的想法
目前的系統(tǒng)只是一個(gè)非常簡(jiǎn)單的第一代版本。往后我們可能會(huì)考慮使用云平臺(tái)存儲(chǔ)傳感器采集的溫度、濕度、光照強(qiáng)度、紫外線強(qiáng)度等數(shù)據(jù),制作一個(gè)APP,讓用戶出門(mén)在外就可以知道家里的情況。
-
智能家居
+關(guān)注
關(guān)注
1932文章
9713瀏覽量
188716 -
python
+關(guān)注
關(guān)注
56文章
4822瀏覽量
85874
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
BME680環(huán)境傳感器的驅(qū)動(dòng)設(shè)計(jì)與實(shí)現(xiàn)

【開(kāi)源】基于stm32的智能家居控制中心
【EVB-335X-II申請(qǐng)】智能家居控制中心
BME680的參數(shù)資料
STM32移植BME680傳感器輸出IAQ相關(guān)資料分享
如何利用stm32的HAL庫(kù)實(shí)現(xiàn)BME680傳感器輸出IAQ?
為L(zhǎng)ED的Do Electronics GT倡議而打造的BME680模塊
什么才能算是智能家居真正的控制中心?
使用iic與bme680通信,Bme680數(shù)據(jù)讀取不到是為什么
STM32移植BME680傳感器輸出IAQ(室內(nèi)空氣質(zhì)量)

基于BME680和Raspberry Pi Pico的氣象站

BME680天氣監(jiān)測(cè)裝置開(kāi)源分享

評(píng)論