Add return status from AC

This commit is contained in:
2022-07-10 18:43:35 +03:00
parent f3221660ce
commit 96976bfaef
5 changed files with 101 additions and 15 deletions

View File

@@ -6,6 +6,9 @@
#include <Adafruit_BME280.h>
#include <MHZ19.h>
#include <RunningMedian.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_Toshiba.h>
//#include "RemoteDebug.h" //https://github.com/JoaoLopesF/RemoteDebug
#define R_LED (13) //D7
@@ -13,7 +16,8 @@
#define B_LED (0) //D3
#define MOV_SENS (16) //D0
#define P_SENS (14) //D5
#define WF_LED 2
#define WF_LED (2) //D4
#define IR_LED (4) //D2
#define HOST_NAME "MidRoom"
#define TOPIC "home/midroom"

View File

@@ -16,10 +16,12 @@ framework = arduino
;board_build.f_cpu = 26000000L
;board_build.ldscript = eagle.flash.1m.ld
;board_build.flash_mode = dout
monitor_speed = 115200
upload_protocol = espota
upload_port = 192.168.1.132
lib_deps =
jwrw/ESP_EEPROM @ ^2.0.0
robtillaart/RunningMedian @ ^0.3.3
crankyoldgit/IRremoteESP8266 @ ^2.8.2
;joaolopesf/RemoteDebug @ 3.0.5

View File

@@ -40,6 +40,8 @@ void onMqttPublish(uint16_t packetId); */
leds g_led(G_LED, 300, 100, true);
leds b_led(B_LED, 300, 100, true);
const uint16_t kIrLed = IR_LED; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRToshibaAC ac(kIrLed); // Set the GPIO to be used for sending messages.
//leds r_led(R_LED, 100);
void setup() {
@@ -119,6 +121,11 @@ void setup() {
Serial1.print(h);
Serial1.print(F("\tP: "));
Serial1.println(p); */
ac.begin();
ac.off();
ac.setFan(0);
ac.setMode(kToshibaAcAuto);
//ac.setSwing(kToshibaAcSwingOff);
}
EEPROM.begin(16);
@@ -302,6 +309,41 @@ void onMqttConnect(bool sessionPresent) {
//itoa(mvDelaySet, v, 10);
mqttClient.publish(TOPIC"/mvdelay", 1, false, v);
mqttClient.subscribe(TOPIC"/mvdelay", 1);
switch (ac.getMode())
{
case kToshibaAcAuto:
v[0] = 'A';
break;
case kToshibaAcCool:
v[0] = 'C';
break;
case kToshibaAcDry:
v[0] = 'D';
break;
case kToshibaAcFan:
v[0] = 'F';
break;
case kToshibaAcHeat:
v[0] = 'H';
break;
default:
break;
}
mqttClient.publish(TOPIC"/ac/mode", 1, false, String(v[0]).c_str());
mqttClient.subscribe(TOPIC"/ac/mode", 1);
itoa(ac.getTemp(), v, 10);
mqttClient.publish(TOPIC"/ac/temp", 1, false, v);
mqttClient.subscribe(TOPIC"/ac/temp", 1);
itoa(ac.getFan(), v, 10);
mqttClient.publish(TOPIC"/ac/fan", 1, false, v);
mqttClient.subscribe(TOPIC"/ac/fan", 1);
mqttClient.publish(TOPIC"/ac/turbo", 1, false, ac.getTurbo() ? "1" : "0");
mqttClient.subscribe(TOPIC"/ac/turbo", 1);
mqttClient.publish(TOPIC"/ac/eco", 1, false, ac.getEcono() ? "1" : "0");
mqttClient.subscribe(TOPIC"/ac/eco", 1);
mqttClient.publish(TOPIC"/ac/state", 1, false, ac.getPower() ? "1" : "0");
mqttClient.subscribe(TOPIC"/ac/state", 1);
// ultoa(ESP.getFlashChipSize(), v, 10);
// mqttClient.publish(TOPIC"/chipsize", 1, false, v);
// ultoa(ESP.getFlashChipRealSize(), v, 10);
@@ -340,6 +382,19 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
EEPROM.put(4, mvDelaySet);
EEPROM.commit();
}
if(strcmp(topic, TOPIC"/mode") == 0){
char m = payload[0];
switch (m)
{
case 'A':
ac.setMode(kToshibaAcAuto);
break;
default:
break;
}
mvDelaySet = atoi(payload);
}
b_led.start();
}
/*