Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #50 from WildernessLabs/develop
Browse files Browse the repository at this point in the history
Update to 1.7.0
  • Loading branch information
jorgedevs committed Jan 10, 2024
2 parents b15e802 + 1d5c517 commit 869f2cb
Show file tree
Hide file tree
Showing 32 changed files with 652 additions and 338 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/develop-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ jobs:
path: Maple
ref: develop

- name: Checkout amqpnetlite
uses: actions/checkout@v3
with:
repository: WildernessLabs/amqpnetlite
path: amqpnetlite
ref: v2.4.5-meadow

- name: Checkout Meadow.Project.Samples
uses: actions/checkout@v3
with:
Expand Down
Binary file modified Design/MeadowAzureIoTHub.png
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Public project samples for Meadow and Meadow.Foundation. Click on any of the pro
<tr>
<td>
<img src="Design/MeadowAzureIoTHub.png" alt="iot, dotnet, meadow, azure, iot-hub"/><br/>
Send Temp/Humidity data from Meadow to Azure IoT Hub</br>
Send environmental data to Azure IoT Hub via AMQP or MQTT</br>
<a href="https://www.hackster.io/wilderness-labs/send-temperature-humidity-data-from-meadow-to-azure-iot-hub-340b39">Hackster</a> | <a href="Source/Azure/AzureIoTHub/">Source Code</a>
</td>
<td>
Expand Down
77 changes: 0 additions & 77 deletions Source/Azure/AzureIoTHub/Azure/IoTHubManager.cs

This file was deleted.

241 changes: 241 additions & 0 deletions Source/Azure/AzureIoTHub/Controllers/DisplayController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
using Meadow;
using Meadow.Foundation.Graphics;
using Meadow.Foundation.Graphics.MicroLayout;
using Meadow.Units;
using System.Threading;

