Skip to content

Commit

Permalink
1.20j
Browse files Browse the repository at this point in the history
  • Loading branch information
klausahrenberg committed Jan 24, 2021
1 parent 9f97156 commit 6ba8eb1
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 111 deletions.
2 changes: 1 addition & 1 deletion WThermostat/src/WThermostat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "WThermostat_DLX_LH01.h"

#define APPLICATION "Thermostat"
#define VERSION "1.20i"
#define VERSION "1.20j"
#define FLAG_SETTINGS 0x20
#define DEBUG false

Expand Down
123 changes: 76 additions & 47 deletions WThermostat/src/WThermostat.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define MODEL_CALYPSOW 7
#define MODEL_DLX_LH01 8
#define PIN_STATE_HEATING_RELAY 5
#define NOT_SUPPORTED 0x00

const char* SCHEDULES = "schedules";
const char* SCHEDULES_MODE_OFF = "off";
Expand Down Expand Up @@ -55,18 +56,27 @@ public :
virtual void configureCommandBytes() {
//command bytes
this->byteDeviceOn = 0x01;
this->byteTemperatureActual = 0x00;
this->byteTemperatureTarget = 0x00;
this->byteTemperatureFloor = 0x00;
this->byteTemperatureActual = NOT_SUPPORTED;
this->byteTemperatureTarget = NOT_SUPPORTED;
this->byteTemperatureFloor = NOT_SUPPORTED;
this->temperatureFactor = 2.0f;
this->byteSchedulesMode = 0x04;
this->byteLocked = 0x06;
this->byteSchedules = 0x65;
this->byteSchedulesMode = NOT_SUPPORTED;
this->byteLocked = NOT_SUPPORTED;
this->byteSchedules = NOT_SUPPORTED;
this->byteSchedulingPosHour = 1;
this->byteSchedulingPosMinute = 0;
this->byteSchedulingDays = 18;
}

virtual bool isDeviceStateComplete() {
return (((this->byteDeviceOn == NOT_SUPPORTED) || (!this->deviceOn->isNull())) &&
((this->byteTemperatureActual == NOT_SUPPORTED) || (!this->actualTemperature->isNull())) &&
((this->byteTemperatureTarget == NOT_SUPPORTED) || (this->targetTemperatureManualMode != 0.0)) &&
((this->byteTemperatureFloor == NOT_SUPPORTED) || (!this->actualFloorTemperature->isNull())) &&
((this->byteSchedulesMode == NOT_SUPPORTED) || (!this->schedulesMode->isNull()))
);
}

