From dd272cfffc22e3bd87b71b28b507f498bba58ba1 Mon Sep 17 00:00:00 2001 From: marcel Date: Sun, 26 Jan 2025 15:15:01 +0100 Subject: [PATCH] Fixed bug rain meter and luminosity meter --- CHANGELOG.md | 16 ++++++++++++++++ TODO.md | 2 +- firmware/weather_station.ino | 11 +++++++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fec421d..55f3a62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -110,3 +110,19 @@ Support for si7021 humidity sensor (this sensor was not suited for outdoor measu - Debug messages can be switched on and off with the _DEBUG_ variable - SEN0562 luminosity sensor + +## [0.3.2] - 2025-01-26 + +### Fixed + +The first hour, the ModBus register SensorRainIreg is instable. This is because in setup(), the variable RainPerHourCounter is set to the current millis() value. The RainPerHourCounter is the index for the array RainPerHour, which can hold 24 values. But the index is set to the millis() value, which can have a value abouve 23. This causes a buffer overflow. After the first hour, the index is reset and from thereon the register SensorRainIreg holds the proper rainfall value. The solution is that the variable HourTimer should be set to the current millis() value in setup(). + +``` + -- ts = millis(); + -- RainPerHourCounter = ts; + + ++ ts = millis(); + ++ HourTimer = ts; +``` + +Buffer roll over luminosity sensor. This happened because the raw value was mutiplied by 100. But that was wrong: copied this section of the code from the temperature sensor code, which uses this mutiply by 100 to gain precision. diff --git a/TODO.md b/TODO.md index e166fcc..320eecf 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,6 @@ # Todo list for weather station with ModBus over RS-485 -## Bug in rain meter register +## Bug in rain meter register [done - 2024-01-26] The first hour, the ModBus register SensorRainIreg is instable. This is because in setup(), the variable RainPerHourCounter is set to the current millis() value. The RainPerHourCounter is the index for the array RainPerHour, which can hold 24 values. But the index is set to the millis() value, which can have a value abouve 23. This causes a buffer overflow. After the first hour, the index is reset and from thereon the register SensorRainIreg holds the proper rainfall value. The solution is that the variable HourTimer should be set to the current millis() value in setup(). diff --git a/firmware/weather_station.ino b/firmware/weather_station.ino index dd01f45..56ac5c6 100644 --- a/firmware/weather_station.ino +++ b/firmware/weather_station.ino @@ -42,6 +42,9 @@ * the circuitry and is therefore about 1.5 degrees above ambient temperature. The BMP280 does not heat up. * - Added SEN0562 luminosity sensor * + * 2025-01-26: - Bug rainmeter fixed + * - Bug luminosity sensor fixed + * * See CHANGELOG.md * **********************************************************************************/ @@ -241,11 +244,11 @@ void ReadSEN0562() ReadSEN0562_register(0x10, buf); //Register address 0x10 data = buf[0] << 8 | buf[1]; - MeasuredData.Luminosity = (((float)data )/1.2)*100; + MeasuredData.Luminosity = ((float)data )/1.2; if (_DEBUG_) { Serial.print("SEN0562 light intensity: "); - Serial.print(MeasuredData.Luminosity/100); + Serial.print(MeasuredData.Luminosity); Serial.println(" Lux"); } } @@ -439,7 +442,7 @@ void setup() { mb.Ireg (SensorRainSinceMidnightIreg, 0); mb.Ireg (SensorSnowFallIreg, 0); - Serial.println(F("Weather station v0.3.1")); + Serial.println(F("Weather station v0.3.2")); Serial.println(F("(C)2024-2025 M.T. Konstapel")); Serial.println(F("This project is free and open source")); Serial.println(F("More details: https://meezenest.nl/mees/")); @@ -534,7 +537,7 @@ void setup() { weatherMeterKit.begin(); ts = millis(); - RainPerHourCounter = ts; + HourTimer = ts; } void loop() {