-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAirConditionerAutoControl.cpp
63 lines (56 loc) · 1.02 KB
/
AirConditionerAutoControl.cpp
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
#include "AirConditionerAutoControl.h"
AirControl::AirControl(char* ssid, char* pwd)
{
dht.begin();
irsend.begin();
}
void AirControl::listen()
{
int temp = this->getSensorData();
Serial.print(temp);
if (temp > TEMP_COLD_MODE_LIMIT)
{
if (lastCommand == "shut")
{
this->sendIRcommand(irCold28);
lastCommand = "cold";
}
}
else if (-50 < temp < TEMP_HOT_MODE_LIMIT)
{
if (lastCommand == "shut")
{
this->sendIRcommand(irHot24);
lastCommand = "hot";
}
}
else if (TEMP_HOT_MODE_SET < temp < TEMP_COLD_MODE_SET)
{
if (lastCommand != "shut")
{
this->sendIRcommand(irShut);
lastCommand = "shut";
}
}
}
int AirControl::getSensorData()
{
//get temp data
// float humi = dht.readHumidity();
float temp = dht.readTemperature();
// int h = (int)humi;
int t = (int)temp;
if (isnan(t)) {
return -500;
}
if (t > 75)
{
return -500;
}
return t;
}
void AirControl::sendIRcommand(uint16_t command[])
{
//send air conditioner ir signal
irsend.sendRaw(command, 147, 38);
}