Azure / iot-plug-and-play-bridge

IoT Plug and Play bridge
Other
60 stars 28 forks source link

Problems with PropertyUpdate and Commands #77

Closed djaus2 closed 1 year ago

djaus2 commented 3 years ago

Describe the bug With the Arduino Serial Sample, the PropertyUpdate and Commands, when exercised from Azure IoTExplorer do not work. There is some code that uses a NULL for the component in both cases which means the Callbacks to the device don't get actioned by the Bridge.

To Reproduce Steps to reproduce the behavior:

  1. Build the Bridge
  2. Create and IoTHub and configure a config.json and schema for it
  3. Build and deploy the Arduino Serial Sample'
  4. Run the Bridge using the using the config.json
  5. Run AzureIoTExplorer and connect to the Hub
  6. Set schema to the local schema file.

Expected behavior In AzureIOTHub expect to action Properties and Commands and see messages in Bridge Console saying its happened, and impacted upon the Arduino App. Examples when it works:

PropertyUpdate:

Info: Processing property update for the device or module twin
Info: Received PnP property update for component=serialpnp, property=sample_rate
Info: Serial Pnp Adapter: Processed property. PropertyUpdated = 3000
Info: Setting property sample_rate to 3000
Info: Serial Pnp Adapter: Sending device information property to IoTHub. propertyName=sample_rate, propertyValue=3000
Info: Serial Pnp Adapter: Got Property Update Notification. propertyName=sample_rate

Command

Info: Number of components in model=1. Using first: serialpnp
Info: Received PnP command for component=serialpnp, command=calibrate
Info: Invoking command calibrate to 3
Info: Command was processed.

Outcome with existing code Both don't happen.

Desktop (please complete the following information):

Additional context As discussed in More issues with the Arduino Serial example #74

In both cases the index for the string array ComponentsInModel used,is zero. Zero is "arbitrary" (but a good guess, there should be at least one), particularly with Commands Also the comment "its not a model the application knows about, this is a property of the model's root component" needs resolution.

config.json

{

    "$schema": "../../iot-plug-and-play-bridge/pnpbridge/src/pnpbridge/src/pnpbridge_config_schema.json",
    "pnp_bridge_connection_parameters": 
    {
        "connection_type" : "connection_string",
        "connection_string" : "HostName=HubPnP2.azure-devices.net;DeviceId=PnPDev2",
        "root_interface_model_id": "dtmi:com:contoso:serialpnp;1",
        "auth_parameters": 
        {
            "auth_type": "symmetric_key",
            "symmetric_key": "Aw6w8ax677Ovgp4FXDaxcEiLJfVsbAjR+cvudt/oKqE="
        }
    },
    "pnp_bridge_debug_trace": false,
    "pnp_bridge_config_source": "local",
    "_comment_devices": "Array of devices for Azure Pnp interface should be published",
    "pnp_bridge_interface_components": 
    [
        {
            "_comment": "Grove Beginner Kit for Arduino Sensors and Actuators Device Component",
            "pnp_bridge_component_name": "serialpnp",
            "pnp_bridge_adapter_id": "serial-pnp-interface",
            "pnp_bridge_adapter_config": 
            {
                "com_port": "COM4",
                "_comment": "NOTE: com_port parameter will NOT be used when use_com_device_interface is set to true. In case of windows iot edition, the COMXX symbolic links are not created. Setting use_com_device_interface to false will pick the first available COM interface.",
                "use_com_device_interface": "false",
                "baud_rate": "115200"
            }
        }
    ],
    "pnp_bridge_adapter_global_configs": 
    {
        "serial-pnp-interface": {
            "DjAus" : {
                "company_id": "0x499",
                "endianness": "big",
                "telemetry_descriptor": [
                    {
                        "telemetry_name": "temperature",
                        "displayName":"Temperature",
                        "data_parse_type": "decimal",
                        "conversion_bias": 0,
                        "conversion_coefficient": 1.0
                    }
                ],
                "properties": {
                    "sample_rate": {
                        "name": "sample_rate",
                        "displayName":"Sample Rate",
                        "dataType": "integer",
                        "required": true
                    }
                },
                "commands": {
                    "calibrate": {
                        "commandType": "synchronous",
                        "request":
                        {
                            "dataType": "integer"
                        },
                        "response":
                        {
                            "dataType": "integer"
                        }
                    },
                    "toggle_state": {
                        "commandType": "synchronous",
                        "request":
                        {
                            "dataType": "integer"
                        },
                        "response":
                        {
                            "dataType": "integer"
                        }
                    }
                }
            }
        }
    }
}

Schema.json


{
  "@context": "dtmi:dtdl:context;2",
  "@id": "dtmi:com:contoso:serialpnp;1",
  "@type": "Interface",
  "displayName": "Pnp Bridge Root Interface Model serialpnp",
  "description": "Arduino Serial PnP",
  "comment": "Serial PnP for Arduino",

  "contents": [
    {
      "@type": "Property",
      "displayName": "Sample Rate",
      "description": "Rate of temperature readings.",
      "name": "sample_rate",
      "schema": "integer",
      "writable": true
    },
    {
      "@type": [
      "Telemetry",
      "Temperature"
      ],
      "description": "Current temperature on the device",
      "displayName": "Temperature",
      "name": "temperature",
      "schema": "float",
      "unit": "degreeCelsius"
    },
    {
      "@type": "Command",
      "name": "calibrate",
      "description": "Calibrates the thermometer.",
      "commandType": "synchronous",
      "request": {
          "name": "input",
          "schema": "integer"
      },
      "response": {
        "name": "calibrateResponse",
        "schema": "integer"
      }  
    },
    {
      "@type": "Command",
      "name": "toggle_state",
      "comment": "Enable-disable sampling.",
      "commandType": "synchronous" ,
      "request": {
        "name": "input",
        "schema": "integer"
      },
      "response": {
        "name": "output",
        "schema": "integer"
      }  
    }
  ]

}
usivagna commented 1 year ago

Thank you for your interest in the IoT Plug and Play bridge, unfortunately due to new innovations in Azure IoT and changes in product strategy we have come to the decision to deprecate the IoT Plug and Play bridge. Thank you to the community for your support on this journey. The repo is planned to be archived as a read-only repository on November 30th 2023. Thank you to everyone who contributed bug fixes and new adapters for connecting devices with IoT Plug and Play. You can find the latest IoT innovations at https://techcommunity.microsoft.com/t5/internet-of-things-blog/bg-p/IoTBlog. Please note that any use of archived repositories introduces more risks from a security standpoint and should be done with caution.