From 776fa99ee6d4e76354112042a0d9491c377edebd Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 17 Dec 2021 11:31:29 +0100 Subject: [PATCH] Fix exception 28 on HRG15 Fix exception 28 on HRG15 (#14067) --- tasmota/xsns_90_hrg15.ino | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/tasmota/xsns_90_hrg15.ino b/tasmota/xsns_90_hrg15.ino index f7ba63721..46c17b28a 100644 --- a/tasmota/xsns_90_hrg15.ino +++ b/tasmota/xsns_90_hrg15.ino @@ -53,8 +53,7 @@ struct RG15 { float rate = 0.0f; } Rg15; -void Rg15Init(void) -{ +void Rg15Init(void) { Rg15.ready = 0; if (PinUsed(GPIO_HRG15_RX) && PinUsed(GPIO_HRG15_TX)) { HydreonSerial = new TasmotaSerial(Pin(GPIO_HRG15_RX), Pin(GPIO_HRG15_TX)); @@ -92,8 +91,7 @@ bool Rg15Poll(void) { while (HydreonSerial->available()) { Rg15ReadLine(rg15_buffer); - AddLog(LOG_LEVEL_DEBUG_MORE,PSTR("%s:" D_JSON_SERIALRECEIVED " = %s"),"HRG", rg15_buffer); - + AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("HRG: Received '%s'"), rg15_buffer); Rg15Process(rg15_buffer); } @@ -102,11 +100,11 @@ bool Rg15Poll(void) { return true; } -bool Rg15ReadLine(char* buffer) -{ +bool Rg15ReadLine(char* buffer) { char c; uint8_t i = 0; uint32_t cmillis = millis(); + buffer[0] = '\0'; while (1) { if (HydreonSerial->available()) { @@ -121,8 +119,7 @@ bool Rg15ReadLine(char* buffer) return false; } } - - buffer[i-2] = '\0'; + if (i > 1) { buffer[i-2] = '\0'; } return true; } @@ -163,14 +160,14 @@ bool Rg15Command(void) { HydreonSerial->flush(); if (send[0] == 'k' || send[0] == 'K' || send[0] == 'o' || send[0] == 'O') { - ResponseCmndDone(); - return serviced; + ResponseCmndDone(); + return serviced; } char rg15_buffer[255]; if (Rg15ReadLine(rg15_buffer)) { - Response_P(PSTR("{\"" D_JSON_SERIALRECEIVED "\":%s\"}"), rg15_buffer); - Rg15Process(rg15_buffer); + Response_P(PSTR("{\"" D_JSON_SERIALRECEIVED "\":\"%s\"}"), rg15_buffer); + Rg15Process(rg15_buffer); } } @@ -184,7 +181,7 @@ void Rg15Show(bool json) } if (json) { - ResponseAppend_P(PSTR(",\"" RG15_NAME "\":{\"" D_JSON_ACTIVE "\":%2_f, \"" D_JSON_EVENT "\":%2_f, \"" D_JSON_TOTAL "\":%2_f, \"" D_JSON_FLOWRATE "\":%2_f}"), &Rg15.acc, &Rg15.event, &Rg15.total, &Rg15.rate); + ResponseAppend_P(PSTR(",\"" RG15_NAME "\":{\"" D_JSON_ACTIVE "\":%2_f,\"" D_JSON_EVENT "\":%2_f,\"" D_JSON_TOTAL "\":%2_f,\"" D_JSON_FLOWRATE "\":%2_f}"), &Rg15.acc, &Rg15.event, &Rg15.total, &Rg15.rate); #ifdef USE_WEBSERVER } else { WSContentSend_PD(HTTP_RG15, &Rg15.acc, &Rg15.event, &Rg15.total, &Rg15.rate);