Azure / iot-plug-and-play-bridge

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

Can't get PnP Modelled Telemetry when can set Properties and action commands [BUG] #78

Closed djaus2 closed 1 year ago

djaus2 commented 3 years ago

Describe the bug In Azure IoT Explorer on the IoT Plug and Play Components tab, Telemetry doesn't show any results. Telemetry does though work from the menu on left. Properties(Writeable) and Commands both on the IoT Plug and Play components tab do work as well. Using the Arduino Serial Sample.

So the question is how to get the modeled schema for Telemetry working in Azure IoT Explorer?

To Reproduce Steps to reproduce the behavior: 1.Build or download the PnPBridge_bin app (on Windowsx64)

  1. build and deploy the Arduino Serial Sample to an Arduino Uno connected to teh dev machine via USB
  2. Get the config.json and set the correct Com Port and Hub-Device connection string. 4.Run the app .\PnPBridge_bin .\config.json.'
  3. Run the Azure IoT Explorer and connect the Hub-Device
  4. Go to the Telemetry lab (left menu) and run it.
  5. Go to the IoT Plug and Play components tab
  6. Configure the schema file to be local and point to folder where you have it on the dev machine
  7. Choose Default Component, then check the Interface, which should match the schema.
  8. Choose Telemetry from that tab, and run it
  9. Select Show modeled events

Expected behavior In 6. should see telemetry In 10. Should see telemetry similar to 6. In11. Should see the modeled data.

Screenshots In 6.:

{
  "body": {
    "temperature": 12.34
  },
  "enqueuedTime": "Fri Sep 10 2021 13:27:13 GMT+1000 (Australian Eastern Standard Time)",
  "properties": {}
}

Output on bridge app:

Info: Starting Azure PnpBridge
Info: Pnp Bridge is running as an IoT Egde device.
Info: Pnp Bridge creation succeeded.
Info: Connection_type is [connection_string]
Info: Tracing is disabled
Info: IoT Edge Device configuration initialized successfully
Info: Building Pnp Bridge Adapter Manager, Adapters & Components
Info: Pnp Adapter with adapter ID serial-pnp-interface has been created. 
Info: Pnp Adapter Manager created successfully.
Info: Opening com port COM4
Info: Pnp components created successfully.
Info: Pnp components built in model successfully.
Info: Sent reset request
Info: Receieved reset response
Info: Sent descriptor request
Info: Connected to Azure IoT Hub
Info: Receieved descriptor response, of length 348
Info: Device Version : 1
Info: Device Name    : Example Thermometer
Info: Interface ID : http://contoso.com/thermometer_example
Info:   Property type : 3
Info:   Name : temperature
Info:   Display Name : Ambient Temperature
Info:   Description : A sample of the ambient temperature.
Info:   Unit : celsius
Info:   Property type : 2
Info:   Name : sample_rate
Info:   Display Name : Sample Rate
Info:   Description : Sample Rate of temperature measurements
Info:   Unit : ms
Info:   Property type : 1
Info:   Name : calibrate
Info:   Display Name : Calibrate Temperature
Info:   Description : Calibrates the thermometer
Info:   Property type : 1
Info:   Name : toggle_state
Info:   Display Name : Toggle State
Info:   Description : Pauses/Unpauses the Telemetry
Info: Pnp components started successfully.
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 = 3333
Info: Setting property sample_rate to 3333
Info: Serial Pnp Adapter: Sending device information property to IoTHub. propertyName=sample_rate, propertyValue=3333
Info: Serial Pnp Adapter: Got Property Update Notification. propertyName=sample_rate
Info: temperature: 12.340000
Info: PnpBridge_PnpBridgeStateTelemetryCallback called, result=0, telemetry=PnpBridge configuration complete
Info: SerialDataSendEventCallback called, result=0, telemetry=temperature
Info: temperature: 12.340000
Info: SerialDataSendEventCallback called, result=0, telemetry=temperature
Info: temperature: 12.340000
Info: SerialDataSendEventCallback called, result=0, telemetry=temperature
Info: temperature: 12.340000
Info: SerialDataSendEventCallback called, result=0, telemetry=temperature
Info: temperature: 12.340000

Nb: I am actually using a fork of the the bridge at djaus2/iot-plug-and-play-bridge that has enabled the Property Updates and Commands to work with the Arduino device when exercised from IoT Explorer. But this problem exists as well with the unforked bridge with the Arduino device and teh following config and schema files.

Desktop (please complete the following information):

Additional context Running built app in iot-plug-and-play-bridge\pnpbridge\cmake\pnpbridge_x86\src\pnpbridge\samples\console\Debug

config.json is location there:

{

    "$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=HubPnP3.azure-devices.net;DeviceId=PnPDev3",
        "root_interface_model_id": "dtmi:com:contoso:serialpnp;1",
        "auth_parameters": 
        {
            "auth_type": "symmetric_key",
            "symmetric_key": "q+6OU6byhvpT9zU3Mbr6KhR8Ur47zEa/EFyM8fEHHMU="
        }
    },
    "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": {
                    "temperature":
                    {
                        "name": "temperature",
                        "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"
                            }
                        }
                    }
                }
            }
        }
    }
}

the schema file **arduino-serial-grove.json locally:


{
    "@context": "dtmi:dtdl:context;2",
    "@id": "dtmi:com:contoso:serialpnp;1",
    "@type": "Interface",
    "displayName": "Pnp Bridge Root Interface Model serialpnp",
    "description": "Arduino Serial PnP",
    "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",
        "description": "Calibrates the thermometer.",
        "commandType": "synchronous",
        "request": {
            "name": "input",
            "schema": "integer"
        },
        "response": {
          "name": "calibrateResponse",
          "schema": "integer"
        }  
      }
    ]

}
djaus2 commented 3 years ago

Note I have simplified config.json somewhat as there is only one component. Also the config.json points (first line) to the local copy of the schema as above.

Also I have posted this question on Azure IoT Explorer repository here This has the updated config.json

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.