Skip to content

Commit

Permalink
Update NuGet packages and enhance sensor retry logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gicastel committed Oct 19, 2024
1 parent 06042c8 commit 6c446ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 5 additions & 5 deletions device_dotnet/Nerdostat.Device.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Iot.Device.Bindings" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Devices.Client" Version="1.42.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Iot.Device.Bindings" Version="3.2.0" />
<PackageReference Include="Microsoft.Azure.Devices.Client" Version="1.42.3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 9 additions & 1 deletion device_dotnet/Services/Thermostat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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;
Expand Down

0 comments on commit 6c446ad

Please sign in to comment.