Using the Demo Applications > Firmware Demo
Firmware Demo
Located in the demo/firmware-update-demo subdirectory of the Connector installation, this demo contains resources to realize an Azure IoT use case for firmware updates. The edge code for this demo is sourced from the online Microsoft Azure IoT documentation. That edge demo will work as-is, but the version that is included in the Azure IoT Hub Connector installation makes the following changes:
Connection-string is provided as an argument, rather than hard-coded in the source.
The device ID is pulled from connection string and printed.
Content is downloaded from the provided URL.
The "image" contents is printed when "applying".
The error-handling code has been fixed to work as expected.
Before You Begin
If you used the Appliance demo and have not uninstalled NodeJS or the Azure iothub-explorer tool, you have met the additional requirements. Otherwise, in addition to the general requirements for all demos, make sure that you have installed the following software:
NodeJS (6.9.4+)
Azure iothub-explorer tool (optional)
Setup
To set up this demo, follow these steps:
1. From the demo/firmware-update-demo/platform/entities/ subdirectory of the Connector installation, use ThingWorx Composer to import Entities.xml into the ThingWorx Platform. If you need assistance importing a file, refer to the instructions here, and substitute the Entities.xml file for this demo when choosing the file to import.
2. To initialize the edge code, run npm install from the demo/firmware-update-demo/edge subdirectory of the Connector installation.
3. From ThingWorx Composer, create an Azure IoT Thing, and select the UpdateableFirmwareThing Thing Template as its Base Template.
4. From ThingWorx Composer, navigate to your new Thing, and follow these steps:
a. In the gatewayThing property field of this Thing, enter the name of your AzureIotHub Thing.
b. Create the device in Azure in one of the following ways:
Use the Azure IoT Hub portal.
Navigate to the ConnectionServicesHub Thing in ThingWorx and run the CreateAzureIotDevice service.
5. From ThingWorx Composer, create a FileRepository Thing, using the AzureStorageContainerFileRepository Thing Template. Be sure to name the FileRepository Thing to match the name of a container within the storage account associated with your Connector.
6. To obtain the connection string for the Azure IoT device:
Run iothub-explorer get {DEVICE_ID}
or
From the Azure Portal, navigate as follows: {IOT_HUB} > > > > Device Explorer > {DEVICE_ID} > Connection string -- primary key.
Copy the connection string. Paste it in a text editor and check for semicolons. If it has any semicolons, add single or double-quotation marks around it (single if no other quotation marks, otherwise, double).
* 
The 1.16.1 version of iot-service-client strips the open and close double quotation marks from direct method String payloads (parameters). If you are using this newer version of the iot-service-client, use single quotation marks around a String that contains a semi-colon.
Run
1. Start the edge device from the demo/firmware-update-demo/edge subdirectory, using the connection string you copied, as follows:
node index.js {CONNECTION_STRING}
The output should be
Running device {DEVICE_ID}
Client connected to IoT Hub.
Waiting for firmwareUpdate direct method.
2. In ThingWorx Composer, navigate to the FirmwareUpdate mashup, and select to view the mashup.
3. Choose your Azure IoT Thing from the entity picker.
4. Choose your AzureStorageContainerFileRepository Thing from the entity picker.
5. Supply a path to a file within the container.
A small text file is easiest for this demo. If you do not have one, use the SaveText service on the FileRepository Thing to create one.
6. Click Update on the mashup. As the update proceeds, the mashup will show the content of the firmwareUpdate infotable as the update proceeds.
The output from the edge device follows:
Response to method 'firmwareUpdate' sent successfully.
Device twin acquired.
twin state reported: waiting
twin state reported: downloading
Downloading image from {AZURE_URL} twin state
twin state reported: downloadComplete
twin state reported: applying
Applying image data: {FILE_CONTENTS}
twin state reported: applyComplete