Azure IoT Application — Part 1
Hello, This docs will guide you to build basic IoT device configuration with Azure. In this docs will be creating IoT device simulation. I have created this in year 2018, some of azure services might be rename.
STEP 1: Launch Visual Studio
Step 2: Go to File menu and select New -> Project
Step 3: Select Blank App (Universal Windows) template. Enter project Name IoTDeviceApp
Step 4: Choose Minimum Version & Target Version according to Installed SDK.
Step 5: Wait for few seconds to load the Blank Project. Double click on “MainPage.xaml” file
Step 6: replace below code with Grid tag.
Remove below code & add StackPanel code block
<Grid Background=”{ThemeResource ApplicationPageBackgroundThemeBrush}”>
</Grid>
Replace to
<StackPanel Background=”{ThemeResource ApplicationPageBackgroundThemeBrush}”>
<TextBlock FontSize=”32">Intervals:</TextBlock>
<TextBlock FontSize=”32" x:Name=”txtIntervalCount”></TextBlock>
</StackPanel>
Step 7: Open or double click on MainPage.xaml.cs file.
Step 8: Add below code
namespace IoTDeviceApp
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
DispatcherTimer _sensorTimer;
int _intervalCount = 0;
public MainPage()
{
this.InitializeComponent();
}
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
_sensorTimer = new DispatcherTimer();
_sensorTimer.Interval = TimeSpan.FromMilliseconds(500);
_sensorTimer.Tick += SensorTimer_Tick1;
_sensorTimer.Start();
}
async void SensorTimer_Tick1(object sender, object e)
{
_intervalCount++;
txtIntervalCount.Text = _intervalCount.ToString();
// Simulate reading Temperature from Device
var rand = new Random();
double temp = 22 + rand.NextDouble() * 4–2;
}
}
}
Step 9: To run an app, click on “Local Machine” option
Interval will start automatically
Thanks For Reading.
PART 2 : https://thisismeetpatel.medium.com/azure-iot-part-2-setup-azure-iot-hub-9c196d5721ae
Part 4: https://thisismeetpatel.medium.com/azure-iot-application-part-4-service-bus-queue-630dfd4c3fa8
Part 5: https://thisismeetpatel.medium.com/azure-iot-application-part-5-logic-apps-2e76d5b10ea4
Follow me
LinkedIn : Meet Patel
Twitter : Meet Patel