gina
gina

Reputation: 179

How to use configuration settings in a Universal Windows App

I have an universal windows app which is deployed to Raspberry PI 3 with windows iOT Core, the PI 3 can have many sensors connected, therefore those sensors need to be registered with Azure IOT Hub, in order to do that I register them manually with Device Explorer, and then on an XML file I created, I put the Device Key and other configuration settings.

In that way the PI can use the DeviceKey from the config file, and the sensor reading and then send the data to the IOT HUB.

Piece of cake it works fine.

However I dont know if this way of configuration is the best practice for universal windows app, first than all, I dont know how to edit that XML file before installing the package, or after its installed I dont know where to find the file and edit it before the app runs.

Question is simple: is this best practice or not? if Yes how can I edit that file before deploying, please remember that the same app will be installed on 100 devices and the XML file will be different, If no,, what is the best practice?

Upvotes: 2

Views: 644

Answers (3)

Rita Han
Rita Han

Reputation: 9700

I agree with @Snake Chia.

And maybe you can try this practice:

Share one device in IOT HUB and you need only one set of configuration settings, so don't need to edit the configuration file while deploying the app. Using one data field of the message to distinguish different sensors. In Azure side, Azure Stream Analytics can help you to process data from sensor devices.

Upvotes: 1

David Jones
David Jones

Reputation: 582

Use TPM for security/credentials as this extracts connectivity credentials from the device, once it is configured on the device, without needing any device specific coding (ie no connection string). Eg about halfway along in this video: Channel9

Upvotes: 3

Snake Chia
Snake Chia

Reputation: 181

My practice is this:

I will have a "Registration Function" embedded in UWP apps for RPi3, when the apps start, it will detect if the devicekey is save locally or not, if not it will initialized the registration process, else it continue what it should be doing.

I will embedded the general information for registration in the UWP apps, when the process being trigger, it will connect to Azure IoT Hub to retrieve the list of devices, and randomly (not that random too) generate the "devicename" and "devicekey", register the newly generate device with Azure IoT Hub. Do remember to save the "devicename" and "devicekey" in your RPi3 so you can communicate with the device.

I did one step more which is, I will have an UI for RPi3, when I connect the RPi3 to a monitor, I can have an option to "reset" the device, so it will "delete" and "unregister" itself from Azure IoT Hub and re-launch the registration process again.

Hope this will help.

Upvotes: 4

Related Questions