6 Replies Latest reply on Jul 28, 2017 6:23 PM by sharmon RSS
    sharmon Creator

    How To Manage Remote/Source Bindings w/ a New AzureIotThing

    How do you manage remote property bindings for a new Thing that's based on the AzureIotThing Template?

     

    I've tried two methods for getting Things into my ThingWorx instance:

    • Starting the data flowing to the Azure IoT Hub, and then using the ImportAzureIoTDevices service of the ConnectionServicesHub. This successfully creates a Thing, but doesn't bind any remote properties.
    • Creating a Thing in my ThingWorx instance first, making sure it implements AzureIoTThing, and that it has all the expected properties.

     

    I'm not successful in my mapping of the remote Azure properties to my local Thing properties yet, however.

     

    More details:

     

    Here's a Thing representing a Blue Pump. It implements AzureIotThing (via Azure.Test.BluePumpTemplate) and a shape that matches all the properties my simulator sends up:

     

    BluePump007-General.png

    BluePump007-Properties.png

    I'm sending the following data via a simulator through my Azure IoT Hub:

    13:58:37.721 [main] INFO  c.t.p.a.i.d.AzureIotEdgeDeviceDemo - Sending event: message={"temperature":178.4,"RPM":3500,"PumpID":"Blue Pump 7","Color":"Blue"}
    13:58:37.799 [pool-3-thread-1] INFO  c.t.p.a.i.d.AzureIotEdgeDeviceDemo - Send event response: status=OK_EMPTY
    13:58:42.800 [main] INFO  c.t.p.a.i.d.AzureIotEdgeDeviceDemo - Sending event: message={"temperature":178.4,"RPM":3500,"PumpID":"Blue Pump 7","Color":"Blue"}
    13:58:42.878 [pool-3-thread-2] INFO  c.t.p.a.i.d.AzureIotEdgeDeviceDemo - Send event response: status=OK_EMPTY
    13:58:47.883 [main] INFO  c.t.p.a.i.d.AzureIotEdgeDeviceDemo - Sending event: message={"temperature":178.4,"RPM":3500,"PumpID":"Blue Pump 7","Color":"Blue"}
    13:58:47.961 [pool-3-thread-2] INFO  c.t.p.a.i.d.AzureIotEdgeDeviceDemo - Send event response: status=OK_EMPTY
    

     

    I've verified that my simulator is sending messages successfully to my Azure IoT Hub. Here's its Device Twin up in Azure:

     

    {
      "deviceId": "BluePump007",
      "etag": "AAAAAAAAAAE=",
      "properties": {
        "desired": {
          "$metadata": {
            "$lastUpdated": "2017-07-28T17:56:27.2307635Z"
          },
          "$version": 1
        },
        "reported": {
          "$metadata": {
            "$lastUpdated": "2017-07-28T17:56:27.2307635Z"
          },
          "$version": 1
        }
      }
    }
    

     

    I don't know how to map my remote Azure properties to my ThingWorx Thing properties, though. Here's my, 'manage bindings,' dialog:

     

    BluePump007-Manage-Bindings.png

     

    How do I get my remote bindings mapped?

      • Re: How To Manage Remote Bindings w/ a New AzureIotThing
        ekobyakov-2 Explorer

        AzureIoTThing is not RemoteThing so it does not support GetMetadata() service that is required for remote bindings. When you import things from Azure IoT registry you can optionally specify what shapes to add to created things.

          • Re: How To Manage Remote Bindings w/ a New AzureIotThing
            sharmon Creator

            When you do the import, with a shape included, does it bind similarly-named properties together?

              • Re: How To Manage Remote Bindings w/ a New AzureIotThing
                ekobyakov-2 Explorer

                I am not sure what you mean by that. It just adds that shape to the thing. When message arrives for that thing with properties they are set on the platform using property name or remote property name.

                  • Re: How To Manage Remote Bindings w/ a New AzureIotThing
                    sharmon Creator

                    Here's what I'm asking. This is the, "Manage Property Bindings," dialog from the TestDishwasher1 Thing from the appliance demo:

                    TestDishwasher1-Properties.png

                    Here's the same dialog for my BluePump007 thing:

                    BluePunp007-Property-Binding.png

                    The entities from the demo come out of the import with Source/Remote Bindings already made. Mine doesn't have any. I'm not seeing my properties change.

                     

                    How do I make those bindings happen?

                      • Re: How To Manage Remote/Source Bindings w/ a New AzureIotThing
                        ekobyakov-2 Explorer

                        For appliance demo they come from the imported model data included with the demo. You should be able to edit property and give it remote name

                          • Re: How To Manage Remote/Source Bindings w/ a New AzureIotThing
                            sharmon Creator

                            There's More Than One Way To Do It (TMTOWTDI), but this is what works for me, every time. In this method of connecting a ThingWorx Thing to an Azure device, we're going to work from the ThingWorx side first, and create a device in Azure when we're done.


                            First, start fresh on the Azure side by going to the Device Explorer and deleting your device:

                            Azure-Device Explorer.png

                            Then, start building your Thing in ThingWorx. I think it's a best practice to group properties in a Thing Shape, so that's my first step. My Raspberry Pi will be sending four properties. I'll start adding them, one-by-one, making sure they're remote properties:

                            remote-properties.png

                            I like to give my property a remote name that matches the name I'll be sending up from the Raspberry Pi (or simulator, or whatever). This is not required, but it gives a good belt-and-suspenders feeling:

                            Remote-name.png

                             

                            You can accept defaults for most of the properties. This is what my Thing Shape looks like, once it's complete:

                            Completed-Thing-Shape.png

                            My next step is to create a Thing Template. The most important part of this step is to make sure it uses AzureIotThing as a Base Thing Template (or a Thing Template derived from AzureIotThing). You also want to make sure to implement the Thing Shape you just worked so hard on:

                            ThingTemplate.png

                            Finally, create your Thing. Make to use the Thing Template you just created the Base Thing Template, and you'll get all those sweet, sweet remote properties for free. Make sure you name your Thing with the same Device ID you're sending to the Azure IoT Hub:

                            Complete-Thing.png

                            The next step is where I make sure my Azure and ThingWorx are talking to each other (you're already running a properly-configured Azure IoT Hub Connector, right? Right?). Find the ConnectionServicesHub Thing that was imported when you installed the Azure Extension Package. Go to Services and select the, "CreateAzureIotDevice," service. Run it with the test button, and use the name of the Thing you just created as the thingName parameter:

                            CreateAzureIotDevice-Service.png

                             

                            This will create a device over on your Azure IoT Hub and associate the ThingWorx Thing with it. Try sending some data while watching your Thing's properties. They should update as expected. If they don't, try restarting your Azure IoT Hub Connector and trying again.

                             

                            Enjoy sending that data through your Azure IoT Hub to ThingWorx!