Skip to content

Commit

Permalink
Added more photos to readme. Program will now exit on startup if user…
Browse files Browse the repository at this point in the history
… did not set a PagerDuty integration key.
  • Loading branch information
Aldaviva committed Sep 23, 2023
1 parent 6f35da9 commit cee748e
Show file tree
Hide file tree
Showing 22 changed files with 2,558 additions and 2,446 deletions.
Binary file added .github/images/cabinet-panel-puller.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/control-panel-open.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/control-panel-puller.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/light-current-sensor.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/lint-trap-screws.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/motor-current-sensor.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/pi-closeup.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/images/pi-installed.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,515 changes: 767 additions & 748 deletions Circuit/Current sensor schematics.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Circuit/Current sensor.fzz
Binary file not shown.
Binary file added Circuit/Current sensor.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,234 changes: 1,647 additions & 1,587 deletions Circuit/Current sensor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion DryerDuty/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class Configuration {

public string pagerDutyIntegrationKey { get; set; } = null!;
public string? pagerDutyIntegrationKey { get; set; }
public double motorMinimumActiveAmps { get; set; }
public double lightMinimumActiveAmps { get; set; }
public double motorGain { get; set; } = 1.0;
Expand Down
6 changes: 3 additions & 3 deletions DryerDuty/DryerDuty.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ServerGarbageCollection>true</ServerGarbageCollection>
<NoWarn>CS8524</NoWarn>

<Version>0.0.0</Version>
<Version>0.0.1</Version>
<Copyright>© 2023 Ben Hutchison</Copyright>
<Authors>Ben Hutchison</Authors>
<Company>$(Authors)</Company>
Expand All @@ -24,7 +24,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Iot.Device.Bindings" Version="2.2.0" />
<PackageReference Include="Iot.Device.Bindings" Version="3.0.0" />
<PackageReference Include="PagerDuty" Version="0.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="7.0.0" />
</ItemGroup>
Expand All @@ -34,7 +34,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Tests" />
</ItemGroup>
Expand Down
11 changes: 5 additions & 6 deletions DryerDuty/DryerMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace DryerDuty;

public class DryerMonitor: IHostedService, IDisposable {

internal const int SAMPLES_PER_WINDOW = 120; // 120Hz, Nyquist limit for 60Hz AC sine wave
internal const int SAMPLES_PER_WINDOW = 2 * 60; // 120Hz is the Nyquist limit for 60Hz AC sine wave
private const int MOTOR_CHANNEL = 0;
private const int LIGHT_CHANNEL = 1;
private const int MAX_ADC_READING = (2 << 9) - 1;
private const int MAX_ADC_READING = 1023; // 10-bit unsigned int
private const double REFERENCE_VOLTS = 3.3;
private const double MAX_CURRENT_TRANSFORMER_OUTPUT_VOLTS = 1;

Expand All @@ -36,12 +36,12 @@ public class DryerMonitor: IHostedService, IDisposable {
this.logger = logger;
this.pagerDutyManager = pagerDutyManager;
this.config = config;
this.adc = adc;

for (int i = 0; i < samplesByChannel.Length; i++) {
samplesByChannel[i] = new int[SAMPLES_PER_WINDOW];
}

this.adc = adc;
aggregatingTimer = new Timer(samplingWindow) { AutoReset = true };
samplingTimer = new Timer(samplingWindow.Divide(SAMPLES_PER_WINDOW)) { AutoReset = true };

Expand All @@ -60,7 +60,6 @@ public class DryerMonitor: IHostedService, IDisposable {
}

aggregatingTimer.Start();
logger.LogInformation("Timers started");
}

public Task StopAsync(CancellationToken cancellationToken) {
Expand Down Expand Up @@ -95,11 +94,11 @@ public class DryerMonitor: IHostedService, IDisposable {
_ => state ?? LaundryMachineState.IDLE
};

logger.LogTrace("Dryer is {state}, using {motorAmps:N3} amps for the motor and {lightAmps:N3} amps for the light", newState, motorAmps, lightAmps);

bool stateChanged = state != null && state != newState;
state = newState;

logger.Log(stateChanged ? LogLevel.Debug : LogLevel.Trace, "Dryer is {state}, using {motorAmps:N3} amps for the motor and {lightAmps:N3} amps for the light", newState, motorAmps, lightAmps);

if (stateChanged) {
await onStateChange(newState);
}
Expand Down
1 change: 0 additions & 1 deletion DryerDuty/PagerDutyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class PagerDutyManagerImpl: PagerDutyManager {
public async Task createChange() {
try {
await pagerDuty.Send(new Change("The dryer is starting a load of laundry."));
logger.LogDebug("Created Change event in PagerDuty");
} catch (PagerDutyException e) {
logger.LogWarning(e, "Failed to create Change event in PagerDuty");
}
Expand Down
11 changes: 10 additions & 1 deletion DryerDuty/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@
services.AddHostedService<DryerMonitor>();
services.AddSingleton<PagerDutyManager, PagerDutyManagerImpl>();
services.AddSingleton(_ => context.Configuration.Get<Configuration>()!);
services.AddSingleton<IPagerDuty>(s => new PagerDuty(s.GetRequiredService<Configuration>().pagerDutyIntegrationKey));
services.AddSingleton<IPagerDuty>(s => {
string? integrationKey = s.GetRequiredService<Configuration>().pagerDutyIntegrationKey;
if (integrationKey == null || integrationKey.Contains("Add a PagerDuty Events API v2 Integration to your Service and paste its Integration Key here")) {
s.GetRequiredService<ILogger<Program>>().LogError("During DryerDuty startup, pagerDutyIntegrationKey was found to be missing or misconfigured in appsettings.json. " +
"Program is exiting. See https://github.com/Aldaviva/DryerDuty#configuration for instructions.");
throw new ArgumentException("Missing pagerDutyIntegrationKey in appsettings.json");
}
return new PagerDuty(integrationKey);
});
})
.Build();

Expand Down
2 changes: 1 addition & 1 deletion DryerDuty/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"pagerDutyIntegrationKey": "<Add a PagerDuty Events API v2 Integration to your Service and paste its Integration Key here>",
"pagerDutyIntegrationKey": "Add a PagerDuty Events API v2 Integration to your Service and paste its Integration Key here",
"motorMinimumActiveAmps": 2.0,
"lightMinimumActiveAmps": 0.04,
"motorGain": 1.64,
Expand Down
90 changes: 32 additions & 58 deletions DryerDuty/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
"net7.0": {
"Iot.Device.Bindings": {
"type": "Direct",
"requested": "[2.2.0, )",
"resolved": "2.2.0",
"contentHash": "H0LNTHt/eO/zeze8oK+g8r04VUJ4dQ7U5JG4YtYTQAiPkVX2DkQy6DWtWECAXqKzYe0QlM6m2kCBmnblHBlVlQ==",
"dependencies": {
"Microsoft.Extensions.Logging.Abstractions": "5.0.0",
"SixLabors.ImageSharp": "1.0.2",
"System.Device.Gpio": "2.2.0",
"System.Drawing.Common": "5.0.3",
"requested": "[3.0.0, )",
"resolved": "3.0.0",
"contentHash": "mx3wNLZizgz+V5+P5TdAz37KHajKnWdwgtiKZ8SJvDrfsZWMb/1antzWx6z4vm9uAhUKXHhG6LuPfbnpcj65FQ==",
"dependencies": {
"Microsoft.Extensions.Logging.Abstractions": "7.0.0",
"System.Device.Gpio": "3.0.0",
"System.Drawing.Common": "6.0.0",
"System.IO.Ports": "5.0.1",
"System.Management": "5.0.0",
"System.Text.Json": "6.0.1",
"UnitsNet": "4.77.0"
"UnitsNet": "5.1.0"
}
},
"Microsoft.Extensions.Hosting.Systemd": {
Expand Down Expand Up @@ -309,11 +308,8 @@
},
"Microsoft.Win32.SystemEvents": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "Bh6blKG8VAKvXiLe2L+sEsn62nc1Ij34MrNxepD2OCrS5cpCwQa9MeLyhVQPQ/R4Wlzwuy6wMK8hLb11QPDRsQ==",
"dependencies": {
"Microsoft.NETCore.Platforms": "5.0.0"
}
"resolved": "6.0.0",
"contentHash": "hqTM5628jSsQiv+HGpiq3WKBl2c8v1KZfby2J6Pr7pEPlK9waPdgEO6b8A/+/xn/yZ9ulv8HuqK71ONy2tg67A=="
},
"Newtonsoft.Json": {
"type": "Transitive",
Expand Down Expand Up @@ -351,20 +347,15 @@
"resolved": "5.0.0",
"contentHash": "KOWNOPDzXNZkKHwfCs9gBzJS1JeOli7fBmI93l92FcTb/42Fc0ojKYL9gUZANYtM7x5nRPPzUJtW29klkt+2Zw=="
},
"SixLabors.ImageSharp": {
"type": "Transitive",
"resolved": "1.0.2",
"contentHash": "iZJ37Iss3pUkFl961x1aka85QuvgY9oNZabHijzVnHs4QTz6EMNx3zjJDyvK/0+Ryj6JPv/PC7GVIJXLHtu2nQ=="
},
"System.CodeDom": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "JPJArwA1kdj8qDAkY2XGjSWoYnqiM7q/3yRNkt6n28Mnn95MuEGkZXUbPBf7qc3IjwrGY5ttQon7yqHZyQJmOQ=="
},
"System.Device.Gpio": {
"type": "Transitive",
"resolved": "2.2.0",
"contentHash": "ShuBDkL/QlQvaeUXcTvtY8xnb0U/ueisVw3VcIgybmrHAl4BiQ/oZEi8yQFzb/xlzDc12AZ/J1oUE9AawV7Yag=="
"resolved": "3.0.0",
"contentHash": "tU+rRrRlAiFj7PKcrr1hjw9QSxBZ2B0w8Pse05nUi0M85p8kSkAJdJExqjd06iW4K15dNjLkR/RO1NMalCRq+Q=="
},
"System.Diagnostics.EventLog": {
"type": "Transitive",
Expand All @@ -373,10 +364,10 @@
},
"System.Drawing.Common": {
"type": "Transitive",
"resolved": "5.0.3",
"contentHash": "rEQZuslijqdsO0pkJn7LtGBaMc//YVA8de0meGihkg9oLPaN+w+/Pb5d71lgp0YjPoKgBKNMvdq0IPnoW4PEng==",
"resolved": "6.0.0",
"contentHash": "NfuoKUiP2nUWwKZN6twGqXioIe1zVD0RIj2t976A+czLHr2nY454RwwXs6JU9Htc6mwqL6Dn/nEL3dpVf2jOhg==",
"dependencies": {
"Microsoft.Win32.SystemEvents": "5.0.0"
"Microsoft.Win32.SystemEvents": "6.0.0"
}
},
"System.IO.Ports": {
Expand Down Expand Up @@ -425,18 +416,10 @@
"System.Text.Encodings.Web": "7.0.0"
}
},
"System.ValueTuple": {
"type": "Transitive",
"resolved": "4.5.0",
"contentHash": "okurQJO6NRE/apDIP23ajJ0hpiNmJ+f0BwOlB/cSqTLQlw5upkf+5+96+iG2Jw40G1fCVCyPz/FhIABUjMR+RQ=="
},
"UnitsNet": {
"type": "Transitive",
"resolved": "4.77.0",
"contentHash": "S4rErosYZ+M7N2f76mx3DEZL/biGaUr1SJKfT8lTj7swFpyElcTcJG93rb2jTxzTKrSBDMFpLlYjpbCPEK/gfw==",
"dependencies": {
"System.ValueTuple": "4.5.0"
}
"resolved": "5.1.0",
"contentHash": "LnhJ56+zBPrauImZj9zQO/orqW5SbtrLSZ/u3VZqaVd5LE76iZpqdhUnMI1mQ2PyduKeUHOLFSQQA7LP7Vhx3g=="
}
},
"net7.0/linux-arm": {
Expand All @@ -451,11 +434,8 @@
},
"Microsoft.Win32.SystemEvents": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "Bh6blKG8VAKvXiLe2L+sEsn62nc1Ij34MrNxepD2OCrS5cpCwQa9MeLyhVQPQ/R4Wlzwuy6wMK8hLb11QPDRsQ==",
"dependencies": {
"Microsoft.NETCore.Platforms": "5.0.0"
}
"resolved": "6.0.0",
"contentHash": "hqTM5628jSsQiv+HGpiq3WKBl2c8v1KZfby2J6Pr7pEPlK9waPdgEO6b8A/+/xn/yZ9ulv8HuqK71ONy2tg67A=="
},
"runtime.linux-arm.runtime.native.System.IO.Ports": {
"type": "Transitive",
Expand Down Expand Up @@ -484,10 +464,10 @@
},
"System.Drawing.Common": {
"type": "Transitive",
"resolved": "5.0.3",
"contentHash": "rEQZuslijqdsO0pkJn7LtGBaMc//YVA8de0meGihkg9oLPaN+w+/Pb5d71lgp0YjPoKgBKNMvdq0IPnoW4PEng==",
"resolved": "6.0.0",
"contentHash": "NfuoKUiP2nUWwKZN6twGqXioIe1zVD0RIj2t976A+czLHr2nY454RwwXs6JU9Htc6mwqL6Dn/nEL3dpVf2jOhg==",
"dependencies": {
"Microsoft.Win32.SystemEvents": "5.0.0"
"Microsoft.Win32.SystemEvents": "6.0.0"
}
},
"System.IO.Ports": {
Expand Down Expand Up @@ -541,11 +521,8 @@
},
"Microsoft.Win32.SystemEvents": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "Bh6blKG8VAKvXiLe2L+sEsn62nc1Ij34MrNxepD2OCrS5cpCwQa9MeLyhVQPQ/R4Wlzwuy6wMK8hLb11QPDRsQ==",
"dependencies": {
"Microsoft.NETCore.Platforms": "5.0.0"
}
"resolved": "6.0.0",
"contentHash": "hqTM5628jSsQiv+HGpiq3WKBl2c8v1KZfby2J6Pr7pEPlK9waPdgEO6b8A/+/xn/yZ9ulv8HuqK71ONy2tg67A=="
},
"runtime.linux-arm.runtime.native.System.IO.Ports": {
"type": "Transitive",
Expand Down Expand Up @@ -574,10 +551,10 @@
},
"System.Drawing.Common": {
"type": "Transitive",
"resolved": "5.0.3",
"contentHash": "rEQZuslijqdsO0pkJn7LtGBaMc//YVA8de0meGihkg9oLPaN+w+/Pb5d71lgp0YjPoKgBKNMvdq0IPnoW4PEng==",
"resolved": "6.0.0",
"contentHash": "NfuoKUiP2nUWwKZN6twGqXioIe1zVD0RIj2t976A+czLHr2nY454RwwXs6JU9Htc6mwqL6Dn/nEL3dpVf2jOhg==",
"dependencies": {
"Microsoft.Win32.SystemEvents": "5.0.0"
"Microsoft.Win32.SystemEvents": "6.0.0"
}
},
"System.IO.Ports": {
Expand Down Expand Up @@ -631,11 +608,8 @@
},
"Microsoft.Win32.SystemEvents": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "Bh6blKG8VAKvXiLe2L+sEsn62nc1Ij34MrNxepD2OCrS5cpCwQa9MeLyhVQPQ/R4Wlzwuy6wMK8hLb11QPDRsQ==",
"dependencies": {
"Microsoft.NETCore.Platforms": "5.0.0"
}
"resolved": "6.0.0",
"contentHash": "hqTM5628jSsQiv+HGpiq3WKBl2c8v1KZfby2J6Pr7pEPlK9waPdgEO6b8A/+/xn/yZ9ulv8HuqK71ONy2tg67A=="
},
"runtime.linux-arm.runtime.native.System.IO.Ports": {
"type": "Transitive",
Expand Down Expand Up @@ -664,10 +638,10 @@
},
"System.Drawing.Common": {
"type": "Transitive",
"resolved": "5.0.3",
"contentHash": "rEQZuslijqdsO0pkJn7LtGBaMc//YVA8de0meGihkg9oLPaN+w+/Pb5d71lgp0YjPoKgBKNMvdq0IPnoW4PEng==",
"resolved": "6.0.0",
"contentHash": "NfuoKUiP2nUWwKZN6twGqXioIe1zVD0RIj2t976A+czLHr2nY454RwwXs6JU9Htc6mwqL6Dn/nEL3dpVf2jOhg==",
"dependencies": {
"Microsoft.Win32.SystemEvents": "5.0.0"
"Microsoft.Win32.SystemEvents": "6.0.0"
}
},
"System.IO.Ports": {
Expand Down
Loading

0 comments on commit cee748e

Please sign in to comment.