namespace MeadowAzureIoTHub.Controllers
{
public class DisplayController
{
Color backgroundColor = Color.FromHex("#23ABE3");

Font8x12 font8x12 = new Font8x12();
Font12x20 font12X20 = new Font12x20();

CancellationTokenSource token;

Image imgWifi = Image.LoadFromResource("MeadowAzureIoTHub.Resources.img_wifi.bmp");
Image imgWifiFade = Image.LoadFromResource("MeadowAzureIoTHub.Resources.img_wifi_fade.bmp");
Image imgSync = Image.LoadFromResource("MeadowAzureIoTHub.Resources.img_sync.bmp");
Image imgSyncFade = Image.LoadFromResource("MeadowAzureIoTHub.Resources.img_sync_fade.bmp");

DisplayScreen displayScreen;

AbsoluteLayout SplashLayout;

AbsoluteLayout DataLayout;

Picture Wifi;

Picture Sync;

Label Title;

Label Temperature;

Label Humidity;

public DisplayController(IGraphicsDisplay display)
{
displayScreen = new DisplayScreen(display, RotationType._90Degrees)
{
BackgroundColor = backgroundColor
};

LoadSplashLayout();

displayScreen.Controls.Add(SplashLayout);

LoadDataLayout();

displayScreen.Controls.Add(DataLayout);
}

private void LoadSplashLayout()
{
SplashLayout = new AbsoluteLayout(displayScreen, 0, 0, displayScreen.Width, displayScreen.Height)
{
IsVisible = false
};

var logo = Image.LoadFromResource("MeadowAzureIoTHub.Resources.img_meadow.bmp");
var displayImage = new Picture(
55,
60,
logo.Width,
logo.Height,
logo)
{
BackColor = backgroundColor,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
};
SplashLayout.Controls.Add(displayImage);

SplashLayout.Controls.Add(new Label(
0,
160,
displayScreen.Width,
font8x12.Height)
{
Text = $"Azure IoT Hub",
TextColor = Color.Black,
Font = font8x12,
ScaleFactor = ScaleFactor.X2,
HorizontalAlignment = HorizontalAlignment.Center,
});
}

public void LoadDataLayout()
{
DataLayout = new AbsoluteLayout(displayScreen, 0, 0, displayScreen.Width, displayScreen.Height)
{
IsVisible = false
};

Sync = new Picture(
15,
15,
imgSyncFade.Width,
imgSyncFade.Height,
imgSyncFade);
DataLayout.Controls.Add(Sync);

Title = new Label(
60,
20,
120,
26)
{
Text = "AMQP",
TextColor = Color.Black,
Font = font8x12,
ScaleFactor = ScaleFactor.X2,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
DataLayout.Controls.Add(Title);

Wifi = new Picture(
195,
15,
imgWifiFade.Width,
imgWifiFade.Height,
imgWifiFade);
DataLayout.Controls.Add(Wifi);

DataLayout.Controls.Add(new Box(
20,
57,
200,
76)
{
ForeColor = Color.Black,
IsFilled = false
});

DataLayout.Controls.Add(new Label(
24,
65,
192,
font8x12.Height * 2)
{
Text = "Temperature",
TextColor = Color.Black,
Font = font8x12,
ScaleFactor = ScaleFactor.X2,
HorizontalAlignment = HorizontalAlignment.Center
});

Temperature = new Label(
24,
93,
192,
font12X20.Height * 2)
{
Text = "--°C",
TextColor = Color.Black,
Font = font12X20,
ScaleFactor = ScaleFactor.X2,
HorizontalAlignment = HorizontalAlignment.Center
};
DataLayout.Controls.Add(Temperature);

DataLayout.Controls.Add(new Box(
20,
144,
200,
76)
{
ForeColor = Color.Black,
IsFilled = false
});

DataLayout.Controls.Add(new Label(
24,
152,
192,
font8x12.Height * 2)
{
Text = "Humidity",
TextColor = Color.Black,
Font = font8x12,
ScaleFactor = ScaleFactor.X2,
HorizontalAlignment = HorizontalAlignment.Center
});

Humidity = new Label(
24,
180,
192,
font12X20.Height * 2)
{
Text = "--%",
TextColor = Color.Black,
Font = font12X20,
ScaleFactor = ScaleFactor.X2,
HorizontalAlignment = HorizontalAlignment.Center
};
DataLayout.Controls.Add(Humidity);
}

public void ShowSplashScreen()
{
DataLayout.IsVisible = false;
SplashLayout.IsVisible = true;
}

public void ShowDataScreen()
{
SplashLayout.IsVisible = false;
DataLayout.IsVisible = true;
}

public void UpdateTitle(string title)
{
Title.Text = title;
}

public void UpdateWiFiStatus(bool isConnected)
{
Wifi.Image = isConnected
? imgWifi
: imgWifiFade;
}

public void UpdateSyncStatus(bool isSyncing)
{
Sync.Image = isSyncing
? imgSync
: imgSyncFade;
}

public void UpdateReadings((Temperature? Temperature, RelativeHumidity? Humidity) reading)
{
Temperature.Text = $"{reading.Temperature.Value.Celsius:N1}°C";

Humidity.Text = $"{reading.Humidity.Value.Percent:N2}%";
}
}
}
26 changes: 26 additions & 0 deletions Source/Azure/AzureIoTHub/Controllers/IIoTHubController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Meadow.Units;
using System.Threading.Tasks;

namespace MeadowAzureIoTHub.Controllers
{
/// <summary>
/// You'll need to create an IoT Hub - https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-create-through-portal
/// Create a device within your IoT Hub
/// And then generate a SAS token - this can be done via the Azure CLI
///
/// Example
/// az iot hub generate-sas-token
/// --hub-name HUB_NAME
/// --device-id DEVICE_ID
/// --resource-group RESOURCE_GROUP
/// --login [Open Shared access policies -> Select iothubowner -> copy Primary connection string]
/// </summary>
internal interface IIoTHubController
{
bool isAuthenticated { get; }

Task<bool> Initialize();

Task SendEnvironmentalReading((Temperature? Temperature, RelativeHumidity? Humidity) reading);
}
}
Loading

0 comments on commit 869f2cb

Please sign in to comment.