From f890c2d85a61ffe9b3d7b9d26c057523643b4350 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 3 Jan 2022 11:36:57 +0100 Subject: [PATCH] Fix HRG-15 serial reception --- FIRMWARE.md | 2 +- README.md | 2 +- tasmota/xsns_90_hrg15.ino | 51 +++++++++++++++++++++++---------------- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/FIRMWARE.md b/FIRMWARE.md index 610cc6fba..7373dd131 100644 --- a/FIRMWARE.md +++ b/FIRMWARE.md @@ -18,7 +18,7 @@ See [CHANGELOG.md](https://github.com/arendst/Tasmota/blob/development/tasmota/C ## Development -[![Dev Version](https://img.shields.io/badge/development%20version-v10.1.x.x-blue.svg)](https://github.com/arendst/Tasmota) +[![Dev Version](https://img.shields.io/badge/development%20version-v2022.01.x-blue.svg)](https://github.com/arendst/Tasmota) [![Download Dev](https://img.shields.io/badge/download-development-yellow.svg)](http://ota.tasmota.com/tasmota/) [![Tasmota CI](https://github.com/arendst/Tasmota/workflows/Tasmota%20CI/badge.svg)](https://github.com/arendst/Tasmota/actions?query=workflow%3A%22Tasmota+CI%22) [![Tasmota ESP32 CI](https://github.com/arendst/Tasmota/workflows/Tasmota%20ESP32%20CI/badge.svg)](https://github.com/arendst/Tasmota/actions?query=workflow%3A%22Tasmota+ESP32+CI%22) diff --git a/README.md b/README.md index b41539308..a8b23fbec 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Easy initial installation of Tasmota can be performed using the [Tasmota WebInst ## Development -[![Dev Version](https://img.shields.io/badge/development%20version-v10.1.x.x-blue.svg)](https://github.com/arendst/Tasmota) +[![Dev Version](https://img.shields.io/badge/development%20version-v2022.01.x-blue.svg)](https://github.com/arendst/Tasmota) [![Download Dev](https://img.shields.io/badge/download-development-yellow.svg)](http://ota.tasmota.com/tasmota/) [![Tasmota CI](https://github.com/arendst/Tasmota/workflows/Tasmota%20CI/badge.svg)](https://github.com/arendst/Tasmota/actions?query=workflow%3A%22Tasmota+CI%22) [![Tasmota ESP32 CI](https://github.com/arendst/Tasmota/workflows/Tasmota%20ESP32%20CI/badge.svg)](https://github.com/arendst/Tasmota/actions?query=workflow%3A%22Tasmota+ESP32+CI%22) diff --git a/tasmota/xsns_90_hrg15.ino b/tasmota/xsns_90_hrg15.ino index 104ee5b02..1ab96e67c 100644 --- a/tasmota/xsns_90_hrg15.ino +++ b/tasmota/xsns_90_hrg15.ino @@ -99,7 +99,7 @@ float Rg15Parse(char* buffer, const char* item) { return 0.0f; } -void Rg15Process(char* buffer) { +bool Rg15Process(char* buffer) { // Process payloads like: // Acc 0.01 mm, EventAcc 2.07 mm, TotalAcc 54.85 mm, RInt 2.89 mmph // Acc 0.001 in, EventAcc 0.002 in, TotalAcc 0.003 in, RInt 0.004 iph @@ -113,7 +113,9 @@ void Rg15Process(char* buffer) { if (Rg15.acc > 0.0f) { Rg15.time = RG15_EVENT_TIMEOUT; // We have some data, so the rain event is on-going } + return true; } + return false; } /*********************************************************************************************/ @@ -133,6 +135,33 @@ void Rg15Init(void) { } void Rg15Poll(void) { + bool publish = false; + + if (!HydreonSerial->available()) { + // Check if the rain event has timed out, reset rate to 0 + if (Rg15.time) { + Rg15.time--; + if (!Rg15.time) { + Rg15.acc = 0; + Rg15.rate = 0; + publish = true; + } + } + } else { + // Now read what's available + char rg15_buffer[RG15_BUFFER_SIZE]; + while (HydreonSerial->available()) { + Rg15ReadLine(rg15_buffer); + if (Rg15Process(rg15_buffer)) { // Do NOT use "publish = Rg15Process(rg15_buffer)" + publish = true; + } + } + } + + if (publish && !TasmotaGlobal.global_state.mqtt_down) { + MqttPublishSensor(); + } + if (Rg15.init_step) { Rg15.init_step--; if (1 == Rg15.init_step) { @@ -149,26 +178,6 @@ void Rg15Poll(void) { HydreonSerial->println('R'); // Read available data once } } - - if (!HydreonSerial->available()) { - // Check if the rain event has timed out, reset rate to 0 - if (Rg15.time) { - Rg15.time--; - if (!Rg15.time) { - Rg15.acc = 0; - Rg15.rate = 0; - MqttPublishSensor(); - } - } - } else { - // Now read what's available - char rg15_buffer[RG15_BUFFER_SIZE]; - while (HydreonSerial->available()) { - Rg15ReadLine(rg15_buffer); - Rg15Process(rg15_buffer); - } - if (!TasmotaGlobal.global_state.mqtt_down) { MqttPublishSensor(); } - } } void Rg15Show(bool json) {