Using the Demo Applications > Appliance Demo
Appliance Demo
The Appliance demonstration showcases several Azure IoT features supported by the Azure IoT Hub Connector. Four different Internet-connected appliances demonstrate:
Pushing properties to the ThingWorx Platform
Updating the Reported field of the device twin
Reacting to changes in the Desired field of the device twin
Using Device Methods
Uploading files
In addition to telemetry data, theAappliance demo includes information to demonstrate integration with an internal or third-party database.
Before You Begin
The demo is available in the /demo/appliance-demo/ subdirectory of the Connector installation. In addition to the general prerequisites for all demos, ensure that the following requirements are met:
From the Azure portal, be sure to specify a storage container called “file-uploads” in the Azure IoT Hub that you created. Select Messaging > File Upload to specify the container. The AzureStorageThingAzureFridge relies on this connection between the hub and storage container.
NodeJS 6.9.4 or later is installed. If you have not already, download and extract the Node.js distribution bundle for version 6.9.4 or later from https://nodejs.org/en/download/package-manager/.
The file, ApplianceDemoEntities.xml, is imported into the ThingWorx Platform. The file is located in demo/appliance-demo/platform/entities subdirectory of the Connector installation. You must import this file into ThingWorx Platform before running any of the demo scripts. If you need assistance with importing a file, refer to the instructions for importing the entities XML file for the Edge Device Demo Client. When selecting the file to import, navigate to ApplianceDemoEntities.xml and select it. Otherwise the instructions are the same.
* 
You must either be an administrator or a user with the appropriate permissions to import a file into ThingWorx Platform. For more information on importing files into ThingWorx Platform, refer to Importing and Exporting Data, Entities, and Extensions.
The following table lists and describes the Thing Templates that are provided with this demo:
Template
Functions
Azure Washer
Indicates how much time remains in each cycle and sub-cycle.
Reports the consumption of detergent, assuming that a full bottle of detergent is pre-loaded and dispenses what is needed for any given load.
Reports the consumption of fabric softener, assuming a pre-loaded bottle dispenses what is needed for each load.
Monitors the temperature of water.
Through a property, may signal out-of-balance during the spin cycle.
Azure Dryer
Monitors how much time remains.
Monitors the internal temperature.
Maintains a count of dryer sheets, assuming pre-loading of sheets.
Azure Dishwasher
Indicates how much time remains in each cycle and sub-cycle.
Maintains a count of detergent pods.
Senses remaining rinse agent level.
Potentially reports any malfunctions to the platform, such as clogged drain, leak, and wash arm blockage.
Azure Refrigerator
Sets the temperatures for the freezer and main part of the refrigerator.
Monitors the temperatures of the refrigerator and freezer.
Monitors the ice-maker for consumption of ice (via a service).
Monitors the opening and closing of the doors, which can affect temperature. This information may lend itself to graphing fluctuations in temperature.
Uploads a file. Specify the file that you want to upload from the device (devices.json, provision.conf, or any other file on “device”)
The demo/appliance-demo/edge subdirectory contains NodeJS scripts for the edge logic. The edge logic uses value streams to send data to ThingWorx Platform.
Setting Up the Demo
Follow these steps to set up the appliance demo:
1. In the Node.js installation, locate the npm (Node Package Manager) utility.
2. From a Command Prompt or shell window, navigate to thedemo/appliance-demo/edge/directory where provision.js is located and run npm install from that directory. Note that you must run npm install from this subdirectory.
3. Log in to ThingWorx Composer.
4. Select and Things in the left navigation panel, and navigate to each appliance Thing that the import created.
5. For each appliance Thing, follow these steps:
a. In the gatewayThing property field of each 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.
6. From the demo/appliance-demo/edge subdirectory of the Connector installation, open the provision.conf file in a text editor. Edit this file so that it contains the appropriate information for the ThingWorx Platform instance (the URL for the instance and the application key for the Connector to use to access the instance) and for the Azure IoT Hub to which you are connecting (the host name of the hub and the name and key of the registry policy). For example:
/{
"twx-platform" : {
"protocol": "http",
"host" : "twx host",
"app-key" : "<your app-key>",
"port" : "twx port",
"inventory-table-name" : "ApplianceInventory"
},
"azure" : {
"hub-hostname" : "some-hub-name.azure-devices.net",
"registry-policy-name" : "registryReadWrite",
"registry-policy-key": "your hub's registryReadWrite policy key"
}
}
7. From a Command Prompt (Windows) or a shell (Linux), navigate to the demo/appliance-demo/edge subdirectory of the Connector installation, and run the provision.js script, passing the provision.conf file name and the devices.json file name.
The following example shows the expected output of the script as it runs:
> node provision.js provision.conf devices.json
Created device: TestFridge1
Updated device: 01-0111111 AzureFridge
Imported TestFridge1 AzureFridge
Imported TestFridge1
Created device: TestWasher1
Updated device: 01-0222222 AzureWasher
Imported TestWasher1 AzureWasher
Imported TestWasher1
Created device: TestDryer1
Updated device: 01-0333333 AzureDryer
Imported TestDryer1 AzureDryer
Imported TestDryer1
Created device: TestDishwasher1
Updated device: 01-0444444 AzureDishwasher
Imported TestDishwasher1 AzureDishwasher
Imported TestDishwasher1
After the script completes, you might notice that four .key files have been created, one for each device. These key files are used to start the devices with the next script.
* 
You will receive errors if the devices have already been created in your hub, but if you already have entries in your ApplianceInventory, those errors are ignored.
8. From ThingWorx Composer, navigate to each appliance Thing the script created, and follow these steps for each Thing:
a. In the gatewayThing property field of each 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.
9. Start up the appliances with the start.js script. Here is an example of starting the appliances and the resulting output from the script:
> node start.js
TestDishwasher1 ready: SN#01-0444444 AzureDishwasher
TestDryer1 ready: SN#01-0333333 AzureDryer
TestFridge1 ready: SN#01-0111111 AzureFridge
TestWasher1 ready: SN#01-0222222 AzureWasher
TestWasher1 sent {"cycleName":"Stopped","cycleTimeRemaining":0,
"subCycleName":"Stopped","subCycleTimeRemaining":0,"softenerLevel":55,
"detergentLevel":20,"waterTemp":0,"outOfBalance":false}
TestDishwasher1 sent {"currentCycle":"Stopped","cycleTimeRemaining":0,
"currentSubCycle":"Stopped","subCycleTimeRemaining":0,
"detergentPodsRemaining":85,"rinseAgentLevel":50,
"washArmImpeded":false,"drainClogged":false,"leakDetected":false}
TestDryer1 sent {"currentCycle":"Stopped","cycleTimeRemaining":0,
"dryerSheetsRemaining":6,"temperature":0}
TestFridge1 sent {"fridgeTemp":42,"freezerTemp":10,
"waterFilterLastChanged":1485010826052,"iceLevel":30,
"freezerTempSetPoint":10,"fridgeTempSetPoint":42,"doorOpen":false}

