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

Additional samples #84

Closed
wants to merge 14 commits into from
Closed
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
24 changes: 24 additions & 0 deletions Source/Additional Samples/Clima_Simulation/Clima_Simulation.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Meadow.Sdk/1.1.0">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<OutputType>Library</OutputType>
<AssemblyName>App</AssemblyName>
<LangVersion>10.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Meadow.Core\source\implementations\f7\Meadow.F7\Meadow.F7.csproj" />
<ProjectReference Include="..\..\..\..\Meadow.Logging\Source\Meadow.Logging.LogProviders\Driver\Meadow.Logging.LogProviders.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="meadow.config.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="app.config.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="wifi.config.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
48 changes: 48 additions & 0 deletions Source/Additional Samples/Clima_Simulation/MeadowApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Meadow;
using Meadow.Devices;
using Meadow.Logging;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Clima_Simulation;
// Change F7FeatherV2 to F7FeatherV1 if using Feather V1 Meadow boards
// Change to F7CoreComputeV2 for Project Lab V3.x
public class MeadowApp : App<F7CoreComputeV2>
{
public override async Task Initialize()
{
Resolver.Log.Info($"Initializing...");

var cloudLogger = new CloudLogger();
Resolver.Log.AddProvider(cloudLogger);
Resolver.Services.Add(cloudLogger);

var count = 1;
var r = new Random();

while (true)
{
// send a cloud log
Resolver.Log.Info($"log loop {count++}");

// send a cloud event
var cl = Resolver.Services.Get<CloudLogger>();
cl.LogEvent(100, "clima conditions", new Dictionary<string, object>()
{
{ "Temperature", r.Next(20, 25) },
{ "Rain", r.Next(0, 5) },
{ "Light", r.Next(1000, 2000) },
{ "SolarVoltage", r.Next(3, 5) },
{ "Humidity", r.Next(80, 110) },
{ "WindSpeed", r.Next(10, 15) },
{ "WindDirection", r.Next(0, 360) },
{ "Pressure", r.Next(1, 5) },
{ "Co2Level", r.Next(750, 1000) },
{ "BatteryVoltage", r.Next(3,5) },
});

await Task.Delay(60 * 1000);
}
}
}
36 changes: 36 additions & 0 deletions Source/Additional Samples/Clima_Simulation/app.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Uncomment additional options as needed.
# To learn more about these config options, including custom application configuration settings, check out the Application Settings Configuration documentation.
# http://developer.wildernesslabs.co/Meadow/Meadow.OS/Configuration/Application_Settings_Configuration/

# App lifecycle configuration.
Lifecycle:

# Control whether Meadow will restart when an unhandled app exception occurs. Combine with Lifecycle > AppFailureRestartDelaySeconds to control restart timing.
RestartOnAppFailure: false

# When app set to restart automatically on app failure,
# AppFailureRestartDelaySeconds: 15

# Logging configuration.
Logging:

# Adjust the level of logging detail.
LogLevel:

# Trace, Debug, Information, Warning, or Error
Default: Trace

# Meadow.Cloud configuration.
MeadowCloud:

# Enable Logging, Events, Command + Control
Enabled: true

# Enable Over-the-air Updates
# EnableUpdates: false

# Enable Health Metrics
# EnableHealthMetrics: false

# How often to send metrics to Meadow.Cloud
# HealthMetricsIntervalMinutes: 60
54 changes: 54 additions & 0 deletions Source/Additional Samples/Clima_Simulation/meadow.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Acceptable values for true: true, 1, yes
# Acceptable values for false: false, 0, no

# Main Device Config
Device:

# Name of the device on the network.
Name: MeadowDevice

# Uncomment if SD card hardware present on this hardware
# (e.g., Core-Compute module with SD add-on)? Optional; default value is `false`.
# SdStorageSupported: true

# Control how the ESP coprocessor will start and operate.
Coprocessor:

# Should the ESP32 automatically attempt to connect to an access point at startup?
# If set to true, wifi.yaml credentials must be stored in the device.
AutomaticallyStartNetwork: true

# Should the ESP32 automatically reconnect to the configured access point?
AutomaticallyReconnect: true

# Maximum number of retry attempts for connections etc. before an error code is returned.
MaximumRetryCount: 7

# Network configuration.
Network:

# Network Interface (Default value is WiFi with DHCP)
Interfaces:
- Name: WiFi
UseDHCP: true

# Default Interface
DefaultInterface: Wifi

# Automatically attempt to get the time at startup?
GetNetworkTimeAtStartup: true

# Time synchronization period in seconds.
NtpRefreshPeriod: 600

# Name of the NTP servers.
NtpServers:
- 0.pool.ntp.org
- 1.pool.ntp.org
- 2.pool.ntp.org
- 3.pool.ntp.org

# IP addresses of the DNS servers.
DnsServers:
- 1.1.1.1
- 8.8.8.8
12 changes: 12 additions & 0 deletions Source/Additional Samples/Clima_Simulation/wifi.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Uncomment to set the default Wi-Fi credentials. (This file will be processed into secure storage on the ESP32 and then deleted from the device.)
# To learn more about these config options, including custom application configuration settings, check out the Application Settings Configuration documentation.
# http://developer.wildernesslabs.co/Meadow/Meadow.OS/Configuration/WiFi_Configuration/

