Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 32b136d4cc | |||
| 8284ae9695 | |||
| c575f52ebb | |||
| 4d2ee85cbe | |||
| d6364fc975 | |||
| 7ff39ea252 | |||
| b61de80e8a | |||
| c53f6a3f77 | |||
| 7fe92790d7 | |||
| 3b9d5bc984 | |||
| a73f171102 | |||
| 157dc0e6cf | |||
| df6428550f | |||
| f1d4a7c1bc | |||
| 485453bc7d | |||
| 661fe4dfd6 | |||
| 0207899f1b |
94
.github/workflows/build.yml
vendored
94
.github/workflows/build.yml
vendored
@@ -3,7 +3,7 @@ name: Build and Deploy
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master # Change to your default branch if different
|
||||
- master
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
environment:
|
||||
@@ -28,7 +28,7 @@ on:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: self-hosted # Ensure your self-hosted runner is configured
|
||||
runs-on: self-hosted
|
||||
environment: ${{ github.event.inputs.environment || 'prod' }}
|
||||
steps:
|
||||
- name: Get Current User
|
||||
@@ -43,7 +43,7 @@ jobs:
|
||||
- name: Set up .NET
|
||||
uses: actions/setup-dotnet@v2
|
||||
with:
|
||||
dotnet-version: '9.0' # Change to your required .NET version
|
||||
dotnet-version: '9.0'
|
||||
|
||||
- name: Restore .NET Dependencies
|
||||
run: dotnet restore ./HomeApi.sln
|
||||
@@ -74,6 +74,24 @@ jobs:
|
||||
} else {
|
||||
Write-Host "ChromeHeadlessShell not found in published output"
|
||||
}
|
||||
|
||||
# Check wwwroot and manually copy if missing
|
||||
- name: Ensure wwwroot is Included
|
||||
run: |
|
||||
if (-not (Test-Path -Path "./output/dotnet/wwwroot")) {
|
||||
Write-Host "wwwroot folder not found in published output, manually copying..."
|
||||
|
||||
# Check if wwwroot exists in project directory
|
||||
$sourceWwwroot = "./HomeApi/wwwroot"
|
||||
|
||||
if (Test-Path -Path $sourceWwwroot) {
|
||||
Write-Host "Found wwwroot directory in source, copying..."
|
||||
New-Item -ItemType Directory -Path "./output/dotnet/wwwroot" -Force
|
||||
Copy-Item -Path "$sourceWwwroot/*" -Destination "./output/dotnet/wwwroot" -Recurse -Force
|
||||
} else {
|
||||
Write-Host "WARNING: Could not find wwwroot in source directory!"
|
||||
}
|
||||
}
|
||||
|
||||
- name: Generate SemVer version
|
||||
if: ${{ github.event.inputs.create_release != 'false' }}
|
||||
@@ -82,10 +100,11 @@ jobs:
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
branch: master
|
||||
patchAll: true # Always increment patch number
|
||||
patchAll: true
|
||||
|
||||
- name: Create GitHub Release
|
||||
if: ${{ github.event.inputs.create_release != 'false' }}
|
||||
id: create_release
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -94,21 +113,60 @@ jobs:
|
||||
release_name: Release ${{ steps.semver.outputs.next }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
|
||||
- name: Create placeholder appsettings for release
|
||||
if: ${{ github.event.inputs.create_release != 'false' }}
|
||||
run: |
|
||||
$appSettings = @{
|
||||
Logging = @{
|
||||
LogLevel = @{
|
||||
Default = "Information"
|
||||
"Microsoft.AspNetCore" = "Warning"
|
||||
}
|
||||
}
|
||||
ApiConfiguration = @{
|
||||
EspConfiguration = @{
|
||||
InformationBoardImageUrl = "http://server_ip:port/home/default.jpg"
|
||||
UpdateIntervalMinutes = [int]"${{ vars.ESP_UPDATE_INTERVAL }}"
|
||||
BlackTextThreshold = [int]"${{ vars.ESP_BLACK_TEXT_THRESHOLD }}"
|
||||
EnableDithering = [System.Convert]::ToBoolean("${{ vars.ESP_ENABLE_DITHERING }}")
|
||||
DitheringStrength = [int]"${{ vars.ESP_DITHERING_STRENGTH }}"
|
||||
EnhanceContrast = [System.Convert]::ToBoolean("${{ vars.ESP_ENHANCE_CONTRAST }}")
|
||||
ContrastStrength = [int]"${{ vars.ESP_CONTRAST_STRENGTH }}"
|
||||
IsHighContrastMode = [System.Convert]::ToBoolean("${{ vars.ESP_HIGH_CONTRAST_MODE }}")
|
||||
}
|
||||
Keys = @{
|
||||
Weather = "SET THIS TO YOUR KEY"
|
||||
ResRobot = "SET THIS TO YOUR KEY"
|
||||
}
|
||||
BaseUrls = @{
|
||||
Nominatim = "${{ vars.NOMINATIM_URL }}"
|
||||
Aurora = "${{ vars.AURORA_URL }}"
|
||||
Weather = "${{ vars.WEATHER_URL }}"
|
||||
ResRobot = "${{ vars.RES_ROBOT_URL }}"
|
||||
}
|
||||
DefaultCity = "CITY ADDRESS"
|
||||
DefaultStation = "YOUR STATION"
|
||||
}
|
||||
AllowedHosts = "*"
|
||||
}
|
||||
|
||||
$appSettings | ConvertTo-Json -Depth 10 | Set-Content -Path "./output/dotnet/appsettings.json"
|
||||
Write-Host "Created placeholder appsettings.json successfully"
|
||||
|
||||
- name: Zip the build for github release
|
||||
if: ${{ github.event.inputs.create_release != 'false' }}
|
||||
run: Compress-Archive -Path './output/*' -DestinationPath './out/HomeScreen_Build_${{ steps.semver.outputs.next }}.zip' -CompressionLevel Optimal -Force
|
||||
run: Compress-Archive -Path './output/*' -DestinationPath './output/HomeScreen_Build_${{ steps.semver.outputs.next }}.zip' -CompressionLevel Optimal -Force
|
||||
|
||||
- name: Upload Release Asset
|
||||
if: ${{ github.event.inputs.create_release != 'false' }}
|
||||
id: upload-release-asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./output/HomeScreen_Build_${{ steps.semver.outputs.next }}.zip
|
||||
asset_name: HomeScreen_Build_${{steps.semver.outputs.patch}}.zip
|
||||
asset_name: HomeScreen_Build_${{ steps.semver.outputs.next }}.zip
|
||||
asset_content_type: application/zip
|
||||
|
||||
- name: Generate appsettings.json
|
||||
@@ -150,24 +208,6 @@ jobs:
|
||||
$appSettings | ConvertTo-Json -Depth 10 | Set-Content -Path "./output/dotnet/appsettings.json"
|
||||
Write-Host "Generated appsettings.json successfully"
|
||||
|
||||
# Check wwwroot and manually copy if missing
|
||||
- name: Ensure wwwroot is Included
|
||||
run: |
|
||||
if (-not (Test-Path -Path "./output/dotnet/wwwroot")) {
|
||||
Write-Host "wwwroot folder not found in published output, manually copying..."
|
||||
|
||||
# Check if wwwroot exists in project directory
|
||||
$sourceWwwroot = "./HomeApi/wwwroot"
|
||||
|
||||
if (Test-Path -Path $sourceWwwroot) {
|
||||
Write-Host "Found wwwroot directory in source, copying..."
|
||||
New-Item -ItemType Directory -Path "./output/dotnet/wwwroot" -Force
|
||||
Copy-Item -Path "$sourceWwwroot/*" -Destination "./output/dotnet/wwwroot" -Recurse -Force
|
||||
} else {
|
||||
Write-Host "WARNING: Could not find wwwroot in source directory!"
|
||||
}
|
||||
}
|
||||
|
||||
- name: Upload Artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
@@ -175,7 +215,7 @@ jobs:
|
||||
path: ./output/dotnet
|
||||
|
||||
deploy:
|
||||
runs-on: self-hosted # Ensure your self-hosted runner is configured
|
||||
runs-on: self-hosted
|
||||
needs: build
|
||||
environment: ${{ github.event.inputs.environment || 'prod' }}
|
||||
|
||||
|
||||
@@ -215,6 +215,18 @@ int jpegDrawCallback(JPEGDRAW *pDraw) {
|
||||
return 1; // Continue decoding
|
||||
}
|
||||
|
||||
void clearDisplay() {
|
||||
// Clear both layers of the display
|
||||
Paint_SelectImage(BlackImage);
|
||||
Paint_Clear(WHITE);
|
||||
Paint_SelectImage(RYImage);
|
||||
Paint_Clear(WHITE);
|
||||
|
||||
// Send clear command to the display
|
||||
EPD_7IN5B_V2_Display(BlackImage, RYImage);
|
||||
Serial.println("Display cleared.");
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("E-Ink Display Initialization");
|
||||
@@ -513,27 +525,36 @@ void fetchAndDisplayImage() {
|
||||
Serial.println("Image displayed successfully.");
|
||||
} else {
|
||||
Serial.println("Failed to open JPEG image");
|
||||
clearDisplay();
|
||||
}
|
||||
} else {
|
||||
Serial.println("Failed to read entire image.");
|
||||
clearDisplay();
|
||||
}
|
||||
free(buffer);
|
||||
} else {
|
||||
Serial.println("Failed to allocate buffer!");
|
||||
clearDisplay();
|
||||
}
|
||||
} else {
|
||||
Serial.println("Content length unknown or invalid.");
|
||||
clearDisplay();
|
||||
}
|
||||
} else if (httpCode == HTTPC_ERROR_CONNECTION_REFUSED) {
|
||||
Serial.println("Connection refused - server may be down");
|
||||
clearDisplay();
|
||||
} else if (httpCode == HTTPC_ERROR_CONNECTION_LOST) {
|
||||
Serial.println("Connection lost during request");
|
||||
clearDisplay();
|
||||
} else if (httpCode == HTTPC_ERROR_NO_HTTP_SERVER) {
|
||||
Serial.println("No HTTP server found");
|
||||
clearDisplay();
|
||||
} else if (httpCode == HTTPC_ERROR_NOT_CONNECTED) {
|
||||
Serial.println("Not connected to server");
|
||||
clearDisplay();
|
||||
} else {
|
||||
Serial.printf("HTTP GET failed, error: %d\n", httpCode);
|
||||
clearDisplay();
|
||||
}
|
||||
|
||||
http.end();
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -18,10 +18,10 @@ public static class ContractExtensions
|
||||
/// A <see cref="WeatherInformation"/> object populated with current weather, aurora probability, and forecast information.
|
||||
/// </returns>
|
||||
public static WeatherInformation ToContract(
|
||||
this WeatherData weather,
|
||||
string locationName,
|
||||
this WeatherData? weather,
|
||||
string? locationName,
|
||||
AuroraForecastApiResponse? auroraForecast,
|
||||
List<Models.Forecast> forecasts)
|
||||
List<Models.Forecast>? forecasts)
|
||||
{
|
||||
return new WeatherInformation
|
||||
{
|
||||
@@ -58,23 +58,23 @@ public static class ContractExtensions
|
||||
},
|
||||
AuroraProbability = new Probability
|
||||
{
|
||||
Date = auroraForecast.Date,
|
||||
Date = auroraForecast?.Date ?? DateTime.Now,
|
||||
Calculated = new CalculatedProbability
|
||||
{
|
||||
Value = auroraForecast.Probability.Calculated.Value,
|
||||
Colour = auroraForecast.Probability.Calculated.Colour,
|
||||
Lat = auroraForecast.Probability.Calculated.Lat,
|
||||
Long = auroraForecast.Probability.Calculated.Long
|
||||
Value = auroraForecast?.Probability.Calculated.Value ?? 0,
|
||||
Colour = auroraForecast?.Probability.Calculated.Colour ?? string.Empty,
|
||||
Lat = auroraForecast?.Probability.Calculated.Lat ?? 0,
|
||||
Long = auroraForecast?.Probability.Calculated.Long ?? 0
|
||||
},
|
||||
Colour = auroraForecast.Probability.Colour,
|
||||
Value = auroraForecast.Probability.Value,
|
||||
Colour = auroraForecast?.Probability.Colour ?? string.Empty,
|
||||
Value = auroraForecast?.Probability.Value.ToString() ?? "No data",
|
||||
HighestProbability = new Highest
|
||||
{
|
||||
Colour = auroraForecast.Probability.Highest.Colour,
|
||||
Lat = auroraForecast.Probability.Highest.Lat,
|
||||
Long = auroraForecast.Probability.Highest.Long,
|
||||
Value = auroraForecast.Probability.Highest.Value,
|
||||
Date = auroraForecast.Probability.Highest.Date
|
||||
Colour = auroraForecast?.Probability.Highest.Colour ?? string.Empty,
|
||||
Lat = auroraForecast?.Probability.Highest.Lat ?? 0,
|
||||
Long = auroraForecast?.Probability.Highest.Long ?? 0,
|
||||
Value = auroraForecast?.Probability.Highest.Value ?? 0,
|
||||
Date = auroraForecast?.Probability.Highest.Date ?? DateTime.Now
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
22
HomeApi/Extensions/MediatorExtensions.cs
Normal file
22
HomeApi/Extensions/MediatorExtensions.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using MediatR;
|
||||
|
||||
namespace HomeApi.Extensions;
|
||||
|
||||
public static class MediatorExtensions
|
||||
{
|
||||
public static async Task<T?> TrySendAsync<T>(
|
||||
this IMediator mediator,
|
||||
IRequest<T> request,
|
||||
CancellationToken cancellationToken) where T : class
|
||||
{
|
||||
try
|
||||
{
|
||||
return await mediator.Send(request, cancellationToken);
|
||||
}
|
||||
catch (OperationCanceledException) { throw; }
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
23
HomeApi/Extensions/ServiceCallExtensions.cs
Normal file
23
HomeApi/Extensions/ServiceCallExtensions.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace HomeApi.Extensions;
|
||||
|
||||
public static class ServiceCallExtensions
|
||||
{
|
||||
public static async Task<TResult?> TryCallAsync<TService, TResult>(
|
||||
this TService service,
|
||||
Func<TService, Task<TResult>> action,
|
||||
ILogger logger,
|
||||
string errorMessage)
|
||||
where TResult : class?
|
||||
{
|
||||
try
|
||||
{
|
||||
return await action(service);
|
||||
}
|
||||
catch (OperationCanceledException) { throw; }
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, errorMessage);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Dynamic;
|
||||
using System.Reflection;
|
||||
using HomeApi.Extensions;
|
||||
using HomeApi.Models.Configuration;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Options;
|
||||
@@ -22,8 +23,8 @@ public static class ImageGeneration
|
||||
|
||||
public async Task<Stream> Handle(Command request, CancellationToken cancellationToken)
|
||||
{
|
||||
var weather = await mediator.Send(new Weather.Command(), cancellationToken);
|
||||
var departureBoard = await mediator.Send(new DepartureBoard.Command(), cancellationToken);
|
||||
var weather = await mediator.TrySendAsync(new Weather.Command(), cancellationToken);
|
||||
var departureBoard = await mediator.TrySendAsync(new DepartureBoard.Command(), cancellationToken);
|
||||
|
||||
var model = new Models.Image
|
||||
{
|
||||
@@ -31,8 +32,6 @@ public static class ImageGeneration
|
||||
TimeTable = departureBoard
|
||||
};
|
||||
|
||||
if(weather is null)
|
||||
throw new Exception("Weather data not found");
|
||||
|
||||
var engine = new RazorLightEngineBuilder()
|
||||
.SetOperatingAssembly(Assembly.GetExecutingAssembly())
|
||||
@@ -59,7 +58,7 @@ public static class ImageGeneration
|
||||
{
|
||||
var browserFetcher = new BrowserFetcher();
|
||||
await browserFetcher.DownloadAsync();
|
||||
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
|
||||
await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions
|
||||
{
|
||||
Headless = true,
|
||||
Args = ["--disable-gpu"]
|
||||
|
||||
@@ -35,16 +35,27 @@ public static class Weather
|
||||
|
||||
public async Task<WeatherInformation> Handle(Command request, CancellationToken cancellationToken)
|
||||
{
|
||||
var coordinates = await _geocodingService.GetCoordinatesAsync(_apiConfiguration.DefaultCity);
|
||||
if (coordinates is null)
|
||||
throw new Exception("Coordinates not found");
|
||||
var coordinates = await _geocodingService.TryCallAsync(service =>
|
||||
service.GetCoordinatesAsync(_apiConfiguration.DefaultCity),
|
||||
_logger,
|
||||
"Failed to get coordinates"
|
||||
);
|
||||
|
||||
var aurora = await _auroraService.TryCallAsync(service =>
|
||||
service.GetAuroraForecastAsync(coordinates?.Lat ?? "0.00", coordinates?.Lon ?? "0.00"),
|
||||
_logger,
|
||||
"Failed to get aurora forecast"
|
||||
);
|
||||
|
||||
var weather = await _weatherService.TryCallAsync(service =>
|
||||
service.GetWeatherAsync(coordinates?.Lat ?? string.Empty, coordinates?.Lon ?? string.Empty),
|
||||
_logger,
|
||||
"Failed to get weather data"
|
||||
);
|
||||
|
||||
var aurora = await _auroraService.GetAuroraForecastAsync(coordinates.Lat, coordinates.Lon);
|
||||
var weather = await _weatherService.GetWeatherAsync(coordinates.Lat, coordinates.Lon);
|
||||
var forecasts = weather?.Forecast.Forecastday.Select(day => day.ToForecast()).ToList();
|
||||
|
||||
var forecasts = weather.Forecast.Forecastday.Select(day => day.ToForecast()).ToList();
|
||||
|
||||
return weather.ToContract(coordinates.Name, aurora, forecasts);
|
||||
return weather?.ToContract(coordinates?.Name, aurora, forecasts) ?? new WeatherInformation();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,15 @@ public class WeatherService(IWeatherClient weatherApi, IOptions<ApiConfiguration
|
||||
{
|
||||
private readonly ApiConfiguration _apiConfig = options.Value;
|
||||
|
||||
public Task<WeatherData> GetWeatherAsync(string lat, string lon)
|
||||
public Task<WeatherData> GetWeatherAsync(string? lat, string? lon)
|
||||
{
|
||||
var location = $"{lat},{lon}";
|
||||
|
||||
if (string.IsNullOrEmpty(lat) || string.IsNullOrEmpty(lon))
|
||||
{
|
||||
location = _apiConfig.DefaultCity;
|
||||
}
|
||||
|
||||
return weatherApi.GetForecastAsync(_apiConfig.Keys.Weather, location);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,6 @@ namespace HomeApi.Models;
|
||||
|
||||
public class Image
|
||||
{
|
||||
public WeatherInformation Weather { get; set; }
|
||||
public List<TimeTable> TimeTable { get; set; }
|
||||
public WeatherInformation? Weather { get; set; }
|
||||
public List<TimeTable>? TimeTable { get; set; }
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
namespace HomeApi.Models.Response;
|
||||
|
||||
public class TrafikLabsApiResponse
|
||||
{
|
||||
public List<Departure> Departure { get; set; }
|
||||
|
||||
153
HomeApi/Models/Response/YrWeatherForecastResponse.cs
Normal file
153
HomeApi/Models/Response/YrWeatherForecastResponse.cs
Normal file
@@ -0,0 +1,153 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace HomeApi.Models.Response;
|
||||
|
||||
public class Data
|
||||
{
|
||||
[JsonPropertyName("instant")]
|
||||
public Instant Instant { get; set; }
|
||||
|
||||
[JsonPropertyName("next_12_hours")]
|
||||
public Next12Hours Next12Hours { get; set; }
|
||||
|
||||
[JsonPropertyName("next_1_hours")]
|
||||
public Next1Hours Next1Hours { get; set; }
|
||||
|
||||
[JsonPropertyName("next_6_hours")]
|
||||
public Next6Hours Next6Hours { get; set; }
|
||||
}
|
||||
|
||||
public class Details
|
||||
{
|
||||
[JsonPropertyName("air_pressure_at_sea_level")]
|
||||
public double AirPressureAtSeaLevel { get; set; }
|
||||
|
||||
[JsonPropertyName("air_temperature")]
|
||||
public double AirTemperature { get; set; }
|
||||
|
||||
[JsonPropertyName("cloud_area_fraction")]
|
||||
public double CloudAreaFraction { get; set; }
|
||||
|
||||
[JsonPropertyName("relative_humidity")]
|
||||
public double RelativeHumidity { get; set; }
|
||||
|
||||
[JsonPropertyName("wind_from_direction")]
|
||||
public double WindFromDirection { get; set; }
|
||||
|
||||
[JsonPropertyName("wind_speed")]
|
||||
public double WindSpeed { get; set; }
|
||||
|
||||
[JsonPropertyName("precipitation_amount")]
|
||||
public double PrecipitationAmount { get; set; }
|
||||
}
|
||||
|
||||
public class Geometry
|
||||
{
|
||||
[JsonPropertyName("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
[JsonPropertyName("coordinates")]
|
||||
public List<double> Coordinates { get; set; }
|
||||
}
|
||||
|
||||
public class Instant
|
||||
{
|
||||
[JsonPropertyName("details")]
|
||||
public Details Details { get; set; }
|
||||
}
|
||||
|
||||
public class Meta
|
||||
{
|
||||
[JsonPropertyName("updated_at")]
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
|
||||
[JsonPropertyName("units")]
|
||||
public Units Units { get; set; }
|
||||
}
|
||||
|
||||
public class Next12Hours
|
||||
{
|
||||
[JsonPropertyName("summary")]
|
||||
public Summary Summary { get; set; }
|
||||
|
||||
[JsonPropertyName("details")]
|
||||
public Details Details { get; set; }
|
||||
}
|
||||
|
||||
public class Next1Hours
|
||||
{
|
||||
[JsonPropertyName("summary")]
|
||||
public Summary Summary { get; set; }
|
||||
|
||||
[JsonPropertyName("details")]
|
||||
public Details Details { get; set; }
|
||||
}
|
||||
|
||||
public class Next6Hours
|
||||
{
|
||||
[JsonPropertyName("summary")]
|
||||
public Summary Summary { get; set; }
|
||||
|
||||
[JsonPropertyName("details")]
|
||||
public Details Details { get; set; }
|
||||
}
|
||||
|
||||
public class Properties
|
||||
{
|
||||
[JsonPropertyName("meta")]
|
||||
public Meta Meta { get; set; }
|
||||
|
||||
[JsonPropertyName("timeseries")]
|
||||
public List<Timeseries> Timeseries { get; set; }
|
||||
}
|
||||
|
||||
public class YrWeatherForecastResponse
|
||||
{
|
||||
[JsonPropertyName("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
[JsonPropertyName("geometry")]
|
||||
public Geometry Geometry { get; set; }
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public Properties Properties { get; set; }
|
||||
}
|
||||
|
||||
public class Summary
|
||||
{
|
||||
[JsonPropertyName("symbol_code")]
|
||||
public string SymbolCode { get; set; }
|
||||
}
|
||||
|
||||
public class Timeseries
|
||||
{
|
||||
[JsonPropertyName("time")]
|
||||
public DateTime Time { get; set; }
|
||||
|
||||
[JsonPropertyName("data")]
|
||||
public Data Data { get; set; }
|
||||
}
|
||||
|
||||
public class Units
|
||||
{
|
||||
[JsonPropertyName("air_pressure_at_sea_level")]
|
||||
public string AirPressureAtSeaLevel { get; set; }
|
||||
|
||||
[JsonPropertyName("air_temperature")]
|
||||
public string AirTemperature { get; set; }
|
||||
|
||||
[JsonPropertyName("cloud_area_fraction")]
|
||||
public string CloudAreaFraction { get; set; }
|
||||
|
||||
[JsonPropertyName("precipitation_amount")]
|
||||
public string PrecipitationAmount { get; set; }
|
||||
|
||||
[JsonPropertyName("relative_humidity")]
|
||||
public string RelativeHumidity { get; set; }
|
||||
|
||||
[JsonPropertyName("wind_from_direction")]
|
||||
public string WindFromDirection { get; set; }
|
||||
|
||||
[JsonPropertyName("wind_speed")]
|
||||
public string WindSpeed { get; set; }
|
||||
}
|
||||
@@ -1,24 +1,26 @@
|
||||
#nullable disable
|
||||
|
||||
using HomeApi.Models.Response;
|
||||
|
||||
namespace HomeApi.Models;
|
||||
|
||||
public class WeatherInformation
|
||||
{
|
||||
public string CityName { get; set; } = string.Empty;
|
||||
public string CityName { get; set; } = "Not defined";
|
||||
public Current Current { get; set; } = new();
|
||||
public List<Forecast> Forecast { get; set; }
|
||||
}
|
||||
|
||||
public class Current
|
||||
{
|
||||
public string Date { get; set; }
|
||||
public double Feelslike { get; set; }
|
||||
public int IsDay { get; set; }
|
||||
public string Date { get; set; } = string.Empty;
|
||||
public double Feelslike { get; set; } = 0;
|
||||
public int IsDay { get; set; } = 1;
|
||||
public double WindPerMeterSecond { get; set; } = 0;
|
||||
public double WindGustPerMeterSecond { get; set; } = 0;
|
||||
public double Temperature { get; set; } = 0;
|
||||
public string LastUpdated { get; set; } = string.Empty;
|
||||
public int Cloud { get; set; }
|
||||
public int Cloud { get; set; } = 0;
|
||||
public string WindDirection { get; set; } = string.Empty;
|
||||
public Location WeatherDataLocation { get; set; } = new();
|
||||
public AirQuality AirQuality { get; set; }
|
||||
@@ -28,72 +30,72 @@ public class Current
|
||||
|
||||
public class Location
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Region { get; set; }
|
||||
public string Country { get; set; }
|
||||
public double Lat { get; set; }
|
||||
public double Lon { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Region { get; set; } = string.Empty;
|
||||
public string Country { get; set; } = string.Empty;
|
||||
public double Lat { get; set; } = 0;
|
||||
public double Lon { get; set; } = 0;
|
||||
}
|
||||
|
||||
public class Probability
|
||||
{
|
||||
public DateTime Date { get; set; }
|
||||
public CalculatedProbability Calculated { get; set; } // my location?
|
||||
public string Colour { get; set; }
|
||||
public int Value { get; set; }
|
||||
public Highest HighestProbability { get; set; }
|
||||
public DateTime Date { get; set; } = DateTime.Now;
|
||||
public CalculatedProbability Calculated { get; set; } = new();
|
||||
public string Colour { get; set; } = string.Empty;
|
||||
public string Value { get; set; } = string.Empty;
|
||||
public Highest HighestProbability { get; set; } = new();
|
||||
}
|
||||
|
||||
public class Highest
|
||||
{
|
||||
public DateTime Date { get; set; }
|
||||
public string Colour { get; set; }
|
||||
public double Lat { get; set; }
|
||||
public double Long { get; set; }
|
||||
public int Value { get; set; }
|
||||
public DateTime Date { get; set; } = DateTime.Now;
|
||||
public string Colour { get; set; } = string.Empty;
|
||||
public double Lat { get; set; } = 0;
|
||||
public double Long { get; set; } = 0;
|
||||
public int Value { get; set; } = 0;
|
||||
}
|
||||
|
||||
public class Forecast
|
||||
{
|
||||
public string Date { get; set; }
|
||||
public double MinTempC { get; set; }
|
||||
public double MaxTempC { get; set; }
|
||||
public string DayIcon { get; set; }
|
||||
public WeatherSummary? Day { get; set; }
|
||||
public WeatherSummary? Night { get; set; }
|
||||
public Astro Astro { get; set; }
|
||||
public int IconCode { get; set; }
|
||||
public string Date { get; set; } = string.Empty;
|
||||
public double MinTempC { get; set; } = 0;
|
||||
public double MaxTempC { get; set; } = 0;
|
||||
public string DayIcon { get; set; } = string.Empty;
|
||||
public WeatherSummary? Day { get; set; } = null;
|
||||
public WeatherSummary? Night { get; set; } = null;
|
||||
public Astro Astro { get; set; } = new();
|
||||
public int IconCode { get; set; } = 0;
|
||||
|
||||
public int ChanceOfRain { get; set; }
|
||||
public int ChanceOfRain { get; set; } = 0;
|
||||
}
|
||||
public class Astro
|
||||
{
|
||||
public string Sunrise { get; set; }
|
||||
public string Sunset { get; set; }
|
||||
public string Moonrise { get; set; }
|
||||
public string Moonset { get; set; }
|
||||
public string Moon_Phase { get; set; }
|
||||
public string Sunrise { get; set; } = string.Empty;
|
||||
public string Sunset { get; set; } = string.Empty;
|
||||
public string Moonrise { get; set; } = string.Empty;
|
||||
public string Moonset { get; set; } = string.Empty;
|
||||
public string Moon_Phase { get; set; } = string.Empty;
|
||||
public double? Moon_Illumination { get; set; }
|
||||
}
|
||||
|
||||
public class AirQuality
|
||||
{
|
||||
public double Co { get; set; }
|
||||
public double No2 { get; set; }
|
||||
public double O3 { get; set; }
|
||||
public double So2 { get; set; }
|
||||
public double Pm2_5 { get; set; }
|
||||
public double Pm10 { get; set; }
|
||||
public int Us_Epa_Index { get; set; }
|
||||
public int Gb_Defra_Index { get; set; }
|
||||
public double Co { get; set; } = 0;
|
||||
public double No2 { get; set; } = 0;
|
||||
public double O3 { get; set; } = 0;
|
||||
public double So2 { get; set; } = 0;
|
||||
public double Pm2_5 { get; set; } = 0;
|
||||
public double Pm10 { get; set; } = 0;
|
||||
public int Us_Epa_Index { get; set; } = 0;
|
||||
public int Gb_Defra_Index { get; set; } = 0;
|
||||
}
|
||||
|
||||
public class WeatherSummary
|
||||
{
|
||||
public string ConditionText { get; set; }
|
||||
public string ConditionIcon { get; set; }
|
||||
public double AvgTempC { get; set; }
|
||||
public double AvgFeelslikeC { get; set; }
|
||||
public int TotalChanceOfRain { get; set; }
|
||||
public int TotalChanceOfSnow { get; set; }
|
||||
public string ConditionText { get; set; } = string.Empty;
|
||||
public string ConditionIcon { get; set; } = string.Empty;
|
||||
public double AvgTempC { get; set; } = 0;
|
||||
public double AvgFeelslikeC { get; set; } = 0;
|
||||
public int TotalChanceOfRain { get; set; } = 0;
|
||||
public int TotalChanceOfSnow { get; set; } = 0;
|
||||
}
|
||||
@@ -43,8 +43,11 @@
|
||||
return "fa-question-circle";
|
||||
}
|
||||
|
||||
private string GetAirQualityStatus(AirQuality data)
|
||||
private string GetAirQualityStatus(AirQuality? data)
|
||||
{
|
||||
if(data == null)
|
||||
return "No Data";
|
||||
|
||||
var highestAqi = Math.Max(data.Us_Epa_Index, data.Gb_Defra_Index);
|
||||
|
||||
return highestAqi switch
|
||||
@@ -487,12 +490,14 @@
|
||||
<div class="current-weather">
|
||||
<div class="location">
|
||||
<i class="fas fa-map-marker-alt location-icon"></i>
|
||||
<span class="location-text">@Model.Weather.CityName</span>
|
||||
<span class="location-text">@(Model.Weather?.CityName ?? "Failed to fetch data")</span>
|
||||
</div>
|
||||
|
||||
<div class="current-temp">
|
||||
<div class="temp-main">@Model.Weather.Current.Temperature°C</div>
|
||||
<div class="feels-like">Feels like @Model.Weather.Current.Feelslike°C</div>
|
||||
<div class="temp-main">
|
||||
@(Model.Weather?.Current.Temperature != null ? $"{Model.Weather.Current.Temperature}°C" : "N/A")
|
||||
</div>
|
||||
<div class="feels-like">Feels like @Model.Weather?.Current.Feelslike°C</div>
|
||||
</div>
|
||||
|
||||
<div class="weather-details">
|
||||
@@ -501,7 +506,7 @@
|
||||
<i class="fas fa-cloud cloud-icon"></i>
|
||||
<span>Clouds</span>
|
||||
</div>
|
||||
<span class="detail-value">@Model.Weather.Current.Cloud%</span>
|
||||
<span class="detail-value">@Model?.Weather?.Current.Cloud%</span>
|
||||
</div>
|
||||
|
||||
<div class="detail-item">
|
||||
@@ -509,7 +514,7 @@
|
||||
<i class="fas fa-wind wind-icon"></i>
|
||||
<span>Wind</span>
|
||||
</div>
|
||||
<span class="detail-value">@Model.Weather.Current.WindPerMeterSecond.ToString("0.##") m/s @Model.Weather.Current.WindDirection</span>
|
||||
<span class="detail-value">@Model?.Weather?.Current.WindPerMeterSecond.ToString("0.##") m/s @Model?.Weather?.Current.WindDirection</span>
|
||||
</div>
|
||||
|
||||
<div class="detail-item">
|
||||
@@ -517,7 +522,7 @@
|
||||
<i class="fas fa-chart-line activity-icon"></i>
|
||||
<span>Gusts</span>
|
||||
</div>
|
||||
<span class="detail-value">@Model.Weather.Current.WindGustPerMeterSecond.ToString("0.##") m/s</span>
|
||||
<span class="detail-value">@Model?.Weather?.Current.WindGustPerMeterSecond.ToString("0.##") m/s</span>
|
||||
</div>
|
||||
|
||||
<div class="detail-item">
|
||||
@@ -525,21 +530,21 @@
|
||||
<i class="fas fa-star aurora-icon"></i>
|
||||
<span>Aurora</span>
|
||||
</div>
|
||||
<span class="detail-value">@Model.Weather.Current.AuroraProbability.Value%</span>
|
||||
<span class="detail-value">@Model?.Weather?.Current.AuroraProbability.Value%</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="air-quality-badge">
|
||||
Air Quality: @GetAirQualityStatus(Model.Weather.Current.AirQuality)
|
||||
Air Quality: @GetAirQualityStatus(Model?.Weather?.Current.AirQuality)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Middle Column - Forecast -->
|
||||
<div class="forecast-section">
|
||||
<h3 class="section-title">@Model.Weather.Forecast.Count-Day Forecast</h3>
|
||||
<h3 class="section-title">@Model?.Weather?.Forecast.Count-Day Forecast</h3>
|
||||
|
||||
<div class="forecast-grid">
|
||||
@foreach (var day in Model.Weather.Forecast)
|
||||
@foreach (var day in Model?.Weather?.Forecast ?? Enumerable.Empty<Forecast>())
|
||||
{
|
||||
<div class="forecast-card">
|
||||
<div class="forecast-date">@GetDayStatus(day.Date)</div>
|
||||
@@ -559,7 +564,7 @@
|
||||
<i class="fas fa-sun sunrise-icon"></i>
|
||||
<span>Sunrise</span>
|
||||
</div>
|
||||
<span class="sun-moon-value">@Model.Weather.Forecast[0].Astro.Sunrise</span>
|
||||
<span class="sun-moon-value">@Model?.Weather?.Forecast[0].Astro.Sunrise</span>
|
||||
</div>
|
||||
|
||||
<div class="sun-moon-item">
|
||||
@@ -567,7 +572,7 @@
|
||||
<i class="fas fa-sun sunset-icon"></i>
|
||||
<span>Sunset</span>
|
||||
</div>
|
||||
<span class="sun-moon-value">@Model.Weather.Forecast[0].Astro.Sunset</span>
|
||||
<span class="sun-moon-value">@Model?.Weather?.Forecast[0].Astro.Sunset</span>
|
||||
</div>
|
||||
|
||||
<div class="sun-moon-item">
|
||||
@@ -575,7 +580,7 @@
|
||||
<i class="fas fa-moon moon-icon"></i>
|
||||
<span>Moonrise</span>
|
||||
</div>
|
||||
<span class="sun-moon-value">@Model.Weather.Forecast[0].Astro.Moonrise</span>
|
||||
<span class="sun-moon-value">@Model?.Weather?.Forecast[0].Astro.Moonrise</span>
|
||||
</div>
|
||||
|
||||
<div class="sun-moon-item">
|
||||
@@ -583,12 +588,12 @@
|
||||
<i class="fas fa-moon moon-icon"></i>
|
||||
<span>Moonset</span>
|
||||
</div>
|
||||
<span class="sun-moon-value">@Model.Weather.Forecast[0].Astro.Moonset</span>
|
||||
<span class="sun-moon-value">@Model?.Weather?.Forecast[0].Astro.Moonset</span>
|
||||
</div>
|
||||
|
||||
<div class="sun-moon-item">
|
||||
<span class="moon-phase-label">Moon phase</span>
|
||||
<span class="sun-moon-value">@Model.Weather.Forecast[0].Astro.Moon_Illumination%</span>
|
||||
<span class="sun-moon-value">@Model?.Weather?.Forecast[0].Astro.Moon_Illumination%</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -598,7 +603,7 @@
|
||||
<h3 class="section-title">Upcoming Departures</h3>
|
||||
|
||||
<div class="transport-list">
|
||||
@foreach (var transport in Model.TimeTable.Take(5))
|
||||
@foreach (var transport in Model?.TimeTable?.Take(5) ?? Enumerable.Empty<TimeTable>())
|
||||
{
|
||||
|
||||
var departureTime = DateTime.Parse(transport.DepartureTime);
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
|
||||
Console.WriteLine("Hello, World!");
|
||||
44
README.md
44
README.md
@@ -1,8 +1,29 @@
|
||||
# This [](https://github.com/Myxelium/HomeScreen/actions/workflows/build.yml)
|
||||
Core api and Esp32 code for displaying weather data and public transport information on a e-ink display.
|
||||
[](https://github.com/myxelium/Wireless_Eink_HomeScreen "Go to GitHub repo")
|
||||
[](https://github.com/myxelium/Wireless_Eink_HomeScreen)
|
||||
[](https://github.com/myxelium/Wireless_Eink_HomeScreen)
|
||||
[](https://github.com/myxelium/Wireless_Eink_HomeScreen/releases/)
|
||||
[](https://www.gnu.org/licenses/gpl-3.0.en.html)
|
||||
[](https://github.com/myxelium/Wireless_Eink_HomeScreen/issues)
|
||||
[](https://github.com/Myxelium/Wireless_Eink_HomeScreen/actions/workflows/build.yml)
|
||||
# What why how
|
||||
This is a project I created that pulls weather data from the internet, transforms it into custom images, and displays them on an e-ink screen powered by an ESP32.
|
||||
|
||||
## What This Project Does
|
||||
|
||||
I wanted a low-power way to see weather information at a glance, so I built this system that:
|
||||
|
||||
- Fetches real-time weather data from online APIs
|
||||
- Processes and converts the data into visual images (temperature graphs, forecast icons, etc.)
|
||||
- Sends these images wirelessly to an ESP32 microcontroller
|
||||
- Displays the information on an energy-efficient e-ink screen
|
||||
- Updates periodically while consuming minimal power
|
||||
|
||||
<img width="800" height="480" alt="image" src="https://github.com/user-attachments/assets/ef5af0c6-ea3a-494d-b2af-3de6e70b3e6a" />
|
||||
|
||||
# How do I get to use this without programming knowledge?
|
||||
Check in the wiki for the guide how to get everything working!
|
||||
### 😺 [Wiki Get Started Guide](https://github.com/Myxelium/Wireless_Eink_HomeScreen/wiki/)
|
||||
|
||||
## Git Notes
|
||||
All commits has to follow this [Conventional Commits style](https://www.conventionalcommits.org/) to pass the pipeline.
|
||||
## Features 😺
|
||||
@@ -11,8 +32,8 @@ All commits has to follow this [Conventional Commits style](https://www.conventi
|
||||
- Display time and date
|
||||
|
||||
## Requirements 🫥
|
||||
- ESP32 board
|
||||
- E-ink display (e.g. Waveshare 7.5 inch)
|
||||
- [ESP32 board](https://www.waveshare.com/wiki/E-Paper_ESP32_Driver_Board)
|
||||
- [E-ink display (e.g. Waveshare 7.5 inch)](https://www.waveshare.com/7.5inch-e-paper-hat.htm)
|
||||
|
||||
# Installation
|
||||
|
||||
@@ -92,7 +113,7 @@ end
|
||||
API[HomeControllerAPI]
|
||||
API -->|MediatR| Handlers
|
||||
Handlers -->|Service Calls| Services
|
||||
Services -->|Refit Clients| Clients
|
||||
Services -->|Refit Http Clients| Clients
|
||||
Clients -->|External APIs| ExtAPIs
|
||||
API -->|Returns JSON/JPEG| ESP
|
||||
end
|
||||
@@ -109,3 +130,16 @@ end
|
||||
ExtAPIs -.-> NominatimAPI
|
||||
ExtAPIs -.-> ResRobotAPI
|
||||
```
|
||||
|
||||
# ESP32 configuration and building
|
||||
<img width="4096" height="1842" alt="image" src="https://github.com/user-attachments/assets/5acf1b3b-f9bb-48bd-b310-a2852544eaba" />
|
||||
|
||||
Best way of getting the ESP32 ready for code upload is to follow this guide [WAVESHARE ESP32 GUIDE](https://web.archive.org/web/20250706150325/https://www.waveshare.com/wiki/E-Paper_ESP32_Driver_Board).
|
||||
Once you have it ready so you can upload code to it copy my code in: Esp32_Code/INFOSCREEN_WITH_INTERVAL from this repo.
|
||||
|
||||
Install following libraries (if more is needed search for them and install them too):
|
||||
* ArduinoJson
|
||||
* GUI_Paint
|
||||
* JPEGDEC
|
||||
|
||||
You need the Waveshare examples installed since it uses code from them download them here [Download](https://files.waveshare.com/upload/5/50/E-Paper_ESP32_Driver_Board_Code.7z) or check above link.
|
||||
|
||||
Reference in New Issue
Block a user