I wanted to do timelapse video of some plants growing in a pot on my window sill so I wrote Windows 10 IoT Core Universal Windows Platform (UWP) background task to capture images and store them to the local file system of a Raspberry Pi or DragonBoard 410C devices.
The first version was pretty rough so for the next one I moved all the configuration to a appsettings file and added the ability to format image file and folder names.
By changing the image\folder name format strings I could "bucket" the images by hour\day\month etc. to make management and searching easier.
{
"ImageFilenameFormatLatest": "Current.jpg",
"FolderNameFormatHistory": "Historic{0:yyMMddHH}",
"ImageFilenameFormatHistory": "{0:yyMMddHHmmss}.jpg",
"ImageUpdateDueSeconds": 10,
"ImageUpdatePeriodSeconds": 30
}
When the application starts up for the first time it creates an empy appsettings file that you can download using either Powerhell or the file explorer in the Windows device portal.
I added a real-time clock(RTC) after a device which wasn't connected to a working network was rebooted (which reset the onboard clock) and the image names were incorrect.
I also had problems with a networked device when the time service took a while to wake up and there would be a few incorrectly named images and\or folders after each restart.
Azure Storage BlobsAfter running the program for a while I found managing many files and folders on the device was a bit painfull so I cloned the application and built a new application which uploaded the images to Azure Storage.
The configuration file gained a few extra settings.
{
"AzureStorageConnectionString": "your Azure storage connection string goes here",
"AzureContainerNameFormatLatest": "Current",
"AzureImageFilenameFormatLatest": "{0}.jpg",
"AzureContainerNameFormatHistory": "Historic",
"AzureImageFilenameFormatHistory": "{0}/{2:yyMMddHHmmss}.jpg",
"ImageUpdateDueSeconds": 30,
"ImageUpdatePeriodSeconds": 300
}
The client application creates folders and files as required.
Overall this worked pretty well I just need a better way of stitching the images together to make a video and a more robust mount for the camera.
Azure IoT Hub StorageI have a weather station in my backyard which uploads sensor data to an Azure IoT Hub for processing. (It also uploads data to Azure IoT Central as well.)
I wanted to store the images "nearby" the sensor data to enable easy correlation of weather events with stored images. So I cloned then built a new application which uploads the images to the Azure Storage associated with an Azure IoT Hub.
With this application I decided to reduce the appsettings file to a bare minimum (see note at end of project), and implemented support for monitoring and remote configuration using device properties and settings.
{
"AzureIoTHubConnectionString": "",
"TransportType": "Mqtt"
}
The Azure storage file and folder names along with image capture periods are configured in the DeviceTwin properties.
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;
}
You can configure the device twin properties programmatically, using the Azure IoT Hub portal or a tool like Azure Device explorer.
The Windows 10 IoT Core application implements two commands "ImageCapture" and "Device Reboot"
This project doesn't include details of the installation and configuration of Windows 10 IoT Core or the deployment of applications as this has been covered by other authors.
Make sure to test your configuration as the rules for naming storage containers, folders and files have tripped me up.
I was thinking about adding Trusted Platform Module (TPM) support. I'm also going to build a couple of Azure Cognitive Services Vision Windows 10 IoT Core client applications
Comments