diff --git a/Samples/WeatherStation/CS/App.xaml b/Samples/WeatherStation/CS/App.xaml
new file mode 100644
index 000000000..88cbb91f7
--- /dev/null
+++ b/Samples/WeatherStation/CS/App.xaml
@@ -0,0 +1,8 @@
+
+
+
diff --git a/Samples/WeatherStation/CS/App.xaml.cs b/Samples/WeatherStation/CS/App.xaml.cs
new file mode 100644
index 000000000..1d18afc15
--- /dev/null
+++ b/Samples/WeatherStation/CS/App.xaml.cs
@@ -0,0 +1,97 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices.WindowsRuntime;
+using Windows.ApplicationModel;
+using Windows.ApplicationModel.Activation;
+using Windows.Foundation;
+using Windows.Foundation.Collections;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Controls.Primitives;
+using Windows.UI.Xaml.Data;
+using Windows.UI.Xaml.Input;
+using Windows.UI.Xaml.Media;
+using Windows.UI.Xaml.Navigation;
+
+namespace WeatherDataReporter
+{
+ ///
+ /// Provides application-specific behavior to supplement the default Application class.
+ ///
+ sealed partial class App : Application
+ {
+ ///
+ /// Initializes the singleton application object. This is the first line of authored code
+ /// executed, and as such is the logical equivalent of main() or WinMain().
+ ///
+ public App()
+ {
+ this.InitializeComponent();
+ this.Suspending += OnSuspending;
+ }
+
+ ///
+ /// Invoked when the application is launched normally by the end user. Other entry points
+ /// will be used such as when the application is launched to open a specific file.
+ ///
+ /// Details about the launch request and process.
+ protected override void OnLaunched(LaunchActivatedEventArgs e)
+ {
+ Frame rootFrame = Window.Current.Content as Frame;
+
+ // Do not repeat app initialization when the Window already has content,
+ // just ensure that the window is active
+ if (rootFrame == null)
+ {
+ // Create a Frame to act as the navigation context and navigate to the first page
+ rootFrame = new Frame();
+
+ rootFrame.NavigationFailed += OnNavigationFailed;
+
+ if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
+ {
+ //TODO: Load state from previously suspended application
+ }
+
+ // Place the frame in the current Window
+ Window.Current.Content = rootFrame;
+ }
+
+ if (rootFrame.Content == null)
+ {
+ // When the navigation stack isn't restored navigate to the first page,
+ // configuring the new page by passing required information as a navigation
+ // parameter
+ rootFrame.Navigate(typeof(MainPage), e.Arguments);
+ }
+ // Ensure the current window is active
+ Window.Current.Activate();
+ }
+
+ ///
+ /// Invoked when Navigation to a certain page fails
+ ///
+ /// The Frame which failed navigation
+ /// Details about the navigation failure
+ void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
+ {
+ throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
+ }
+
+ ///
+ /// Invoked when application execution is being suspended. Application state is saved
+ /// without knowing whether the application will be terminated or resumed with the contents
+ /// of memory still intact.
+ ///
+ /// The source of the suspend request.
+ /// Details about the suspend request.
+ private void OnSuspending(object sender, SuspendingEventArgs e)
+ {
+ var deferral = e.SuspendingOperation.GetDeferral();
+ //TODO: Save application state and stop any background activity
+ deferral.Complete();
+ }
+ }
+}
diff --git a/Samples/WeatherStation/CS/ConnectionStrings.cs b/Samples/WeatherStation/CS/ConnectionStrings.cs
new file mode 100644
index 000000000..db40378ba
--- /dev/null
+++ b/Samples/WeatherStation/CS/ConnectionStrings.cs
@@ -0,0 +1,11 @@
+using Windows.UI.Xaml.Controls;
+
+namespace WeatherDataReporter
+{
+ public sealed partial class MainPage : Page
+ {
+ static string iotHubUri = "{replace}";
+ static string deviceKey = "{replace}";
+ static string deviceId = "{replace}";
+ }
+}
diff --git a/Samples/WeatherStation/CS/IWeatherDataProvider.cs b/Samples/WeatherStation/CS/IWeatherDataProvider.cs
new file mode 100644
index 000000000..d233a07ca
--- /dev/null
+++ b/Samples/WeatherStation/CS/IWeatherDataProvider.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WeatherDataReporter
+{
+ interface IWeatherDataProvider
+ {
+ double GetTemperature();
+ double GetHumidity();
+ }
+}
diff --git a/Samples/WeatherStation/CS/MainPage.xaml b/Samples/WeatherStation/CS/MainPage.xaml
new file mode 100644
index 000000000..ba9e79341
--- /dev/null
+++ b/Samples/WeatherStation/CS/MainPage.xaml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
diff --git a/Samples/WeatherStation/CS/MainPage.xaml.cs b/Samples/WeatherStation/CS/MainPage.xaml.cs
new file mode 100644
index 000000000..f10d986c1
--- /dev/null
+++ b/Samples/WeatherStation/CS/MainPage.xaml.cs
@@ -0,0 +1,55 @@
+using System;
+using System.Diagnostics;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.Azure.Devices.Client;
+using Newtonsoft.Json;
+using Windows.UI.Xaml.Controls;
+
+namespace WeatherDataReporter
+{
+ public sealed partial class MainPage : Page
+ {
+ static DeviceClient deviceClient;
+
+ public MainPage()
+ {
+ this.InitializeComponent();
+
+ deviceClient = DeviceClient.Create(iotHubUri, AuthenticationMethodFactory.CreateAuthenticationWithRegistrySymmetricKey(deviceId, deviceKey), TransportType.Http1);
+
+ SendDeviceToCloudMessagesAsync();
+ }
+
+ private async void SendDeviceToCloudMessagesAsync()
+ {
+ //var weatherDataprovider = await WeatherDataProvider.Create();
+
+ // Use this if you don't have a real sensor:
+ var weatherDataprovider = await SimulatedWeatherDataProvider.Create();
+
+ while (true)
+ {
+ double currentHumidity = weatherDataprovider.GetHumidity();
+ double currentTemperature = weatherDataprovider.GetTemperature();
+
+ var telemetryDataPoint = new
+ {
+ time = DateTime.Now.ToString(),
+ deviceId = deviceId,
+ currentHumidity = currentHumidity,
+ currentTemperature = currentTemperature
+ };
+ var messageString = JsonConvert.SerializeObject(telemetryDataPoint);
+ var message = new Message(Encoding.ASCII.GetBytes(messageString));
+
+ await deviceClient.SendEventAsync(message);
+ Debug.WriteLine("{0} > Sending message: {1}", DateTime.Now, messageString);
+
+ this.listView.Items.Insert(0, messageString);
+
+ await Task.Delay(1000);
+ }
+ }
+ }
+}
diff --git a/Samples/WeatherStation/CS/Package.appxmanifest b/Samples/WeatherStation/CS/Package.appxmanifest
index 02aecf4cf..8f6b6e692 100644
--- a/Samples/WeatherStation/CS/Package.appxmanifest
+++ b/Samples/WeatherStation/CS/Package.appxmanifest
@@ -1,21 +1,20 @@
-
+
+ IgnorableNamespaces="uap mp">
-
+
- WeatherStation
+ WeatherDataReporter
MSFT
Assets\StoreLogo.png
@@ -29,23 +28,18 @@
-
+
+ Description="WeatherDataReporter"
+ BackgroundColor="transparent">
+
-
-
-
-
-
-
-
diff --git a/Samples/WeatherStation/CS/Properties/AssemblyInfo.cs b/Samples/WeatherStation/CS/Properties/AssemblyInfo.cs
index 84f12554e..7c7c1edf3 100644
--- a/Samples/WeatherStation/CS/Properties/AssemblyInfo.cs
+++ b/Samples/WeatherStation/CS/Properties/AssemblyInfo.cs
@@ -1,18 +1,15 @@
-// Copyright (c) Microsoft. All rights reserved.
-
-
-using System.Reflection;
+using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
-[assembly: AssemblyTitle("WeatherStation")]
+[assembly: AssemblyTitle("WeatherDataReporter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("WeatherStation")]
+[assembly: AssemblyProduct("WeatherDataReporter")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -29,4 +26,4 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
-[assembly: ComVisible(false)]
\ No newline at end of file
+[assembly: ComVisible(false)]
diff --git a/Samples/WeatherStation/CS/README.md b/Samples/WeatherStation/CS/README.md
index d05b46afc..b0c7d027c 100644
--- a/Samples/WeatherStation/CS/README.md
+++ b/Samples/WeatherStation/CS/README.md
@@ -1,13 +1,81 @@
-# Weather Station
+# Azure Weather Station
-Communicate with an I2C/SPI based temperature and pressure sensor
+## Adapted from [here](https://blogs.msdn.microsoft.com/iot/2016/01/26/using-power-bi-to-visualize-sensor-data-from-windows-10-iot-core/).
-Upon executing this sample, you'll have learned how to measure temperature and pressure using I2C/SPI!
+## Introduction
+Building a weather station is the rite of passage for beginning IoT enthusiasts. It's easy to put together from inexpensive components and provides immediate gratification. For example, you can blow air on your sensor and watch the temperature graph spike up or down. You can leave the weather station in your home and monitor humidity and temperature remotely. The list goes on.
-[Each pin on this map](https://adafruitsample.azurewebsites.net/cardViewer?lesson=203) is another maker that has run this sample. Zoom around to see where they are and deploy the sample to put your pin on the map!
+At the same time, the project presents some unique challenges. How do you send the data from your device to the cloud? How do you visualize it in interesting ways? Finally -- how do you make sure you're looking at your data? In other words, how do you reliably authenticate your device?
-![weather-station](../../../Resources/images/AdafruitStarterPack/WeatherStation.jpg)
+## Authenticating a Headless Device
+In a typical OAuth 2.0 authorization flow, the user is presented with a browser window where they can enter their credentials. The application then obtains an access token that is used to communicate with the desired cloud service. Alas, this approach is not suitable for headless IoT devices without the mouse and keyboard attached, or devices that only offer console I/O.
-### Click [here](https://www.hackster.io/windows-iot/weather-station) to get started!
+This problem is solved with the latest version of the Active Directory Authentication Library (still in preview) that introduces a new authentication flow tailored for headless devices. The approach goes like this: when a user authentication is required, instead of bringing up a browser window, the app asks the user to use another device to navigate to [https://aka.ms/devicelogin](https://aka.ms/devicelogin) and enter a specific code. Once the code is provided, the web page will lead the user through a normal authentication experience, including consent prompts and multi factor authentication if necessary. Upon successful authentication, the app will receive the required access tokens through a back channel and use it to access the desired cloud service.
-### If you have v2 of the kit with a BME280 Click [here](https://www.hackster.io/windows-iot/weather-station-v-2-0-8abe16?auth_token=80b912d8d81919969ccab0080ddd8e2f) to get started!
+## Hardware Setup
+For this example, we will use a humidity and temperature sensor, such as the HTU21D, which is available from a number of vendors (e.g., Sparkfun, Amazon).
+
+The sensor connects to your device via I²C bus, as shown on the following wiring diagram (the location of the pins might be slightly different if you're using a device other than Raspberry Pi 2):
+
+![Humidity and temperature sensor](https://msdnshared.blob.core.windows.net/media/2016/01/humidity-htu21d_bb.png)
+
+## Software Setup
+The software setup will require several steps. First, we'll need to register an application in the Azure Active Directory. Then, we'll copy the client ID from the application and use it in our UWP app running on the device. Finally, we'll create a dashboard in Power BI to visualize data coming from our device.
+
+### Registering an Application in Azure
+This step assumes that your organization already has an Azure Active Directory set up. If not, you can get started here.
+
+You can register your application from the Azure Portal, however it's easier to do it from the dedicated Power BI application registration page [here](https://dev.powerbi.com/apps).
+
+Navigate to the above page, log in with your Power BI credentials and fill out the information about your app:
+
+![Power Bi app information](https://msdnshared.blob.core.windows.net/media/2016/01/Register_app_step2.png)
+
+Note that I used a dummy URL for the redirect -- our app will not need this information but we cannot leave this field empty.
+
+In the next step, enable the "Read All Datasets" and "Read and Write All Datasets" APIs and click "Register App".
+
+Once this is done, click "Register App". The web page will generate the Client ID, which looks like this:
+
+![Register your app](https://msdnshared.blob.core.windows.net/media/2016/01/Register_app_step4.png)
+
+Leave the browser page open -- we will need to copy the Client ID and paste it into our C# app.
+
+## Build the App
+The C# app UWP that we're going to use combines the Power BI REST APIs with the use of headless device flow from the Azure Active Directory Library described [here](https://github.com/Azure-Samples/active-directory-dotnet-deviceprofile/).
+
+The full source of the app is available on our GitHub repository [here](https://github.com/ms-iot/samples/tree/develop/Azure/WeatherStation.PowerBI).
+
+To run your application on your device, you need to get the source code and find the clientID constant in PBIClient.cs:
+
+```
+ // WeatherPBIApp: replace with the actual Client ID from the Azure Application:
+ private const string clientID = "";
+```
+
+Replace the value with the string obtained from the registered Azure Application at the previous step and compile the app for ARM architecture. For this app, you will need to connect your Raspberry Pi to a monitor (keyboard and mouse are not required) to display the user code from the device. While this means that the device is no longer completely headless, you might imagine a slightly more advanced version of the app where the user code is communicated via an SMS message, an HTTP POST request, or is displayed on an [LED matrix](https://www.raspberrypi.org/products/sense-hat/).
+
+Deploy the app to your Raspberry Pi. If all goes well, you should see the following:
+
+![Running Raspberry Pi app](https://msdnshared.blob.core.windows.net/media/2016/01/App_running.png)
+
+Now switch to another device -- either a desktop PC or a phone and navigate to the specified URL. Type in the specified user code and press Continue:
+
+![Signing into application](https://msdnshared.blob.core.windows.net/media/2016/01/signin1.png)
+
+Once the user code is accepted, the application will receive the access code and start sending data to Power BI.
+
+### Configure Power BI Dashboard
+Login to your [Power BI account](https://powerbi.microsoft.com/en-us/) and look for the "WeatherReport" dataset in the navigation bar on the left. In the Visualization pane create a "Temperature by Time" line chart:
+
+![Temperature by Time line chart](https://msdnshared.blob.core.windows.net/media/2016/01/TemperaturexTime.png)
+
+You can then create a "Humidity by Time" chart in a similar way. Alternatively, you can plot both temperature and humidity on the same axis.
+
+Now save your report and pin it to the dashboard. You should see something that looks like this:
+
+![Temperature and humidity charts](https://msdnshared.blob.core.windows.net/media/2016/01/dashboard.png)
+
+That's it! Enjoy your weather station!
+
+Want to learn more about using Power BI to visualize sensor data from IoT Core? Read the blog post [here](https://blogs.msdn.microsoft.com/iot/2016/01/26/using-power-bi-to-visualize-sensor-data-from-windows-10-iot-core/).
diff --git a/Samples/WeatherStation/CS/SimulatedWeatherDataProvider.cs b/Samples/WeatherStation/CS/SimulatedWeatherDataProvider.cs
new file mode 100644
index 000000000..5c1b0ee16
--- /dev/null
+++ b/Samples/WeatherStation/CS/SimulatedWeatherDataProvider.cs
@@ -0,0 +1,53 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WeatherDataReporter
+{
+ class SimulatedWeatherDataProvider : IWeatherDataProvider
+ {
+ private int i = 0;
+ private const int delay = 1000;
+ private const int humPeriod = 20 * delay;
+ private const int humMin = 60;
+ private const int humMax = 80;
+
+ private const int tempPeriod = 25 * delay;
+ private const int tempMin = 68;
+ private const int tempMax = 82;
+
+ private static readonly Random rnd = new Random();
+
+ public static Task Create()
+ {
+ return Task.FromResult(new SimulatedWeatherDataProvider());
+ }
+
+ static private double CalculateNextValue(int i, int period, int min, int max)
+ {
+ double x = Math.PI * (((double)i * delay) / period);
+ double val = ((1.0 + Math.Sin(x)) / 2.0) * (max - min) + min;
+
+ // Add random fluctuation
+ if (true)
+ {
+ var delta = (double)rnd.Next(min - max, max - min);
+ val += delta / 20;
+ }
+
+ return val;
+ }
+
+ public double GetHumidity()
+ {
+ return CalculateNextValue(i++, humPeriod, humMin, humMax);
+ }
+
+ public double GetTemperature()
+ {
+ return CalculateNextValue(i++, tempPeriod, tempMin, tempMax);
+ }
+ }
+}
diff --git a/Samples/WeatherStation/CS/StartupTask.cs b/Samples/WeatherStation/CS/StartupTask.cs
deleted file mode 100644
index c383d6392..000000000
--- a/Samples/WeatherStation/CS/StartupTask.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Net.Http;
-using Windows.ApplicationModel.Background;
-using Windows.Devices.I2c;
-using Windows.Devices.Enumeration;
-using Windows.System.Threading;
-
-
-namespace WeatherStation
-{
- public sealed class StartupTask : IBackgroundTask
- {
- BackgroundTaskDeferral deferral;
- private ThreadPoolTimer timer;
- I2cDevice sensor;
-
- public async void Run(IBackgroundTaskInstance taskInstance)
- {
- deferral = taskInstance.GetDeferral();
-
- //Ox40 was determined by looking at the datasheet for the device
- var controller = await I2cController.GetDefaultAsync();
- sensor = controller.GetDevice(new I2cConnectionSettings(0x40));
-
- timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromMilliseconds(500));
-
- }
-
- private void Timer_Tick(ThreadPoolTimer timer)
- {
- //Read temperature and humidity and send result to debugger output window
-
- byte[] tempCommand = new byte[1] { 0xE3 };
- byte[] tempData = new byte[2];
- sensor.WriteRead(tempCommand, tempData);
- var rawTempReading = tempData[0] << 8 | tempData[1];
- var tempRatio = rawTempReading / (float)65536;
- double temperature = (-46.85 + (175.72 * tempRatio)) * 9 / 5 + 32;
- System.Diagnostics.Debug.WriteLine("Temp: " + temperature.ToString());
-
- byte[] humidityCommand = new byte[1] { 0xE5 };
- byte[] humidityData = new byte[2];
- sensor.WriteRead(humidityCommand, humidityData);
- var rawHumidityReading = humidityData[0] << 8 | humidityData[1];
- var humidityRatio = rawHumidityReading / (float)65536;
- double humidity = -6 + (125 * humidityRatio);
- System.Diagnostics.Debug.WriteLine("Humidity: " + humidity.ToString());
-
- }
- }
-}
diff --git a/Samples/WeatherStation/CS/WeatherDataProvider.cs b/Samples/WeatherStation/CS/WeatherDataProvider.cs
new file mode 100644
index 000000000..373372efb
--- /dev/null
+++ b/Samples/WeatherStation/CS/WeatherDataProvider.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Windows.Devices.I2c;
+using Windows.Devices.Enumeration;
+
+namespace WeatherDataReporter
+{
+ class WeatherDataProvider
+ {
+ public static async Task Create()
+ {
+ String aqs = I2cDevice.GetDeviceSelector("I2C1");
+ IReadOnlyList dis = await DeviceInformation.FindAllAsync(aqs);
+ //Ox40 was determined by looking at the datasheet for the device
+ var sensor = await I2cDevice.FromIdAsync(dis[0].Id, new I2cConnectionSettings(0x40));
+ return new WeatherDataProvider(sensor);
+ }
+
+ private I2cDevice sensor;
+
+ private WeatherDataProvider(I2cDevice sensor)
+ {
+ this.sensor = sensor;
+ }
+
+ public double GetHumidity()
+ {
+ byte[] humidityCommand = new byte[1] { 0xE5 };
+ byte[] humidityData = new byte[2];
+ try
+ {
+ sensor.WriteRead(humidityCommand, humidityData);
+ var rawHumidityReading = humidityData[0] << 8 | humidityData[1];
+ var humidityRatio = rawHumidityReading / (float)65536;
+ double humidity = -6 + (125 * humidityRatio);
+ return humidity;
+ }
+ catch (Exception)
+ {
+ return 0.0;
+ }
+ }
+
+ public double GetTemperature()
+ {
+ try
+ {
+ byte[] tempCommand = new byte[1] { 0xE3 };
+ byte[] tempData = new byte[2];
+ sensor.WriteRead(tempCommand, tempData);
+ var rawTempReading = tempData[0] << 8 | tempData[1];
+ var tempRatio = rawTempReading / (float)65536;
+ double temperature = -46.85 + (175.72 * tempRatio);
+ return temperature;
+ }
+ catch (Exception)
+ {
+ return 0.0;
+ }
+ }
+ }
+}
diff --git a/Samples/WeatherStation/CS/WeatherStation.csproj b/Samples/WeatherStation/CS/WeatherDataReporter.csproj
similarity index 81%
rename from Samples/WeatherStation/CS/WeatherStation.csproj
rename to Samples/WeatherStation/CS/WeatherDataReporter.csproj
index be4ddfaa3..5e43e649c 100644
--- a/Samples/WeatherStation/CS/WeatherStation.csproj
+++ b/Samples/WeatherStation/CS/WeatherDataReporter.csproj
@@ -4,11 +4,11 @@
Debug
x86
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}
- winmdobj
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}
+ AppContainerExe
Properties
- WeatherStation
- WeatherStation
+ WeatherDataReporter
+ WeatherDataReporter
en-US
UAP
10.0.17763.0
@@ -17,10 +17,7 @@
true
512
{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- false
- WeatherStation_TemporaryKey.pfx
- true
- true
+ WeatherDataReporter_TemporaryKey.pfx
win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot
@@ -93,14 +90,23 @@
true
-
+
+ App.xaml
+
+
+
+
+ MainPage.xaml
+
+
+
Designer
-
+
@@ -113,9 +119,25 @@
+
+ MSBuild:Compile
+ Designer
+
+
+ MSBuild:Compile
+ Designer
+
+
+
+
+ 1.0.0-preview-005
+
5.0.0
+
+ 8.0.1-beta1
+
14.0
@@ -128,4 +150,4 @@
-->
-
\ No newline at end of file
+
diff --git a/Samples/WeatherStation/CS/WeatherDataReporter.sln b/Samples/WeatherStation/CS/WeatherDataReporter.sln
new file mode 100644
index 000000000..3ef4a10fe
--- /dev/null
+++ b/Samples/WeatherStation/CS/WeatherDataReporter.sln
@@ -0,0 +1,40 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.23107.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WeatherDataReporter", "WeatherDataReporter.csproj", "{89E9D605-9869-4185-83B8-DF321AACE7C7}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|ARM = Debug|ARM
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|ARM = Release|ARM
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Debug|ARM.ActiveCfg = Debug|ARM
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Debug|ARM.Build.0 = Debug|ARM
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Debug|ARM.Deploy.0 = Debug|ARM
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Debug|x64.ActiveCfg = Debug|x64
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Debug|x64.Build.0 = Debug|x64
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Debug|x64.Deploy.0 = Debug|x64
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Debug|x86.ActiveCfg = Debug|x86
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Debug|x86.Build.0 = Debug|x86
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Debug|x86.Deploy.0 = Debug|x86
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Release|ARM.ActiveCfg = Release|ARM
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Release|ARM.Build.0 = Release|ARM
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Release|ARM.Deploy.0 = Release|ARM
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Release|x64.ActiveCfg = Release|x64
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Release|x64.Build.0 = Release|x64
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Release|x64.Deploy.0 = Release|x64
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Release|x86.ActiveCfg = Release|x86
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Release|x86.Build.0 = Release|x86
+ {89E9D605-9869-4185-83B8-DF321AACE7C7}.Release|x86.Deploy.0 = Release|x86
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/Samples/WeatherStation/CS/WeatherStation_TemporaryKey.pfx b/Samples/WeatherStation/CS/WeatherDataReporter_TemporaryKey.pfx
similarity index 100%
rename from Samples/WeatherStation/CS/WeatherStation_TemporaryKey.pfx
rename to Samples/WeatherStation/CS/WeatherDataReporter_TemporaryKey.pfx
diff --git a/Samples/WeatherStation/CS/WeatherStation.sln b/Samples/WeatherStation/CS/WeatherStation.sln
deleted file mode 100644
index a5fcd94ab..000000000
--- a/Samples/WeatherStation/CS/WeatherStation.sln
+++ /dev/null
@@ -1,40 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 14
-VisualStudioVersion = 14.0.22823.1
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WeatherStation", "WeatherStation.csproj", "{B9AFEEE5-701C-4D17-B301-E961C279A19D}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|ARM = Debug|ARM
- Debug|x64 = Debug|x64
- Debug|x86 = Debug|x86
- Release|ARM = Release|ARM
- Release|x64 = Release|x64
- Release|x86 = Release|x86
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Debug|ARM.ActiveCfg = Debug|ARM
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Debug|ARM.Build.0 = Debug|ARM
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Debug|ARM.Deploy.0 = Debug|ARM
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Debug|x64.ActiveCfg = Debug|x64
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Debug|x64.Build.0 = Debug|x64
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Debug|x64.Deploy.0 = Debug|x64
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Debug|x86.ActiveCfg = Debug|x86
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Debug|x86.Build.0 = Debug|x86
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Debug|x86.Deploy.0 = Debug|x86
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Release|ARM.ActiveCfg = Release|ARM
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Release|ARM.Build.0 = Release|ARM
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Release|ARM.Deploy.0 = Release|ARM
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Release|x64.ActiveCfg = Release|x64
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Release|x64.Build.0 = Release|x64
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Release|x64.Deploy.0 = Release|x64
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Release|x86.ActiveCfg = Release|x86
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Release|x86.Build.0 = Release|x86
- {B9AFEEE5-701C-4D17-B301-E961C279A19D}.Release|x86.Deploy.0 = Release|x86
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
diff --git a/Samples/WeatherStation/README.md b/Samples/WeatherStation/README.md
index 725da4502..d62a3aa23 100644
--- a/Samples/WeatherStation/README.md
+++ b/Samples/WeatherStation/README.md
@@ -2,24 +2,90 @@
page_type: sample
urlFragment: weather-station
languages:
- - cpp
- csharp
- - vb
products:
- windows
description: Communicate with an I2C/SPI based temperature and pressure sensor with Windows 10 IoT Core.
---
-# Weather Station
+# Azure Weather Station
-Communicate with an I2C/SPI based temperature and pressure sensor
+## Adapted from [here](https://blogs.msdn.microsoft.com/iot/2016/01/26/using-power-bi-to-visualize-sensor-data-from-windows-10-iot-core/).
-Upon executing this sample, you'll have learned how to measure temperature and pressure using I2C/SPI!
+## Introduction
+Building a weather station is the rite of passage for beginning IoT enthusiasts. It's easy to put together from inexpensive components and provides immediate gratification. For example, you can blow air on your sensor and watch the temperature graph spike up or down. You can leave the weather station in your home and monitor humidity and temperature remotely. The list goes on.
-[Each pin on this map](https://adafruitsample.azurewebsites.net/cardViewer?lesson=203) is another maker that has run this sample. Zoom around to see where they are and deploy the sample to put your pin on the map!
+At the same time, the project presents some unique challenges. How do you send the data from your device to the cloud? How do you visualize it in interesting ways? Finally -- how do you make sure you're looking at your data? In other words, how do you reliably authenticate your device?
-![weather-station](../../Resources/images/AdafruitStarterPack/WeatherStation.jpg)
+## Authenticating a Headless Device
+In a typical OAuth 2.0 authorization flow, the user is presented with a browser window where they can enter their credentials. The application then obtains an access token that is used to communicate with the desired cloud service. Alas, this approach is not suitable for headless IoT devices without the mouse and keyboard attached, or devices that only offer console I/O.
-### Click [here](https://www.hackster.io/windows-iot/weather-station) to get started!
+This problem is solved with the latest version of the Active Directory Authentication Library (still in preview) that introduces a new authentication flow tailored for headless devices. The approach goes like this: when a user authentication is required, instead of bringing up a browser window, the app asks the user to use another device to navigate to [https://aka.ms/devicelogin](https://aka.ms/devicelogin) and enter a specific code. Once the code is provided, the web page will lead the user through a normal authentication experience, including consent prompts and multi factor authentication if necessary. Upon successful authentication, the app will receive the required access tokens through a back channel and use it to access the desired cloud service.
-### If you have v2 of the kit with a BME280 Click [here](https://www.hackster.io/windows-iot/weather-station-v-2-0-8abe16?auth_token=80b912d8d81919969ccab0080ddd8e2f) to get started!
+## Hardware Setup
+For this example, we will use a humidity and temperature sensor, such as the HTU21D, which is available from a number of vendors (e.g., Sparkfun, Amazon).
+
+The sensor connects to your device via I²C bus, as shown on the following wiring diagram (the location of the pins might be slightly different if you're using a device other than Raspberry Pi 2):
+
+![Humidity and temperature sensor](https://msdnshared.blob.core.windows.net/media/2016/01/humidity-htu21d_bb.png)
+
+## Software Setup
+The software setup will require several steps. First, we'll need to register an application in the Azure Active Directory. Then, we'll copy the client ID from the application and use it in our UWP app running on the device. Finally, we'll create a dashboard in Power BI to visualize data coming from our device.
+
+### Registering an Application in Azure
+This step assumes that your organization already has an Azure Active Directory set up. If not, you can get started here.
+
+You can register your application from the Azure Portal, however it's easier to do it from the dedicated Power BI application registration page [here](https://dev.powerbi.com/apps).
+
+Navigate to the above page, log in with your Power BI credentials and fill out the information about your app:
+
+![Power Bi app information](https://msdnshared.blob.core.windows.net/media/2016/01/Register_app_step2.png)
+
+Note that I used a dummy URL for the redirect -- our app will not need this information but we cannot leave this field empty.
+
+In the next step, enable the "Read All Datasets" and "Read and Write All Datasets" APIs and click "Register App".
+
+Once this is done, click "Register App". The web page will generate the Client ID, which looks like this:
+
+![Register your app](https://msdnshared.blob.core.windows.net/media/2016/01/Register_app_step4.png)
+
+Leave the browser page open -- we will need to copy the Client ID and paste it into our C# app.
+
+## Build the App
+The C# app UWP that we're going to use combines the Power BI REST APIs with the use of headless device flow from the Azure Active Directory Library described [here](https://github.com/Azure-Samples/active-directory-dotnet-deviceprofile/).
+
+The full source of the app is available on our GitHub repository [here](https://github.com/ms-iot/samples/tree/develop/Azure/WeatherStation.PowerBI).
+
+To run your application on your device, you need to get the source code and find the clientID constant in PBIClient.cs:
+
+```
+ // WeatherPBIApp: replace with the actual Client ID from the Azure Application:
+ private const string clientID = "";
+```
+
+Replace the value with the string obtained from the registered Azure Application at the previous step and compile the app for ARM architecture. For this app, you will need to connect your Raspberry Pi to a monitor (keyboard and mouse are not required) to display the user code from the device. While this means that the device is no longer completely headless, you might imagine a slightly more advanced version of the app where the user code is communicated via an SMS message, an HTTP POST request, or is displayed on an [LED matrix](https://www.raspberrypi.org/products/sense-hat/).
+
+Deploy the app to your Raspberry Pi. If all goes well, you should see the following:
+
+![Running Raspberry Pi app](https://msdnshared.blob.core.windows.net/media/2016/01/App_running.png)
+
+Now switch to another device -- either a desktop PC or a phone and navigate to the specified URL. Type in the specified user code and press Continue:
+
+![Signing into application](https://msdnshared.blob.core.windows.net/media/2016/01/signin1.png)
+
+Once the user code is accepted, the application will receive the access code and start sending data to Power BI.
+
+### Configure Power BI Dashboard
+Login to your [Power BI account](https://powerbi.microsoft.com/en-us/) and look for the "WeatherReport" dataset in the navigation bar on the left. In the Visualization pane create a "Temperature by Time" line chart:
+
+![Temperature by Time line chart](https://msdnshared.blob.core.windows.net/media/2016/01/TemperaturexTime.png)
+
+You can then create a "Humidity by Time" chart in a similar way. Alternatively, you can plot both temperature and humidity on the same axis.
+
+Now save your report and pin it to the dashboard. You should see something that looks like this:
+
+![Temperature and humidity charts](https://msdnshared.blob.core.windows.net/media/2016/01/dashboard.png)
+
+That's it! Enjoy your weather station!
+
+Want to learn more about using Power BI to visualize sensor data from IoT Core? Read the blog post [here](https://blogs.msdn.microsoft.com/iot/2016/01/26/using-power-bi-to-visualize-sensor-data-from-windows-10-iot-core/).