etc...
At this point the demo is running and you should be able to watch data arriving on ThingWorx Platform.
The AzureIotThing Template contains three JSON properties that contain current values of the device twin data, divided up into three pieces. They are twinDesired, twinReported, and twinTags. These fields are not pushed via ingress. Only twinDesired and twinTags can be modified from ThingWorx Composer.
* 
You can modify some remote properties of appliance Things from ThingWorx by going to the Properties page of the Thing that represents your Azure IoT Edge device or Azure IoT Device, and setting them or by using services available on that Thing.
Other properties are read-only. To update the values shown in ThingWorx Composer for properties, click Refresh or reload the Thing. Keep in mind that the properties are managed with the Azure IoT Services SDK.
What Else to Explore and Try
You may want to invoke services to monitor properties and their values as well as the devices in the ApplianceInventory:
Each device has a set of properties associated with the CustomerAppliance Data Shape. These properties include the model, serial number, purchase date, and contract type for each appliance. They become visible only after invoking the FetchApplianceInventoryData service on each Thing.
You can view all the devices in the ApplianceInventory by opening up the ApplianceInventory table Thing (under DataTables) and executing the GetDataTableEntries service.
The twinReported field contains the serial number and the name of the Thing Template used to create the Thing. The serial number is used in conjunction with the FetchApplianIoceInventoryData service to grab data from the table and populate properties of the Thing.