In my previous post the application uploaded images to an Azure storage account associated with an Azure IoT Hub based on configuration file settings. The application didn’t use any of the Azure IoT Hub device management functionality like device twins and direct methods.

In this version only the Azure IoT hub connection string and protocol to use are stored in the JSON configuration file.
{ "AzureIoTHubConnectionString": "", "TransportType": "Mqtt", }
On startup the application uploads a selection of properties to the Azure IoT Hub to assist with support, fault finding etc.
// This is from the OS reportedProperties["Timezone"] = TimeZoneSettings.CurrentTimeZoneDisplayName; reportedProperties["OSVersion"] = Environment.OSVersion.VersionString; reportedProperties["MachineName"] = Environment.MachineName; reportedProperties["ApplicationDisplayName"] = package.DisplayName; reportedProperties["ApplicationName"] = packageId.Name; reportedProperties["ApplicationVersion"] = string.Format($"{version.Major}.{version.Minor}.{version.Build}.{version.Revision}"); // Unique identifier from the hardware SystemIdentificationInfo systemIdentificationInfo = SystemIdentification.GetSystemIdForPublisher(); using (DataReader reader = DataReader.FromBuffer(systemIdentificationInfo.Id)) { byte[] bytes = new byte[systemIdentificationInfo.Id.Length]; reader.ReadBytes(bytes); reportedProperties["SystemId"] = BitConverter.ToString(bytes); }

The Azure Storage file and folder name formats along with the image capture due and update periods are configured in the DeviceTwin properties. Initially I had some problems with the dynamic property types so had to .ToString and then Timespan.TryParse the periods.
Twin deviceTwin= azureIoTHubClient.GetTwinAsync().Result; if (!deviceTwin.Properties.Desired.Contains("AzureImageFilenameLatestFormat")) { this.logging.LogMessage("DeviceTwin.Properties AzureImageFilenameLatestFormat setting missing", LoggingLevel.Warning); return; } … if (!deviceTwin.Properties.Desired.Contains("ImageUpdateDue") || !TimeSpan.TryParse(deviceTwin.Properties.Desired["ImageUpdateDue"].Value.ToString(), out imageUpdateDue)) { this.logging.LogMessage("DeviceTwin.Properties ImageUpdateDue setting missing or invalid format", LoggingLevel.Warning); return; }

The application also supports two commands “ImageCapture’ and “DeviceReboot”. For testing I used Azure Device Explorer

After running the installer (available from GitHub) the application will create a default configuration file in
\User Folders\LocalAppData\PhotoTimerTriggerAzureIoTHubStorage-uwp_1.2.0.0_arm__nmn3tag1rpsaw\LocalState\
Which can be downloaded, modified then uploaded using the portal file explorer application. If you want to make the application run on device start-up the radio button below needs to be selected.