# WiFi network credentials
Credentials:

# WiFi SSID
Ssid: YourSSID

# WiFi Password
Password: SSIDPassword
11 changes: 11 additions & 0 deletions Source/Additional Samples/Clima_reTerminal/App.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Application
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Clima_reTerminal"
x:Class="Clima_reTerminal.App">

<Application.Styles>
<FluentTheme />
<StyleInclude Source="avares://OxyPlot.Avalonia/Themes/Default.axaml"/>
</Application.Styles>
</Application>
36 changes: 36 additions & 0 deletions Source/Additional Samples/Clima_reTerminal/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Clima_reTerminal.ViewModels;
using Clima_reTerminal.Views;

namespace Clima_reTerminal
{
public partial class App : Application
{
public App()
{
RegisterServices();
}

public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
base.Initialize();
}

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(),
//WindowState = Avalonia.Controls.WindowState.FullScreen
};
}

base.OnFrameworkInitializationCompleted();
}
}
}
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions Source/Additional Samples/Clima_reTerminal/Client/RestClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using Clima_reTerminal.Models;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace Clima_reTerminal.Client
{
public static class RestClient
{
static RestClient() { }

public static async Task<List<QueryResponse>> GetSensorReadings()
{
using (HttpClient client = new HttpClient())
{
try
{
client.DefaultRequestHeaders.Add("Authorization", $"apikey {Secrets.API_KEY}");
client.Timeout = new TimeSpan(0, 5, 0);

var response = await client.GetAsync($"" +
$"{Secrets.MEADOW_CLOUD_URL}/api/orgs/{Secrets.ORGANIZATION_ID}/search/source:event " +
$"deviceId:{Secrets.DEVICE_ID} eventId:100 size:20 sortby:timestamp sortorder:desc");

if (response.IsSuccessStatusCode)
{
string jsonString = await response.Content.ReadAsStringAsync();
Console.WriteLine("Response Content: " + jsonString);

var root = JsonSerializer.Deserialize<Root>(jsonString);

return root?.data?.queryResponses;
}
else
{
Console.WriteLine("Error: " + response.StatusCode);
return new List<QueryResponse>();
}
}
catch (TaskCanceledException)
{
Console.WriteLine("Request timed out.");
return new List<QueryResponse>();
}
catch (Exception e)
{
Console.WriteLine($"Request went sideways: {e.Message}");
return new List<QueryResponse>();
}
}
}

public static async Task<bool> SendCommand(CultivarCommands command, bool relayState)
{
using (HttpClient client = new HttpClient())
{
try
{
client.DefaultRequestHeaders.Add("Authorization", $"apikey {Secrets.API_KEY}");
client.Timeout = new TimeSpan(0, 5, 0);

string jsonString = $"" +
$"{{" +
$"\"deviceIds\": [" +
$"\"{Secrets.DEVICE_ID}\"]," +
$"\"commandName\": \"{command}\"," +
$"\"args\": {{ " +
$"\"relaystate\": {relayState}" +
$"}}," +
$"\"qos\": 0" +
$"}}";

var content = new StringContent(jsonString, Encoding.UTF8, "application/json");

HttpResponseMessage response = await client.PostAsync($"{Secrets.MEADOW_CLOUD_URL}/api/devices/commands", content);

if (response.IsSuccessStatusCode)
{
string responseContent = await response.Content.ReadAsStringAsync();
Console.WriteLine("Response Content: " + responseContent);
}
else
{
Console.WriteLine("Error: " + response.StatusCode);
}

return true;
}
catch (TaskCanceledException)
{
Console.WriteLine("Request timed out.");
return false;
}
catch (Exception e)
{
Console.WriteLine($"Request went sideways: {e.Message}");
return false;
}
}
}
}
}
37 changes: 37 additions & 0 deletions Source/Additional Samples/Clima_reTerminal/Clima_reTerminal.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

<ItemGroup>
<AvaloniaResource Include="Assets\**" />
<None Remove=".gitignore" />
<None Remove="Assets\icon-fans.png" />
<None Remove="Assets\icon-heater.png" />
<None Remove="Assets\icon-humidity.png" />
<None Remove="Assets\icon-lights.png" />
<None Remove="Assets\icon-soil.png" />
<None Remove="Assets\icon-sprinkler.png" />
<None Remove="Assets\icon-temp.png" />
</ItemGroup>

<ItemGroup>
<TrimmerRootDescriptor Include="Roots.xml" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.4" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.4" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.4" />
<PackageReference Include="Azure.DigitalTwins.Core" Version="1.4.0" />
<PackageReference Include="Azure.Identity" Version="1.11.3" />
<PackageReference Include="OxyPlot.Avalonia" Version="2.1.0-Avalonia11" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.4" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.4" />
</ItemGroup>
</Project>
Loading
Loading