Skip to content

Commit

Permalink
v2.5R21
Browse files Browse the repository at this point in the history
- calculation of RETURN-AIR in MHI-AC-Ctrl.ino corrected
- Removed the option #define ROOM_TEMP_IU for adaption by the user in support.h. Now it is generated automatically when ROOM_TEMP_DS18X20 and ROOM_TEMP_MQTT are not defined
- Reworked WiFi network re-scan function
  • Loading branch information
absalom-muc committed Dec 17, 2021
1 parent dbcfec3 commit e3bc1bd
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 34 deletions.
5 changes: 2 additions & 3 deletions SW-Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,10 @@ note: The according libraries [OneWire](https://www.pjrc.com/teensy/td_libs_OneW
If the DS18x20 should replace the room temperature sensor of the AC, you have to confiure it as described in the next clause.

## Room temperature
Instead of using the room temperature sensor of the AC, the DS18x20 sensor on the MHI-AC-Ctrl board or the received temperature via the MQTT topic Troom can be used.
Usage of the room temperature sensor inside the AC is the default, but instead you can use the DS18x20 sensor on the MHI-AC-Ctrl board or the received temperature via the MQTT topic Troom.
```
//Use only one of the follwoing options for the room temperature
#define ROOM_TEMP_IU // use room temperature from indoor unit (default)
//#define ROOM_TEMP_DS18X20 // use room temperature from DS18x20
//#define ROOM_TEMP_MQTT // use room temperature from received MQTT topic
#define ROOM_TEMP_MQTT_TIMEOUT 20 // only considered if ROOM_TEMP_MQTT is defined
// time in seconds, after this time w/o receiving a valid room temperature
Expand Down
3 changes: 3 additions & 0 deletions Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ There was a [bug](https://github.com/knolleary/pubsubclient/issues/747) introduc
## :fire: MQTT connects / disconnects periodically
The HOSTNAME specified in support.h is used as WiFi hostname, MQTT hostname and OTA hostname. In case that you use more than one MHI-AC-Ctrl, e.g. in a multi-split configuration, you have to use unique HOSTNAME to every PCB.

## :fire: AC switches power off sometimes
When there is for >=120 seconds no valid MISO frame, the AC goes into an error state (MQTT topic Errorcode=1) and the AC switches off. You can leave the error state by sending a command via IR-RC or by sending a command via SPI. I assume this is some kind of safety function. This happens when there is >=120 seconds no WiFi or MQTT connection, because the SW loop related to SPI is not served.

## :fire: Receiving the AC status works, but can't change values
Different root causes are possible:
### :fire: MISO pin not connected to AC
Expand Down
5 changes: 5 additions & 0 deletions Version.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
MHI-AC-Ctrl by absalom-muc

**v2.5R21** (December 2021, draft version)
- calculation of RETURN-AIR in MHI-AC-Ctrl.ino corrected
- Removed the option #define ROOM_TEMP_IU for adaption by the user in support.h. Now it is generated automatically when ROOM_TEMP_DS18X20 and ROOM_TEMP_MQTT are not defined
- Reworked WiFi network re-scan function

**v2.5R1** (November 2021, draft version)
- Version number now located in support.h, published once MQTT connection is available

Expand Down
15 changes: 8 additions & 7 deletions src/MHI-AC-Ctrl-core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ void MHI_AC_Ctrl_Core::set_mode(ACMode mode) {
}

void MHI_AC_Ctrl_Core::set_tsetpoint(uint tsetpoint) {
new_Tsetpoint = 0b10000000 | (2 * tsetpoint);
//new_Tsetpoint = 0b10000000 | (2 * tsetpoint);
new_Tsetpoint = 0b10000000 | tsetpoint;
}

void MHI_AC_Ctrl_Core::set_fan(uint fan) {
Expand All @@ -141,9 +142,9 @@ void MHI_AC_Ctrl_Core::request_ErrOpData() {
}

#ifndef ROOM_TEMP_IU
void MHI_AC_Ctrl_Core::set_troom(byte temperature) {
Serial.printf("MHI_AC_Ctrl_Core::set_troom %i\n", temperature);
new_Troom = temperature;
void MHI_AC_Ctrl_Core::set_troom(byte troom) {
Serial.printf("MHI_AC_Ctrl_Core::set_troom %i\n", troom);
new_Troom = troom;
}
#endif

Expand Down Expand Up @@ -302,7 +303,7 @@ int MHI_AC_Ctrl_Core::loop(int max_time_ms) {

if (MOSI_frame[DB2] != status_tsetpoint_old) { // Temperature setpoint
status_tsetpoint_old = MOSI_frame[DB2];
m_cbiStatus->cbiStatusFunction(status_tsetpoint, (status_tsetpoint_old & 0x7f) >> 1);
m_cbiStatus->cbiStatusFunction(status_tsetpoint, status_tsetpoint_old);
}

if (MOSI_frame[DB4] != status_errorcode_old) { // error code
Expand Down Expand Up @@ -331,11 +332,11 @@ int MHI_AC_Ctrl_Core::loop(int max_time_ms) {
if (MOSI_frame[DB10] == 0x13) {
if (MOSI_frame[DB11] != op_settemp_old) {
op_settemp_old = MOSI_frame[DB11];
m_cbiStatus->cbiStatusFunction(opdata_tsetpoint, op_settemp_old >> 1);
m_cbiStatus->cbiStatusFunction(opdata_tsetpoint, op_settemp_old);
}
}
else if (MOSI_frame[DB10] == 0x33)
m_cbiStatus->cbiStatusFunction(erropdata_tsetpoint, MOSI_frame[DB11] >> 1);
m_cbiStatus->cbiStatusFunction(erropdata_tsetpoint, MOSI_frame[DB11]);
}
break;
case 0x81: // 5 THI-R1 or 6 THI-R2
Expand Down
13 changes: 6 additions & 7 deletions src/MHI-AC-Ctrl.ino
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ void MQTT_subscribe_callback(const char* topic, byte* payload, unsigned int leng
publish_cmd_invalidparameter();
}
else if (strcmp_P(topic, PSTR(MQTT_SET_PREFIX TOPIC_TSETPOINT)) == 0) {
if ((atoi((char*)payload) >= 18) & (atoi((char*)payload) <= 30)) {
mhi_ac_ctrl_core.set_tsetpoint(atoi((char*)payload));
publish_cmd_ok();
}
float f=atof((char*)payload);
if((f >= 18) & (f <= 30))
mhi_ac_ctrl_core.set_tsetpoint((byte)(2 * f));
else
publish_cmd_invalidparameter();
}
Expand Down Expand Up @@ -139,7 +138,7 @@ class StatusHandler : public CallbackInterface_Status {
void cbiStatusFunction(ACStatus status, int value) {
char strtmp[10];
static int mode_tmp = 0xff;
Serial.printf_P(PSTR("status=%i value=%i\n"), status, value);
//Serial.printf_P(PSTR("status=%i value=%i\n"), status, value);
switch (status) {
case status_fsck:
itoa(value, strtmp, 10);
Expand Down Expand Up @@ -216,7 +215,7 @@ class StatusHandler : public CallbackInterface_Status {
case status_tsetpoint:
case opdata_tsetpoint:
case erropdata_tsetpoint:
itoa(value, strtmp, 10);
dtostrf((value & 0x7f)/ 2.0, 0, 1, strtmp);
output_P(status, PSTR(TOPIC_TSETPOINT), strtmp);
break;
case status_errorcode:
Expand All @@ -226,7 +225,7 @@ class StatusHandler : public CallbackInterface_Status {
break;
case opdata_return_air:
case erropdata_return_air:
dtostrf(value * 0.25f - 15, 0, 2, strtmp);
dtostrf((value - 61) / 4.0, 0, 2, strtmp);
output_P(status, PSTR(TOPIC_RETURNAIR), strtmp);
break;
case opdata_thi_r1:
Expand Down
30 changes: 20 additions & 10 deletions src/support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ void setupWiFi() {
strongest_AP = i;
}
}

if((WiFi.status() != WL_CONNECTED) || ((max_rssi > WiFi.RSSI() + 10) && (strcmp(WiFi.BSSIDstr().c_str(), WiFi.BSSIDstr(strongest_AP).c_str()) != 0))) {
Serial.printf_P("current BSSID: %s, strongest BSSID: %s\n", WiFi.BSSIDstr().c_str(), WiFi.BSSIDstr(strongest_AP).c_str());
if((WiFi.status() != WL_CONNECTED) || ((max_rssi > WiFi.RSSI() + 6) && (strcmp(WiFi.BSSIDstr().c_str(), WiFi.BSSIDstr(strongest_AP).c_str()) != 0))) {
Serial.printf("Connecting from bssid:%s to bssid:%s, ", WiFi.BSSIDstr().c_str(), WiFi.BSSIDstr(strongest_AP).c_str());
Serial.printf("channel:%i.\n", WiFi.channel(strongest_AP));
Serial.printf("channel:%i\n", WiFi.channel(strongest_AP));
WiFi.begin(WIFI_SSID, WIFI_PASSWORD, WiFi.channel(strongest_AP), WiFi.BSSID(strongest_AP), true);
}
#else
Expand All @@ -46,12 +46,12 @@ void setupWiFi() {
#endif

unsigned long previousMillis = millis();
while ((WiFi.status() != WL_CONNECTED) || (millis() - previousMillis >= 10*1000)) {
delay(300);
while ((WiFi.status() != WL_CONNECTED) && (millis() - previousMillis < 10*1000)) {
delay(500);
Serial.print(F("."));
}
if(WiFi.status() == WL_CONNECTED)
Serial.printf_P(PSTR(" connected to %s, IP address: %s\n"), WIFI_SSID, WiFi.localIP().toString().c_str());
Serial.printf_P(PSTR(" connected to %s, IP address: %s, BSSID: %s\n"), WIFI_SSID, WiFi.localIP().toString().c_str(), WiFi.BSSIDstr().c_str());
else
Serial.printf_P(PSTR(" not connected, timeout!\n"));
}
Expand All @@ -61,6 +61,12 @@ void MQTTreconnect() {
char strtmp[50];
while (!MQTTclient.connected()) { // Loop until we're reconnected
Serial.print(F("Attempting MQTT connection..."));
if (WiFi.status() != WL_CONNECTED) {
Serial.println(F("WiFi not connected in MQTTreconnect function"));
#if UseStrongestAP==true
setupWiFi();
#endif
}
if (MQTTclient.connect(HOSTNAME, MQTT_USER, MQTT_PASSWORD, MQTT_PREFIX TOPIC_CONNECTED, 0, true, PAYLOAD_CONNECTED_FALSE)) {
Serial.println(F(" connected"));
output_P(status_connected, PSTR(TOPIC_CONNECTED), PSTR(PAYLOAD_CONNECTED_TRUE));
Expand All @@ -71,8 +77,8 @@ void MQTTreconnect() {
itoa(MQTT_lost, strtmp, 10);
output_P(status_mqtt_lost, PSTR(TOPIC_MQTT_LOST), strtmp);
WiFi.BSSIDstr().toCharArray(strtmp, 20);
output_P(status_mqtt_lost, PSTR(TOPIC_WIFI_BSSID), strtmp);
// for testing publish list of access points with the expected SSID
output_P(status_mqtt_lost, PSTR(TOPIC_WIFI_BSSID), strtmp); // CHECK status_mqtt_lost !!!!!!!!!!!!
// for testing publish list of access points with the expected WIFI_SSID
for (int i = 0; i < networksFound; i++)
{
if(strcmp(WiFi.SSID(i).c_str(), WIFI_SSID) == 0){
Expand All @@ -89,10 +95,14 @@ void MQTTreconnect() {
MQTTclient.subscribe(MQTT_SET_PREFIX "#");
}
else {
Serial.println(F(" reconnect failed"));
Serial.print(F(" reconnect failed, reason "));
itoa(MQTTclient.state(), strtmp, 10);
Serial.println(F("try again in 5 seconds"));
Serial.print(strtmp);
Serial.println(F(" try again in 5 seconds"));
Serial.print("WiFi status: ");
Serial.println(WiFi.status());
runtimeMillisMQTT = millis();
MQTTclient.disconnect();
while (millis() - runtimeMillisMQTT < 5000) { // Wait 5 seconds before retrying
delay(0);
ArduinoOTA.handle();
Expand Down
27 changes: 20 additions & 7 deletions src/support.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
#include "MHI-AC-Ctrl-core.h"
#include "MHI-AC-Ctrl.h"

#define VERSION "2.5R1"
#define VERSION "2.5R21"

#define WIFI_SSID "your SSID"
#define WIFI_PASSWORD "your WiFi password"
#define HOSTNAME "MHI-AC-Ctrl"

#define UseStrongestAP true // when false then the first WiFi access point with matching SSID found is used.
// when true then the strongest WiFi access point with matching SSID found is used,
// So far not implemented: addtionally the network is rescanned every 12 minutes for the strongest AP.
// when true then the strongest WiFi access point with matching SSID found is used, and
// WiFi network re-scan every 12 minutes with alternate to +5dB stronger signal if detected

#define MQTT_SERVER "MQTT broker name" // broker name or IP address of the broker
#define MQTT_SERVER "192.168.178.111" // broker name or IP address of the broker
#define MQTT_PORT 1883 // port number used by the broker
#define MQTT_USER "" // if authentication is not used, leave it empty
#define MQTT_PASSWORD "" // if authentication is not used, leave it empty
Expand All @@ -30,8 +30,7 @@
// enter 0 if you don't use the DS18x20
#define ONE_WIRE_BUS 4 // D2, PIN for connecting temperature sensor DS18x20 DQ pin

//Use only one of the follwoing options for the room temperature
#define ROOM_TEMP_IU // use room temperature from indoor unit (default)
// Per default AC internal sensor is used for the room temperature. You can select using the DS18x20 sensor or providing Troom via MQTT.
//#define ROOM_TEMP_DS18X20 // use room temperature from DS18x20
//#define ROOM_TEMP_MQTT // use room temperature from received MQTT topic
#define ROOM_TEMP_MQTT_TIMEOUT 20 // only considered if ROOM_TEMP_MQTT is defined
Expand All @@ -40,6 +39,8 @@

//#define POWERON_WHEN_CHANGING_MODE true // uncomment it to switch on the AC when the mode (heat, cool, dry etc.) is changed
// used e.g. for home assistant support

// *** The configuration ends here ***

#include <ESP8266WiFi.h> // https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WiFi
#include <PubSubClient.h> // https://github.com/knolleary/pubsubclient
Expand All @@ -56,6 +57,18 @@
#endif
#endif

#ifndef ROOM_TEMP_DS18X20
#ifndef ROOM_TEMP_MQTT
#define ROOM_TEMP_IU
#endif
#endif

#ifdef ROOM_TEMP_DS18X20
#ifdef ROOM_TEMP_MQTT
#error "It is not valid to select both ROOM_TEMP_DS18X20 and ROOM_TEMP_MQTT. Please select none or one of these options"
#endif
#endif

extern PubSubClient MQTTclient;

void initWiFi();
Expand Down

0 comments on commit e3bc1bd

Please sign in to comment.