Add return status from AC
This commit is contained in:
@@ -6,6 +6,9 @@
|
|||||||
#include <Adafruit_BME280.h>
|
#include <Adafruit_BME280.h>
|
||||||
#include <MHZ19.h>
|
#include <MHZ19.h>
|
||||||
#include <RunningMedian.h>
|
#include <RunningMedian.h>
|
||||||
|
#include <IRremoteESP8266.h>
|
||||||
|
#include <IRsend.h>
|
||||||
|
#include <ir_Toshiba.h>
|
||||||
//#include "RemoteDebug.h" //https://github.com/JoaoLopesF/RemoteDebug
|
//#include "RemoteDebug.h" //https://github.com/JoaoLopesF/RemoteDebug
|
||||||
|
|
||||||
#define R_LED (13) //D7
|
#define R_LED (13) //D7
|
||||||
@@ -13,7 +16,8 @@
|
|||||||
#define B_LED (0) //D3
|
#define B_LED (0) //D3
|
||||||
#define MOV_SENS (16) //D0
|
#define MOV_SENS (16) //D0
|
||||||
#define P_SENS (14) //D5
|
#define P_SENS (14) //D5
|
||||||
#define WF_LED 2
|
#define WF_LED (2) //D4
|
||||||
|
#define IR_LED (4) //D2
|
||||||
#define HOST_NAME "MidRoom"
|
#define HOST_NAME "MidRoom"
|
||||||
#define TOPIC "home/midroom"
|
#define TOPIC "home/midroom"
|
||||||
|
|
||||||
|
|||||||
@@ -16,10 +16,12 @@ framework = arduino
|
|||||||
;board_build.f_cpu = 26000000L
|
;board_build.f_cpu = 26000000L
|
||||||
;board_build.ldscript = eagle.flash.1m.ld
|
;board_build.ldscript = eagle.flash.1m.ld
|
||||||
;board_build.flash_mode = dout
|
;board_build.flash_mode = dout
|
||||||
|
monitor_speed = 115200
|
||||||
upload_protocol = espota
|
upload_protocol = espota
|
||||||
upload_port = 192.168.1.132
|
upload_port = 192.168.1.132
|
||||||
lib_deps =
|
lib_deps =
|
||||||
jwrw/ESP_EEPROM @ ^2.0.0
|
jwrw/ESP_EEPROM @ ^2.0.0
|
||||||
robtillaart/RunningMedian @ ^0.3.3
|
robtillaart/RunningMedian @ ^0.3.3
|
||||||
|
crankyoldgit/IRremoteESP8266 @ ^2.8.2
|
||||||
;joaolopesf/RemoteDebug @ 3.0.5
|
;joaolopesf/RemoteDebug @ 3.0.5
|
||||||
|
|
||||||
@@ -40,6 +40,8 @@ void onMqttPublish(uint16_t packetId); */
|
|||||||
leds g_led(G_LED, 300, 100, true);
|
leds g_led(G_LED, 300, 100, true);
|
||||||
leds b_led(B_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);
|
//leds r_led(R_LED, 100);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@@ -119,6 +121,11 @@ void setup() {
|
|||||||
Serial1.print(h);
|
Serial1.print(h);
|
||||||
Serial1.print(F("\tP: "));
|
Serial1.print(F("\tP: "));
|
||||||
Serial1.println(p); */
|
Serial1.println(p); */
|
||||||
|
ac.begin();
|
||||||
|
ac.off();
|
||||||
|
ac.setFan(0);
|
||||||
|
ac.setMode(kToshibaAcAuto);
|
||||||
|
//ac.setSwing(kToshibaAcSwingOff);
|
||||||
}
|
}
|
||||||
|
|
||||||
EEPROM.begin(16);
|
EEPROM.begin(16);
|
||||||
@@ -302,6 +309,41 @@ void onMqttConnect(bool sessionPresent) {
|
|||||||
//itoa(mvDelaySet, v, 10);
|
//itoa(mvDelaySet, v, 10);
|
||||||
mqttClient.publish(TOPIC"/mvdelay", 1, false, v);
|
mqttClient.publish(TOPIC"/mvdelay", 1, false, v);
|
||||||
mqttClient.subscribe(TOPIC"/mvdelay", 1);
|
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);
|
// ultoa(ESP.getFlashChipSize(), v, 10);
|
||||||
// mqttClient.publish(TOPIC"/chipsize", 1, false, v);
|
// mqttClient.publish(TOPIC"/chipsize", 1, false, v);
|
||||||
// ultoa(ESP.getFlashChipRealSize(), v, 10);
|
// ultoa(ESP.getFlashChipRealSize(), v, 10);
|
||||||
@@ -340,6 +382,19 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
|
|||||||
EEPROM.put(4, mvDelaySet);
|
EEPROM.put(4, mvDelaySet);
|
||||||
EEPROM.commit();
|
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();
|
b_led.start();
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -38,4 +38,6 @@ lib_deps =
|
|||||||
# Accept new functionality in a backwards compatible manner and patches
|
# Accept new functionality in a backwards compatible manner and patches
|
||||||
;grubykarol/RemoteDebugFork997 @ ^3.0.7
|
;grubykarol/RemoteDebugFork997 @ ^3.0.7
|
||||||
swicago/HeatPump @ ^1.0.0
|
swicago/HeatPump @ ^1.0.0
|
||||||
|
ottowinter/ESPAsyncWebServer-esphome @ ^2.1.0
|
||||||
|
ayushsharma82/WebSerial @ ^1.3.0
|
||||||
; bblanchon/ArduinoJson @ ^6.18.0
|
; bblanchon/ArduinoJson @ ^6.18.0
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <Ticker.h>
|
#include <Ticker.h>
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <ESPAsyncTCP.h>
|
||||||
|
#include <ESPAsyncWebServer.h>
|
||||||
|
#include <WebSerial.h>
|
||||||
#include <AsyncMqttClient.h>
|
#include <AsyncMqttClient.h>
|
||||||
//#include <ArduinoJson.h>
|
//#include <ArduinoJson.h>
|
||||||
#include <HeatPump.h>
|
#include <HeatPump.h>
|
||||||
@@ -43,6 +47,7 @@ Ticker wifiReconnectTimer;
|
|||||||
#ifdef RDEB
|
#ifdef RDEB
|
||||||
RemoteDebug Debug;
|
RemoteDebug Debug;
|
||||||
#endif
|
#endif
|
||||||
|
AsyncWebServer server(80);
|
||||||
|
|
||||||
void connectToWifi();
|
void connectToWifi();
|
||||||
void connectToMqtt();
|
void connectToMqtt();
|
||||||
@@ -115,6 +120,8 @@ void setup(){
|
|||||||
Serial.println(F("Connect WIFI"));
|
Serial.println(F("Connect WIFI"));
|
||||||
#endif
|
#endif
|
||||||
connectToWifi();
|
connectToWifi();
|
||||||
|
WebSerial.begin(&server);
|
||||||
|
server.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
@@ -179,19 +186,22 @@ void onMqttConnect(bool sessionPresent) {
|
|||||||
#ifdef SDEB
|
#ifdef SDEB
|
||||||
Serial.println(F("Connected to MQTT..."));
|
Serial.println(F("Connected to MQTT..."));
|
||||||
#endif
|
#endif
|
||||||
// mqttClient.publish(MAIN_TOPIC "power_set", 1, false, "");
|
|
||||||
// mqttClient.publish(MAIN_TOPIC "mode_set", 1, false, "");
|
mqttClient.publish(MAIN_TOPIC"power_set", 1, false, hp.getPowerSettingBool() ? "1" : "0");
|
||||||
// mqttClient.publish(MAIN_TOPIC "temp_set", 1, false, "");
|
//mqttClient.publish(MAIN_TOPIC"power", 1, false, hp.getPowerSettingBool() ? "1" : "0");
|
||||||
// mqttClient.publish(MAIN_TOPIC "fan_set", 1, false, "");
|
mqttClient.publish(MAIN_TOPIC "mode_set", 1, false, hp.getModeSetting());
|
||||||
// mqttClient.publish(MAIN_TOPIC "vane_set", 1, false, "");
|
//mqttClient.publish(MAIN_TOPIC "mode", 1, false, hp.getModeSetting());
|
||||||
// mqttClient.publish(MAIN_TOPIC "widevane_set", 1, false, "");
|
mqttClient.publish(MAIN_TOPIC "temp_set", 1, false, String(hp.getTemperature()).c_str());
|
||||||
|
mqttClient.publish(MAIN_TOPIC "fan_set", 1, false, hp.getFanSpeed());
|
||||||
|
mqttClient.publish(MAIN_TOPIC "vane_set", 1, false, hp.getVaneSetting());
|
||||||
|
mqttClient.publish(MAIN_TOPIC "widevane_set", 1, false, hp.getWideVaneSetting());
|
||||||
//mqttClient.publish(MAIN_TOPIC DEBUG_TOPIC, 1, false, "");
|
//mqttClient.publish(MAIN_TOPIC DEBUG_TOPIC, 1, false, "");
|
||||||
mqttClient.subscribe(MAIN_TOPIC "power_set", 1);
|
mqttClient.subscribe(MAIN_TOPIC"power_set", 1);
|
||||||
mqttClient.subscribe(MAIN_TOPIC "mode_set", 1);
|
mqttClient.subscribe(MAIN_TOPIC"mode_set", 1);
|
||||||
mqttClient.subscribe(MAIN_TOPIC "temp_set", 1);
|
mqttClient.subscribe(MAIN_TOPIC"temp_set", 1);
|
||||||
mqttClient.subscribe(MAIN_TOPIC "fan_set", 1);
|
mqttClient.subscribe(MAIN_TOPIC"fan_set", 1);
|
||||||
mqttClient.subscribe(MAIN_TOPIC "vane_set", 1);
|
mqttClient.subscribe(MAIN_TOPIC"vane_set", 1);
|
||||||
mqttClient.subscribe(MAIN_TOPIC "widevane_set", 1);
|
mqttClient.subscribe(MAIN_TOPIC"widevane_set", 1);
|
||||||
#ifdef RDEB
|
#ifdef RDEB
|
||||||
debugD("MQTT Connect");
|
debugD("MQTT Connect");
|
||||||
#endif
|
#endif
|
||||||
@@ -221,12 +231,17 @@ void hpSettingsChanged() {
|
|||||||
// root["wideVane"] = currentSettings.wideVane;
|
// root["wideVane"] = currentSettings.wideVane;
|
||||||
mqttClient.publish(MAIN_TOPIC "power", 1, false, currentSettings.power);
|
mqttClient.publish(MAIN_TOPIC "power", 1, false, currentSettings.power);
|
||||||
mqttClient.publish(MAIN_TOPIC "mode", 1, false, currentSettings.mode);
|
mqttClient.publish(MAIN_TOPIC "mode", 1, false, currentSettings.mode);
|
||||||
|
mqttClient.publish(MAIN_TOPIC "mode_set", 1, false, currentSettings.mode);
|
||||||
char t[5];
|
char t[5];
|
||||||
dtostrf(currentSettings.temperature, 4, 1, t);
|
dtostrf(currentSettings.temperature, 4, 1, t);
|
||||||
mqttClient.publish(MAIN_TOPIC "temp", 1, false, t);
|
mqttClient.publish(MAIN_TOPIC "temp", 1, false, t);
|
||||||
mqttClient.publish(MAIN_TOPIC "fan", 1, false, currentSettings.fan);
|
mqttClient.publish(MAIN_TOPIC "fan", 1, false, currentSettings.fan);
|
||||||
mqttClient.publish(MAIN_TOPIC "vane", 1, false, currentSettings.vane);
|
mqttClient.publish(MAIN_TOPIC "vane", 1, false, currentSettings.vane);
|
||||||
mqttClient.publish(MAIN_TOPIC "wideVane", 1, false, currentSettings.wideVane);
|
mqttClient.publish(MAIN_TOPIC "wideVane", 1, false, currentSettings.wideVane);
|
||||||
|
mqttClient.publish(MAIN_TOPIC "temp_set", 1, false, t);
|
||||||
|
mqttClient.publish(MAIN_TOPIC "fan_set", 1, false, currentSettings.fan);
|
||||||
|
mqttClient.publish(MAIN_TOPIC "vane_set", 1, false, currentSettings.vane);
|
||||||
|
mqttClient.publish(MAIN_TOPIC "wideVane_set", 1, false, currentSettings.wideVane);
|
||||||
//root["iSee"] = currentSettings.iSee;
|
//root["iSee"] = currentSettings.iSee;
|
||||||
|
|
||||||
// char buffer[512];
|
// char buffer[512];
|
||||||
@@ -263,9 +278,14 @@ void hpStatusChanged(heatpumpStatus currentStatus) {
|
|||||||
// debugD("StatusSend %s", bufferInfo);
|
// debugD("StatusSend %s", bufferInfo);
|
||||||
// #endif
|
// #endif
|
||||||
char t[5];
|
char t[5];
|
||||||
|
static bool power_mode = currentStatus.operating;
|
||||||
dtostrf(currentStatus.roomTemperature, 4, 1, t);
|
dtostrf(currentStatus.roomTemperature, 4, 1, t);
|
||||||
mqttClient.publish(MAIN_TOPIC "temperature", 1, false, t);
|
mqttClient.publish(MAIN_TOPIC "temperature", 1, false, t);
|
||||||
mqttClient.publish(MAIN_TOPIC "operating", 1, false, currentStatus.operating == false ? "OFF" : "ON");
|
mqttClient.publish(MAIN_TOPIC "operating", 1, false, currentStatus.operating == false ? "OFF" : "ON");
|
||||||
|
if(currentStatus.operating != power_mode){
|
||||||
|
power_mode = currentStatus.operating;
|
||||||
|
mqttClient.publish(MAIN_TOPIC "power_set", 1, false, currentStatus.operating ? "1" : "0");
|
||||||
|
}
|
||||||
//mqttClient.publish(MAIN_TOPIC STATUS_TOPIC, 1, false, bufferInfo);
|
//mqttClient.publish(MAIN_TOPIC STATUS_TOPIC, 1, false, bufferInfo);
|
||||||
// if (!mqtt_client.publish(heatpump_status_topic, bufferInfo, true)) {
|
// if (!mqtt_client.publish(heatpump_status_topic, bufferInfo, true)) {
|
||||||
// mqtt_client.publish(heatpump_debug_topic, "failed to publish to room temp and operation status to heatpump/status topic");
|
// mqtt_client.publish(heatpump_debug_topic, "failed to publish to room temp and operation status to heatpump/status topic");
|
||||||
@@ -341,7 +361,10 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
|
|||||||
mqtt += topic;
|
mqtt += topic;
|
||||||
mqtt += " Payload:";
|
mqtt += " Payload:";
|
||||||
mqtt += String(message);
|
mqtt += String(message);
|
||||||
mqttClient.publish(MAIN_TOPIC "debug_mqtt", 1, false, mqtt.c_str());
|
mqttClient.publish(MAIN_TOPIC"debug_mqtt", 1, false, mqtt.c_str());
|
||||||
|
WebSerial.print(payload);
|
||||||
|
WebSerial.print(" pl:");
|
||||||
|
WebSerial.println(message);
|
||||||
#ifdef SDEB
|
#ifdef SDEB
|
||||||
Serial.print(F("MQTT msg: "));
|
Serial.print(F("MQTT msg: "));
|
||||||
Serial.println(message);
|
Serial.println(message);
|
||||||
@@ -351,7 +374,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (strcmp(topic, MAIN_TOPIC "power_set") == 0) {
|
if (strcmp(topic, MAIN_TOPIC "power_set") == 0) {
|
||||||
mqttClient.publish(MAIN_TOPIC "debug", 1, false, (String("Power set:") + String(message)).c_str());
|
//mqttClient.publish(MAIN_TOPIC "debug", 1, false, (String("Power set:") + String(message)).c_str());
|
||||||
#ifdef SDEB
|
#ifdef SDEB
|
||||||
Serial.print(F("Setpower: "));
|
Serial.print(F("Setpower: "));
|
||||||
Serial.println(message);
|
Serial.println(message);
|
||||||
|
|||||||
Reference in New Issue
Block a user