Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.0.1.2 #95

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions Source/Clima_Demo/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,5 @@ private void OnMeadowSystemError(MeadowSystemErrorInfo error, bool recommendRese
}

forceReset = recommendReset;

// override the reset recommendation
//forceReset = false;
}

private void OnMeadowSystemError(object sender, MeadowSystemErrorInfo e)
{
Resolver.Log.Error($"App has detected a system error: {e.Message}");

if (e is Esp32SystemErrorInfo esp)
{
Resolver.Log.Error($"ESP function: {esp.Function}");
Resolver.Log.Error($"ESP status code: {esp.StatusCode}");
}

if (e.Exception != null)
{
Resolver.Log.Error($"Exception: {e.Exception.Message}");
Resolver.Log.Error($"ErrorNumber: {e.ErrorNumber}");
Resolver.Log.Error($"HResult: {e.Exception.HResult}");

if (e.Exception.InnerException != null)
{
Resolver.Log.Error($"InnerException: {e.Exception.InnerException.Message}");
Resolver.Log.Error($"HResult: {e.Exception.InnerException.HResult}");
}
}
}
}
6 changes: 4 additions & 2 deletions Source/Meadow.Clima/ClimaAppBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Meadow.Devices;

/// <summary>
/// Base class for Clima applications.
/// </summary>
public abstract class ClimaAppBase : App<F7CoreComputeV2, ClimaHardwareProvider, IClimaHardware>
{
}
{ }
10 changes: 8 additions & 2 deletions Source/Meadow.Clima/ClimaHardwareProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ namespace Meadow.Devices;
/// </summary>
public class ClimaHardwareProvider : IMeadowAppEmbeddedHardwareProvider<IClimaHardware>
{
/// <summary>
/// Initializes a new instance of the ClimaHardwareProvider class.
/// </summary>
public ClimaHardwareProvider()
{
}
{ }

/// <summary>
/// Creates an instance of the Clima hardware.
/// </summary>
/// <returns>An instance of IClimaHardware.</returns>
public static IClimaHardware Create()
{
return new ClimaHardwareProvider()
Expand Down
14 changes: 14 additions & 0 deletions Source/Meadow.Clima/Constants/CloudEventIds.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
namespace Meadow.Devices.Clima.Constants;

/// <summary>
/// Enumeration of cloud event IDs.
/// </summary>
public enum CloudEventIds
{
/// <summary>
/// Event ID for when the device starts.
/// </summary>
DeviceStarted = 100,

/// <summary>
/// Event ID for telemetry data.
/// </summary>
Telemetry = 110,

/// <summary>
/// Event ID for booting from a crash.
/// </summary>
BootFromCrash = 200
}
44 changes: 34 additions & 10 deletions Source/Meadow.Clima/Controllers/CloudController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@

namespace Meadow.Devices.Clima.Controllers;

/// <summary>
/// Controller for handling cloud-related operations.
/// </summary>
public class CloudController
{
/// <summary>
/// Waits for all data to be sent to the cloud.
/// </summary>
public async Task WaitForDataToSend()
{
// TODO: add a timeout here
Expand All @@ -20,27 +26,31 @@ public async Task WaitForDataToSend()
Resolver.Log.Info($"All cloud data has been sent");
}

/// <summary>
/// Logs the application startup after a crash.
/// </summary>
public void LogAppStartupAfterCrash()
{
SendEvent(CloudEventIds.DeviceStarted, $"Device restarted after crash");
}

/// <summary>
/// Logs the application startup with the specified hardware revision.
/// </summary>
/// <param name="hardwareRevision">The hardware revision of the device.</param>
public void LogAppStartup(string hardwareRevision)
{
SendEvent(CloudEventIds.DeviceStarted, $"Device started (hardware {hardwareRevision})");
}

/// <summary>
/// Logs the device information including name and location.
/// </summary>
/// <param name="deviceName">The name of the device.</param>
/// <param name="latitiude">The latitude of the device location.</param>
/// <param name="longitude">The longitude of the device location.</param>
public void LogDeviceInfo(string deviceName, double latitiude, double longitude)
{
// {
// "description": "Clima Boot Telemetry",
// "eventId": 109,
// "timestamp": "2024-05-20T22:25:15.862Z",
// "measurements": {
// "lat": 34.2277472,
// "long": -118.2273136
// }
// }
var cloudEvent = new CloudEvent
{
Description = "Clima Position Telemetry",
Expand All @@ -51,19 +61,33 @@ public void LogDeviceInfo(string deviceName, double latitiude, double longitude)
cloudEvent.Measurements.Add("device_name", deviceName);
cloudEvent.Measurements.Add("lat", latitiude);
cloudEvent.Measurements.Add("long", longitude);

SendEvent(cloudEvent);
}

/// <summary>
/// Logs a warning message.
/// </summary>
/// <param name="message">The warning message to log.</param>
public void LogWarning(string message)
{
SendLog(message, "warning");
}

/// <summary>
/// Logs an informational message.
/// </summary>
/// <param name="message">The informational message to log.</param>
public void LogMessage(string message)
{
SendLog(message, "information");
}

/// <summary>
/// Logs telemetry data from sensors and power data.
/// </summary>
/// <param name="sensorData">The sensor data to log.</param>
/// <param name="powerData">The power data to log.</param>
public void LogTelemetry(SensorData sensorData, PowerData powerData)
{
var measurements = sensorData
Expand Down
19 changes: 16 additions & 3 deletions Source/Meadow.Clima/Controllers/LocationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,27 @@

namespace Meadow.Devices.Clima.Controllers;

/// <summary>
/// Controller for handling GNSS location data.
/// </summary>
public class LocationController
{
private IGnssSensor gnss;
private readonly IGnssSensor? gnss = null;

/// <summary>
/// Gets or sets a value indicating whether to log data.
/// </summary>
public bool LogData { get; set; } = false;

public event EventHandler<GnssPositionInfo> PositionReceived;
/// <summary>
/// Event that is triggered when a GNSS position is received.
/// </summary>
public event EventHandler<GnssPositionInfo>? PositionReceived = null;

/// <summary>
/// Initializes a new instance of the <see cref="LocationController"/> class.
/// </summary>
/// <param name="clima">The Clima hardware interface.</param>
public LocationController(IClimaHardware clima)
{
if (clima.Gnss is { } gnss)
Expand All @@ -31,7 +44,7 @@ private void OnGnssDataReceived(object sender, IGnssResult e)
// we only need one position fix - weather stations don't move
Resolver.Log.InfoIf(LogData, $"GNSS Position: lat: [{pi.Position.Latitude}], long: [{pi.Position.Longitude}]");
PositionReceived?.Invoke(this, pi);
gnss.StopUpdating();
gnss?.StopUpdating();
}
}
}
Expand Down
45 changes: 39 additions & 6 deletions Source/Meadow.Clima/Controllers/NetworkController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,44 @@

namespace Meadow.Devices.Clima.Controllers;

/// <summary>
/// Controller for managing network connections and reporting network status.
/// </summary>
public class NetworkController
{
/// <summary>
/// Event triggered when the connection state changes.
/// </summary>
public event EventHandler<bool>? ConnectionStateChanged;

/// <summary>
/// Event triggered when the network is down for a specified period.
/// </summary>
public event EventHandler<TimeSpan>? NetworkDown;

private readonly INetworkAdapter networkAdapter;
private DateTimeOffset? lastDown;
private Timer downEventTimer;

public bool IsConnected => networkAdapter.IsConnected;
public TimeSpan DownTime => lastDown == null ? TimeSpan.Zero : DateTime.UtcNow - lastDown.Value;
public TimeSpan DownEventPeriod { get; } = TimeSpan.FromSeconds(30);

private readonly Timer downEventTimer;

/// <summary>
/// Gets a value indicating whether the network is connected.
/// </summary>
public bool IsConnected { get; private set; }

/// <summary>
/// Gets the total time the network has been down.
/// </summary>
public TimeSpan DownTime { get; private set; }

/// <summary>
/// Gets the period for triggering network down events.
/// </summary>
public TimeSpan DownEventPeriod { get; private set; }

/// <summary>
/// Initializes a new instance of the <see cref="NetworkController"/> class.
/// </summary>
/// <param name="networkAdapter">The network adapter</param>
public NetworkController(INetworkAdapter networkAdapter)
{
if (networkAdapter is IWiFiNetworkAdapter wifi)
Expand All @@ -38,6 +63,10 @@ public NetworkController(INetworkAdapter networkAdapter)
downEventTimer = new Timer(DownEventTimerProc, null, -1, -1);
}

/// <summary>
/// Connects to the cloud.
/// </summary>
/// <returns>A task representing the asynchronous operation.</returns>
public async Task<bool> ConnectToCloud()
{
if (networkAdapter is IWiFiNetworkAdapter wifi)
Expand All @@ -54,6 +83,10 @@ public async Task<bool> ConnectToCloud()
return networkAdapter.IsConnected;
}

/// <summary>
/// Shuts down the network.
/// </summary>
/// <returns>A task representing the asynchronous operation.</returns>
public async Task ShutdownNetwork()
{
if (networkAdapter is IWiFiNetworkAdapter wifi)
Expand Down
Loading
Loading