From 6c446ad6f663838a04a30f14bc0362a1a2ddcf90 Mon Sep 17 00:00:00 2001 From: Giacomo Castellani Date: Sat, 19 Oct 2024 14:23:39 +0200 Subject: [PATCH] Update NuGet packages and enhance sensor retry logic --- device_dotnet/Nerdostat.Device.csproj | 10 +++++----- device_dotnet/Services/Thermostat.cs | 10 +++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/device_dotnet/Nerdostat.Device.csproj b/device_dotnet/Nerdostat.Device.csproj index 95a0615..bfd83eb 100644 --- a/device_dotnet/Nerdostat.Device.csproj +++ b/device_dotnet/Nerdostat.Device.csproj @@ -6,11 +6,11 @@ - - - - - + + + + + diff --git a/device_dotnet/Services/Thermostat.cs b/device_dotnet/Services/Thermostat.cs index 398e002..fbe4a0c 100644 --- a/device_dotnet/Services/Thermostat.cs +++ b/device_dotnet/Services/Thermostat.cs @@ -149,7 +149,7 @@ private decimal GetCurrentSetpoint() bool humOk = false; Temperature temp; RelativeHumidity hum; - int wait = 2000; + int wait = 5000; int loop = 1; using (var controller = new GpioController()) @@ -167,15 +167,23 @@ private decimal GetCurrentSetpoint() while (!tempOk || !humOk) { log.LogWarning("Sensor read failed"); + if (wait < 4999) wait += 500; + await Task.Delay(wait, token).ConfigureAwait(false); if (!tempOk) + { + log.LogWarning("Retrying temperature read"); tempOk = sensor.TryReadTemperature(out temp); + } if (!humOk) + { + log.LogWarning("Retrying humidity read"); humOk = sensor.TryReadHumidity(out hum); + } humOk = humOk && hum.Percent >= 0 && hum.Percent <= 100; tempOk = tempOk && humOk;