Skip to content

Commit 9d36de4

Browse files
authored
Merge pull request #802 from IgorYbema/main
v4.0 - now good
2 parents 6ec78e4 + e27c20f commit 9d36de4

File tree

7 files changed

+38
-20
lines changed

7 files changed

+38
-20
lines changed

HeishaMon/HeishaMon.ino

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -741,21 +741,25 @@ bool readSerial()
741741
log_message(_F("Extra data available on this heatpump"));
742742
extraDataBlockAvailable = true; //request for extra data next run
743743
}
744+
#ifdef RAWDEBUG
744745
{
745746
char mqtt_topic[256];
746747
sprintf(mqtt_topic, "%s/raw/data", heishamonSettings.mqtt_topic_base);
747748
mqtt_client.publish(mqtt_topic, (const uint8_t *)actData, DATASIZE, false); //do not retain this raw data
748749
}
750+
#endif
749751
data_length = 0;
750752
return true;
751753
} else if (data[3] == 0x21) { //decode the new model extra data block
752754
extraDataBlockAvailable = true; //set the flag to true so we know we can request this data always
753755
decode_heatpump_data_extra(data, actDataExtra, mqtt_client, log_message, heishamonSettings.mqtt_topic_base, heishamonSettings.updateAllTime);
756+
#ifdef RAWDEBUG
754757
{
755758
char mqtt_topic[256];
756759
sprintf(mqtt_topic, "%s/raw/dataextra", heishamonSettings.mqtt_topic_base);
757760
mqtt_client.publish(mqtt_topic, (const uint8_t *)actDataExtra, DATASIZE, false); //do not retain this raw data
758761
}
762+
#endif
759763
data_length = 0;
760764
return true;
761765
} else {
@@ -814,6 +818,7 @@ void pushCommandBuffer(byte* command, int length) {
814818
void serialTXTask(void *pvParameters) {
815819
unsigned long lastPCBSendTime = 0;
816820
unsigned long lastHPSendTime = 0;
821+
unsigned long lastHPExtraSendTime = 0;
817822
unsigned long lastPCBSaveTime = 0;
818823
char local_log_msg[LOG_MSG_SIZE];
819824

@@ -857,18 +862,26 @@ void serialTXTask(void *pvParameters) {
857862
byte chk = calcChecksum(panasonicQuery, PANASONICQUERYSIZE);
858863
heatpumpSerial.write(panasonicQuery, PANASONICQUERYSIZE);
859864
heatpumpSerial.write(chk);
860-
if (extraDataBlockAvailable) {
861-
panasonicQuery[3] = 0x21;
862-
chk = calcChecksum(panasonicQuery, PANASONICQUERYSIZE);
863-
heatpumpSerial.write(panasonicQuery, PANASONICQUERYSIZE);
864-
heatpumpSerial.write(chk);
865-
panasonicQuery[3] = 0x10;
866-
}
867-
sprintf_P(local_log_msg, PSTR("heatpump request datagram sent bytes: %d"), PANASONICQUERYSIZE + 1);
865+
sprintf_P(local_log_msg, PSTR("heatpump request query sent bytes: %d"), PANASONICQUERYSIZE + 1);
868866
xQueueSend(logQueue,local_log_msg,0);
869867
}
870868
}
871869

870+
// third priority: extra data block query every waitTime seconds (offset from basic query)
871+
if ((!sending) && (!heishamonSettings.listenonly) && extraDataBlockAvailable) {
872+
if ((unsigned long)(now - lastHPExtraSendTime) >= (1000 * heishamonSettings.waitTime)) {
873+
lastHPExtraSendTime = now;
874+
sending = true;
875+
sendCommandReadTime = now;
876+
panasonicQuery[3] = 0x21;
877+
byte chk = calcChecksum(panasonicQuery, PANASONICQUERYSIZE);
878+
heatpumpSerial.write(panasonicQuery, PANASONICQUERYSIZE);
879+
heatpumpSerial.write(chk);
880+
panasonicQuery[3] = 0x10;
881+
xQueueSend(logQueue, (void*)"heatpump extra query sent", 0);
882+
}
883+
}
884+
872885
// lowest priority: user commands from queue
873886
if ((!sending) && (!heishamonSettings.listenonly)) {
874887
struct cmdbuffer_t cmd;

HeishaMon/src/common/webserver.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -945,18 +945,23 @@ int http_parse_multipart_body(struct webserver_t *client, unsigned char *buf, ui
945945
client->readlen += (pos1+4);
946946
client->substep = 7; // skip case 5 entirely, go straight to data
947947
} else {
948-
// Single \r\n - more headers follow, go to case 5
948+
// Single \r\n - if more headers follow, go to case 5
949949
ptr1 = strncasestr(&client->buffer[pos], "\r\n", client->ptr-pos);
950950
if(ptr1 != NULL) {
951-
client->buffer[pos++] = '=';
952-
uint16_t pos1 = (ptr1-client->buffer);
953-
uint16_t newlen = client->ptr-((pos1+2)-pos);
954-
memmove(&client->buffer[pos], &client->buffer[pos1+2], newlen);
955-
client->ptr = newlen;
956-
client->readlen += (pos1+2);
957-
client->substep = 5;
958-
} else {
959-
client->substep = 6;
951+
if (((ptr1-client->buffer) + 4) >= client->ptr) {
952+
//CRLF on end of buffer, wait for two more to make sure we are not at end of header
953+
loop = 0;
954+
} else {
955+
client->buffer[pos++] = '=';
956+
uint16_t pos1 = (ptr1-client->buffer);
957+
uint16_t newlen = client->ptr-((pos1+2)-pos);
958+
memmove(&client->buffer[pos], &client->buffer[pos1+2], newlen);
959+
client->ptr = newlen;
960+
client->readlen += (pos1+2);
961+
client->substep = 5;
962+
}
963+
} else {
964+
client->substep = 6;
960965
}
961966
}
962967
} else {
16 Bytes
Binary file not shown.

binaries/model-type-large/HeishaMon.ino.esp32-v4.0-complete.bin renamed to binaries/model-type-large/HeishaMon.ino.esp32-v4.0.complete.bin

1.54 MB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f0ad2f3ac41f38c7f20bb6e8f8892cb3
1+
c9d1bbed9e5b87789fc2978964940bba
-16 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a84f109434b184a117cf14f0975bbcf4
1+
c57c0ce91e8b0935c4a6abbcea421e70

0 commit comments

Comments
 (0)