virtual void initializeProperties() {
//schedulesDayOffset
this->schedulesDayOffset = network->getSettings()->setByte("schedulesDayOffset", 0);
Expand All @@ -79,7 +89,7 @@ public :
this->targetTemperature->setOnChange(std::bind(&WThermostat::setTargetTemperature, this, std::placeholders::_1));
this->targetTemperature->setOnValueRequest([this](WProperty* p) {updateTargetTemperature();});
this->addProperty(targetTemperature);
if (byteTemperatureFloor != 0x00) {
if (byteTemperatureFloor != NOT_SUPPORTED) {
this->actualFloorTemperature = WProperty::createTargetTemperatureProperty("floorTemperature", "Floor");
this->actualFloorTemperature->setReadOnly(true);
this->actualFloorTemperature->setVisibility(MQTT);
Expand All @@ -88,6 +98,8 @@ public :
this->actualFloorTemperature = nullptr;
}
this->deviceOn = WProperty::createOnOffProperty("deviceOn", "Power");
//2021-01-24 test bht-002 bug
network->getSettings()->add(this->deviceOn);
this->deviceOn->setOnChange(std::bind(&WThermostat::deviceOnToMcu, this, std::placeholders::_1));
this->addProperty(deviceOn);
this->schedulesMode = new WProperty("schedulesMode", "Schedules", STRING, TYPE_THERMOSTAT_MODE_PROPERTY);
Expand Down Expand Up @@ -169,14 +181,9 @@ public :

}

void cancelConfiguration() {
unsigned char cancelConfigCommand[] = { 0x55, 0xaa, 0x00, 0x03, 0x00, 0x01, 0x02 };
commandCharsToSerial(7, cancelConfigCommand);
}

void handleUnknownMqttCallback(bool getState, String completeTopic, String partialTopic, char *payload, unsigned int length) {
if (partialTopic.startsWith(SCHEDULES)) {
if (byteSchedules != 0x00) {
if (byteSchedules != NOT_SUPPORTED) {
partialTopic = partialTopic.substring(strlen(SCHEDULES) + 1);
if (getState) {
//Send actual schedules
Expand Down Expand Up @@ -313,6 +320,10 @@ public :
}
}

virtual bool sendCompleteDeviceState() {
return this->completeDeviceState->getBoolean();
}

protected :
WClock *wClock;
WProperty* schedulesDayOffset;
Expand Down Expand Up @@ -383,25 +394,32 @@ protected :
return schedulesDayOffset->getByte();
}

virtual bool processCommand(byte commandByte) {
bool knownCommand = true;
if (commandByte == 0x03) {
//ignore, MCU response to wifi state
//55 aa 01 03 00 00

} else if (commandByte == 0x04) {
//Setup initialization request
//received: 55 aa 01 04 00 00
//send answer: 55 aa 00 03 00 01 00
unsigned char configCommand[] = { 0x55, 0xAA, 0x00, 0x03, 0x00, 0x01, 0x00 };
commandCharsToSerial(7, configCommand);
network->startWebServer();
} else if (commandByte == 0x1C) {
//Request for time sync from MCU : 55 aa 01 1c 00 00
this->sendActualTimeToBeca();
} else {
knownCommand = false;
}
virtual bool processCommand(byte commandByte, byte length) {
bool knownCommand = WTuyaDevice::processCommand(commandByte, length);
switch (commandByte) {
case 0x03: {
//ignore, MCU response to wifi state
//55 aa 01 03 00 00
knownCommand = (length == 0);
break;
}
case 0x04: {
//Setup initialization request
//received: 55 aa 01 04 00 00
//send answer: 55 aa 00 03 00 01 00
unsigned char configCommand[] = { 0x55, 0xAA, 0x00, 0x03, 0x00, 0x01, 0x00 };
commandCharsToSerial(7, configCommand);
network->startWebServer();
knownCommand = true;
break;
}
case 0x1C: {
//Request for time sync from MCU : 55 aa 01 1c 00 00
this->sendActualTimeToBeca();
knownCommand = true;
break;
}
}
return knownCommand;
}

Expand All @@ -416,9 +434,15 @@ protected :
if (commandLength == 0x05) {
//device On/Off
//55 aa 00 06 00 05 01 01 00 01 00|01
newB = (receivedCommand[10] == 0x01);
changed = ((changed) || (newB != deviceOn->getBoolean()));
deviceOn->setBoolean(newB);
//2021-01-24 test for bht-002
if (!this->mcuRestarted) {
newB = (receivedCommand[10] == 0x01);
changed = ((changed) || (newB != deviceOn->getBoolean()));
deviceOn->setBoolean(newB);
} else if (!this->deviceOn->isNull()) {
deviceOnToMcu(this->deviceOn);
this->mcuRestarted = false;
}
knownCommand = true;
}
} else if (cByte == byteTemperatureTarget) {
Expand All @@ -433,7 +457,7 @@ protected :
if (changed) updateTargetTemperature();
knownCommand = true;
}
} else if ((byteTemperatureActual != 0x00) && (cByte == byteTemperatureActual)) {
} else if ((byteTemperatureActual != NOT_SUPPORTED) && (cByte == byteTemperatureActual)) {
if (commandLength == 0x08) {
//actual Temperature
//e.g. 23C: 55 aa 01 07 00 08 03 02 00 04 00 00 00 2e
Expand All @@ -443,7 +467,7 @@ protected :
actualTemperature->setDouble(newValue);
knownCommand = true;
}
} else if ((byteTemperatureFloor != 0x00) && (cByte == byteTemperatureFloor)) {
} else if ((byteTemperatureFloor != NOT_SUPPORTED) && (cByte == byteTemperatureFloor)) {
if (commandLength == 0x08) {
//MODEL_BHT_002_GBLW - actualFloorTemperature
//55 aa 01 07 00 08 66 02 00 04 00 00 00 00
Expand Down Expand Up @@ -509,30 +533,35 @@ protected :
byte weekDay = wClock->getWeekDay();
weekDay += getSchedulesDayOffset();
weekDay = weekDay % 7;
int startAddr = (weekDay == 0 ? 36 : (weekDay == 6 ? 18 : 0));
int startAddr = (this->byteSchedulingDays == 18 ? (weekDay == 0 ? 36 : (weekDay == 6 ? 18 : 0)) : ((weekDay == 0) || (weekDay == 6) ? 18 : 0));
int period = 0;
if (wClock->isTimeEarlierThan(schedules[startAddr + period * 3 + hh_Offset], schedules[startAddr + period * 3 + mm_Offset])) {
//Jump back to day before and last schedule of day
weekDay = weekDay - 1;
weekDay = weekDay % 7;
startAddr = (weekDay == 0 ? 36 : (weekDay == 6 ? 18 : 0));
startAddr = (this->byteSchedulingDays == 18 ? (weekDay == 0 ? 36 : (weekDay == 6 ? 18 : 0)) : ((weekDay == 0) || (weekDay == 6) ? 18 : 0));
period = 5;
} else {
//check the schedules in same day
for (int i = 1; i < 6; i++) {
if (i < 5) {
if (wClock->isTimeBetween(schedules[startAddr + i * 3 + hh_Offset], schedules[startAddr + i * 3 + mm_Offset],
schedules[startAddr + (i + 1) * 3 + hh_Offset], schedules[startAddr + (i + 1) * 3 + mm_Offset])) {
period = i;
break;
int index = startAddr + i * 3;
if (index < this->byteSchedulingDays * 3) {
if ((i < 5) && (index + 1 < this->byteSchedulingDays * 3)) {
if (wClock->isTimeBetween(schedules[index + hh_Offset], schedules[index + mm_Offset],
schedules[startAddr + (i + 1) * 3 + hh_Offset], schedules[startAddr + (i + 1) * 3 + mm_Offset])) {
period = i;
break;
}
} else if (wClock->isTimeLaterThan(schedules[index + hh_Offset], schedules[index + mm_Offset])) {
period = (i == 5 ? 5 : 1);
}
} else if (wClock->isTimeLaterThan(schedules[startAddr + 5 * 3 + hh_Offset], schedules[startAddr + 5 * 3 + mm_Offset])) {
period = 5;
} else {
break;
}
}
}
int newPeriod = startAddr + period * 3;
if (/*(getThermostatModel() != MODEL_ET_81_W) && */(this->switchBackToAuto->getBoolean()) &&
if ((this->switchBackToAuto->getBoolean()) &&
(this->currentSchedulePeriod > -1) && (newPeriod != this->currentSchedulePeriod) &&
(this->schedulesMode->equalsString(SCHEDULES_MODE_OFF))) {
this->schedulesMode->setString(SCHEDULES_MODE_AUTO);
Expand Down
2 changes: 1 addition & 1 deletion WThermostat/src/WThermostat_BAC_002_ALW.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public :
this->byteDeviceOn = 0x01;
this->byteTemperatureActual = 0x03;
this->byteTemperatureTarget = 0x02;
this->byteTemperatureFloor = 0x00;
this->byteTemperatureFloor = NOT_SUPPORTED;
this->temperatureFactor = 2.0f;
this->byteSchedulesMode = 0x04;
this->byteLocked = 0x06;
Expand Down
2 changes: 1 addition & 1 deletion WThermostat/src/WThermostat_CalypsoW.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public :
this->temperatureFactor = 10.0f;
this->byteSchedulesMode = 0x03;
this->byteLocked = 0x06;
this->byteSchedules = 0x00;
this->byteSchedules = NOT_SUPPORTED;
this->byteSchedulingPosHour = 1;
this->byteSchedulingPosMinute = 0;
this->byteSchedulingDays = 18;
Expand Down
4 changes: 2 additions & 2 deletions WThermostat/src/WThermostat_DLX_LH01.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public :
this->byteDeviceOn = 0x01;
this->byteTemperatureActual = 0x03;
this->byteTemperatureTarget = 0x02;
this->byteTemperatureFloor = 0x00; //not supported
this->byteTemperatureFloor = NOT_SUPPORTED;
this->temperatureFactor = 1.0f;
this->byteSchedulesMode = 0x04;
this->byteLocked = 0x07;
this->byteSchedules = 0x00; //not supported
this->byteSchedules = NOT_SUPPORTED;
this->byteSchedulingPosHour = 1;
this->byteSchedulingPosMinute = 0;
this->byteSchedulingDays = 18;
Expand Down
2 changes: 1 addition & 1 deletion WThermostat/src/WThermostat_ET81W.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public :
this->temperatureFactor = 10.0f;
this->byteSchedulesMode = 0x03;
this->byteLocked = 0x06;
this->byteSchedules = 0x00;
this->byteSchedules = NOT_SUPPORTED;
this->byteSchedulingPosHour = 1;
this->byteSchedulingPosMinute = 0;
this->byteSchedulingDays = 18;
Expand Down
2 changes: 1 addition & 1 deletion WThermostat/src/WThermostat_HY08WE.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public :
this->temperatureFactor = 10.0f;
this->byteSchedulesMode = 0x04;
this->byteLocked = 0x06;
this->byteSchedules = 0x00;
this->byteSchedules = NOT_SUPPORTED;
this->byteSchedulingPosHour = 1;
this->byteSchedulingPosMinute = 0;
this->byteSchedulingDays = 18;
Expand Down
58 changes: 55 additions & 3 deletions WThermostat/src/WThermostat_ME81H.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ public :

virtual void configureCommandBytes() {
this->byteDeviceOn = 0x01;
this->byteTemperatureActual = 0x00; //actual temperature must be handled different at this model
//actual temperature must be handled in processStatusCommand (byte 0x08)
this->byteTemperatureActual = NOT_SUPPORTED;
this->byteTemperatureTarget = 0x10;
this->byteTemperatureFloor = 0x00; //temp disabled, collides with sensorSelection 0x2d;
this->byteTemperatureFloor = 0x2d;
this->temperatureFactor = 1.0f;
this->byteSchedulesMode = 0x02;
this->byteLocked = 0x28;
Expand All @@ -28,7 +29,7 @@ public :
this->byteSchedulingDays = 8;
//custom
this->byteSystemMode = 0x24;
this->byteSensorSelection = 0x2d;
this->byteSensorSelection = 0x2b;
}

virtual void initializeProperties() {
Expand Down Expand Up @@ -92,6 +93,57 @@ protected :
knownCommand = true;
}
}
} else {
//consume some unsupported commands
switch (cByte) {
case 0x66 :
//Temperature Scale C /
//MCU: C / 55 aa 03 07 00 05 66 04 00 01 00
//MCU: F / 55 aa 03 07 00 05 66 04 00 01 01
knownCommand = true;
break;
case 0x13 :
//Temperature ceiling
//MCU: 35C / 55 aa 03 07 00 08 13 02 00 04 00 00 00 23
//MCU: 40C / 55 aa 03 07 00 08 13 02 00 04 00 00 00 28
knownCommand = true;
break;
case 0x1a :
//Lower limit of temperature
//MCU: 5C / 55 aa 03 07 00 08 1a 02 00 04 00 00 00 05
//MCU: 10C / 55 aa 03 07 00 08 1a 02 00 04 00 00 00 0a
knownCommand = true;
break;
case 0x1b :
//Temperature correction
//MCU: 0C / 55 aa 03 07 00 08 1b 02 00 04 00 00 00 00
//MCU: -2C / 55 aa 03 07 00 08 1b 02 00 04 ff ff ff fe
knownCommand = true;
break;
case 0x0a :
//freeze /
//MCU: off / 55 aa 03 07 00 05 0a 01 00 01 00
//MCU: on / 55 aa 03 07 00 05 0a 01 00 01 01
knownCommand = true;
break;
case 0x65 :
//temp_differ_on - 1C /
//MCU: 55 aa 03 07 00 08 65 02 00 04 00 00 00 01
knownCommand = true;
break;
/*case 0x68 :
// programming_mode - weekend (2 days off) / MCU: 55 aa 03 07 00 05 68 04 00 01 01
knownCommand = true;
break;
case 0x2d :
//unknown Wifi state? / MCU: 55 aa 03 07 00 05 2d 05 00 01 00
knownCommand = true;
break;
case 0x24 :
//unknown Wifi state? / MCU: 55 aa 03 07 00 05 24 04 00 01 00
knownCommand = true;
break;*/
}
}
}
if (changed) {
Expand Down
2 changes: 1 addition & 1 deletion WThermostat/src/WThermostat_MK70GBH.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public :
this->byteDeviceOn = 0x01;
this->byteTemperatureActual = 0x03;
this->byteTemperatureTarget = 0x02;
this->byteTemperatureFloor = 0x00;
this->byteTemperatureFloor = NOT_SUPPORTED;
this->temperatureFactor = 10.0f;
this->byteSchedulesMode = 0x04;
this->byteLocked = 0x08;
Expand Down
12 changes: 6 additions & 6 deletions WThermostat/src/WThermostat_TEMPLATE.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public :

virtual void configureCommandBytes() {
this->byteDeviceOn = 0x01;
this->byteTemperatureActual = 0x18;
this->byteTemperatureTarget = 0x10;
this->byteTemperatureFloor = 0x00;
this->byteTemperatureActual = NOT_SUPPORTED;
this->byteTemperatureTarget = NOT_SUPPORTED;
this->byteTemperatureFloor = NOT_SUPPORTED;
this->temperatureFactor = 10.0f;
this->byteSchedulesMode =
this->byteLocked = 0x28;
this->byteSchedules = 0x26;
this->byteSchedulesMode = NOT_SUPPORTED;
this->byteLocked = NOT_SUPPORTED;
this->byteSchedules = NOT_SUPPORTED;
this->byteSchedulingPosHour = 0;
this->byteSchedulingPosMinute = 1;
this->byteSchedulingDays = 8;
Expand Down
Loading

0 comments on commit 6ba8eb1

Please sign in to comment.