Run a simple C# sample on B&R APC device running Windows 10
Table of Contents
- Introduction
- Step 1: Sign Up To Azure IoT Hub
- Step 2: Register Device
- Step 3: Build and Validate the Sample using C# Client Libraries
- Step 4: Troubleshooting
Introduction
About this document
This multi-step process includes:
- Configuring Azure IoT Hub
- Registering your IoT device
- Build and deploy Azure IoT SDK on device
- Packaging and sharing the logs
Prepare
Before executing any of the steps below, read through each process, step by step to ensure end to end understanding.
You should have the following items ready before beginning the process:
- Computer with GitHub installed and access to the azure-iot-sdk-csharp GitHub public repository.
-
Install Visual Studio 2015 and Tools. You can install any edition of Visual Studio, including the free Community edition.
Make sure to select the “Universal Windows App Development Tools”, the component required for writing apps Windows 10:
-
Required hardware running Windows 10 IoT Core to certify
Note: If you need assistance installing Windows 10 IoT Core , please visit https://www.windowsondevices.com or contact us at iotcert@microsoft.com
Step 1: Sign Up To Azure IoT Hub
Follow the instructions here on how to sign up to the Azure IoT Hub service.
As part of the sign up process, you will receive the connection string.
-
IoT Hub Connection String: An example of IoT Hub Connection String is as below:
HostName=[YourIoTHubName];SharedAccessKeyName=[YourAccessKeyName];SharedAccessKey=[YourAccessKey]
Step 2: Register Device
In this section, you will register your device using DeviceExplorer. The DeviceExplorer is a Windows application that interfaces with Azure IoT Hub and can perform the following operations:
- Device management
- Create new devices
- List existing devices and expose device properties stored on Device Hub
- Provides ability to update device keys
- Provides ability to delete a device
- Monitoring events from your device
- Sending messages to your device
To run DeviceExplorer tool, use following configuration string as described in Step1:
- IoT Hub Connection String
Steps:
-
Click here to download and install DeviceExplorer.
-
Add connection information under the Configuration tab and click the Update button.
-
Create and register the device with your IoT Hub using instructions as below.
a. Click the Management tab.
b. Your registered devices will be visible in the list. In case your device is not there in the list, click Refresh button. If this is your first time, then you shouldn’t retrieve anything.
c. Click Create button to create a device ID and key.
d. Once created successfully, device will be listed in DeviceExplorer.
e. Right click the device and from context menu select “Copy connection string for selected device”.
f. Save this information in Notepad. You will need this information in later steps.
Not running Windows on your PC? - Please follow the instructions here to provision your device and get its credentials.
Step 3: Build and Validate the Sample using C# Client Libraries
This section walks you through building, deploying and validating the IoT Client SDK on your device running Windows 10 IoT Core operating system. You will install the necessary prerequisites on your device. Once done, you will build and deploy the IoT Client SDK, and validate the sample tests required for IoT certification with the Azure IoT SDK.
3.1 Connect the Device
-
Connect the board to your network using an Ethernet cable. This step is required, as the sample depends on internet access.
-
Plug the device into your computer using a micro-USB cable.
3.2 Build the Samples
-
Clone Azure IoT SDK repository to your machine.
-
Start a new instance of Visual Studio 2015. Open the iothub_csharp_deviceclient.sln solution (/azure-iot-sdk-csharp/device) from your local copy of the repository.
-
In Visual Studio, from Solution Explorer, navigate to the UWPSample(Universal Windows) project.
-
Locate the following code in the ConnectionStrings.cs file:
public const string DeviceConnectionString = "<replace>";
-
Replace
<replace>
with the connection string for your device and Save the changes. You can get the connection string from DeviceExplorer as explained in Step 2. -
Choose the right architecture (x86 or ARM, depending on your device) and set the debugging method to “Remote Machine”:
-
To deploy the binaries on your device, right-click on the UWPSample project in the Solution Explorer, select Properties and navigate to the Debug tab:
Type in the name of your device. Make sure the “Use authentication” box is unchecked.
-
Build the solution.
3.3 Run and Validate the Samples
In this section you will run the Azure IoT client SDK samples to validate the communication between your device and Azure IoT Hub. You will send the messages to the Azure IoT Hub service and validate that IoT Hub has successfully receive the data. You will also monitor any messages sent from the Azure IoT Hub to client.
3.3.1 Send Device Events to IoT Hub
-
Launch the DeviceExplorer as explained in Step 2 and navigate to Data tab. Select the device name you created from the drop-down list of device IDs and click Monitor button.
-
DeviceExplorer is now monitoring data sent from the selected device to the IoT Hub.
-
In Visual Studio, from Solution Explorer, right-click the UWPSample(Universal Windows) project, click Debug −> Start new instance to build and run the sample.
-
You should be able to see the events received in the DeviceExplorer’s data tab.
3.3.2 Receive messages from IoT Hub
-
To verify that you can send messages from the IoT Hub to your device, go to the Messages to Device tab in DeviceExplorer.
-
Select the device you created using Device ID drop down.
-
Add some text to the Message field, then click Send.
-
You should be able to see the message received in the device console window.
Step 4: Troubleshooting
Please contact engineering support on support@br-automation.com for help with troubleshooting.
Reference: Some information in this document is obtained from here.