Azure / iot-plug-and-play-bridge

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

Getting Arduino Example to work .. Specifyimg the COM Port #66

Closed djaus2 closed 3 years ago

djaus2 commented 3 years ago

Enter your question here: Arduino sample builds and runs OK.. Can see telemetry in in Arduino Serial Monitor. Have created and conncted to Azure Iot Hub/Device. Bridge app conncts Ok

My question is how to specify the Serial connection (in my case COM7) in config.json Is there as list somewhere of that part of config.json. OK can see for Bluetooth but want to use COM Port..

This part:


  "pnp_bridge_config_source": "local",
  "_comment_devices": "Array of devices for Azure Pnp interface should be published",
  "pnp_bridge_interface_components": [
      {
          "_comment": "Environment Sensor Device Component",
          "pnp_bridge_component_name": "environmentalSensor",
          "pnp_bridge_adapter_id": "environment-sensor-sample-pnp-adapter",
          "pnp_bridge_adapter_config": {
              "sensor_id": "10"
          }
      }
  ]```
djaus2 commented 3 years ago

This is the current ouput:

S C:\Temp\pnp> .\pnp

Info: 
 -- Press Ctrl+C to stop PnpBridge

Info: Using default configuration location
Info: Starting Azure PnpBridge
Info: Pnp Bridge is running as am 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: Adapter with identity environment-sensor-sample-pnp-adapter does not have any associated global parameters. Proceeding with adapter creation.
Info: Pnp Adapter with adapter ID environment-sensor-sample-pnp-adapter has been created.
Info: Pnp Adapter Manager created successfully.
Info: Pnp components created successfully.
Info: Pnp components built in model successfully.
Info: Connected to Azure IoT Hub
Info: Environmental Sensor: Starting Pnp Component
Info: IoTHub client call to _SendReportedState succeeded
Info: Environmental Sensor Adapter:: Sending device information property to IoTHub. propertyName=state, propertyValue=true    
Info: Pnp components started successfully.
Info: IoTHub client call to _SendEventAsync succeeded
Error: Time:Wed Aug 25 21:57:54 2021 File:F:\b1\pnpbridge\deps\azure-iot-sdk-c-pnp\iothub_client\src\iothubtransport_mqtt_common.c Func:mqtt_operation_complete_callback Line:1794 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Wed Aug 25 21:57:55 2021 File:F:\b1\pnpbridge\deps\azure-iot-sdk-c-pnp\iothub_client\src\iothubtransport_mqtt_common.c Func:mqtt_operation_complete_callback Line:1794 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Wed Aug 25 21:57:55 2021 File:F:\b1\pnpbridge\deps\azure-iot-sdk-c-pnp\iothub_client\src\iothubtransport_mqtt_common.c Func:mqtt_operation_complete_callback Line:1794 Connection Not Accepted: 0x5: Not Authorized
djaus2 commented 3 years ago

Got a bit further. Found this in the Bridge source and edited config.json:

  "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": "Environment Sensor Device Component",
          "pnp_bridge_component_name": "serialpnp1",
          "pnp_bridge_adapter_id": "serial-pnp-interface",
          "pnp_bridge_adapter_config": {
              "com_port": "COM7",
              "_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"
          }
      }
  ]
}`

Now I get:

Info: Using default configuration location
Info: Starting Azure PnpBridge
Info: Pnp Bridge is running as am 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: Adapter with identity serial-pnp-interface does not have any associated global parameters. Proceeding with adapter creation.
Info: Pnp Adapter with adapter ID serial-pnp-interface has been created.
Info: Pnp Adapter Manager created successfully.
Info: Opening com port COM7
Info: Pnp components created successfully.
Info: Pnp components built in model successfully.
Info: Sent reset request
Info: Connected to Azure IoT Hub
Info: Pnp components started successfully.
Error: Time:Wed Aug 25 23:05:06 2021 File:F:\b1\pnpbridge\deps\azure-iot-sdk-c-pnp\iothub_client\src\iothubtransport_mqtt_common.c Func:mqtt_operation_complete_callback Line:1794 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Wed Aug 25 23:05:06 2021 File:F:\b1\pnpbridge\deps\azure-iot-sdk-c-pnp\iothub_client\src\iothubtransport_mqtt_common.c Func:mqtt_operation_complete_callback Line:1794 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Wed Aug 25 23:05:07 2021 File:F:\b1\pnpbridge\deps\azure-iot-sdk-c-pnp\iothub_client\src\iothubtransport_mqtt_common.c Func:mqtt_operation_complete_callback Line:1794 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Wed Aug 25 23:05:09 2021 File:F:\b1\pnpbridge\deps\azure-iot-sdk-c-pnp\c-utility\src\singlylinkedlist.c Func:singlylinkedlist_item_get_value Line:206 Invalid argument (item_handle is NULL)
Error: Time:Wed Aug 25 23:05:11 2021 File:F:\b1\pnpbridge\deps\azure-iot-sdk-c-pnp\iothub_client\src\iothubtransport_mqtt_common.c Func:mqtt_operation_complete_callback Line:1794 Connection Not Accepted: 0x5: Not Authorized

So I guess its now a connectivity issue

djaus2 commented 3 years ago

Further with Tracing on:

Info: Connected to Azure IoT Hub
Info: Pnp components started successfully.
-> 23:44:20 CONNECT | VER: 4 | KEEPALIVE: 240 | FLAGS: 192 | USERNAME: PnPArduino.azure-devices.net/PnPDev/?api-version=2020-09-30&DeviceClientType=PnpBridgeUserAgentString%20iothubclient%2f1.3.9%20(native%3b%20WindowsProduct%3a0x00000030%206.2%3b%20x64%3b%20%7bDE23709D-BF48-453A-BEB5-CB189143337A%7d)&model-id=dtmi%3acom%3aexample%3aRootPnpBridgeSerialDevice%3b1 | PWD: XXXX | CLEAN: 0
<- 23:44:20 CONNACK | SESSION_PRESENT: false | RETURN_CODE: 0x5
Error: Time:Wed Aug 25 23:44:20 2021 File:F:\b1\pnpbridge\deps\azure-iot-sdk-c-pnp\iothub_client\src\iothubtransport_mqtt_common.c Func:mqtt_operation_complete_callback Line:1794 Connection Not Accepted: 0x5: Not Authorized
-> 23:44:20 CONNECT | VER: 4 | KEEPALIVE: 240 | FLAGS: 192 | USERNAME: PnPArduino.azure-devices.net/PnPDev/?api-version=2020-09-30&DeviceClientType=PnpBridgeUserAgentString%20iothubclient%2f1.3.9%20(native%3b%20WindowsProduct%3a0x00000030%206.2%3b%20x64%3b%20%7bDE23709D-BF48-453A-BEB5-CB189143337A%7d)&model-id=dtmi%3acom%3aexample%3aRootPnpBridgeSerialDevice%3b1 | PWD: XXXX | CLEAN: 0
<- 23:44:20 CONNACK | SESSION_PRESENT: false | RETURN_CODE: 0x5
Error: Time:Wed Aug 25 23:44:20 2021 File:F:\b1\pnpbridge\deps\azure-iot-sdk-c-pnp\iothub_client\src\iothubtransport_mqtt_common.c Func:mqtt_operation_complete_callback Line:1794 Connection Not Accepted: 0x5: Not Authorized
-> 23:44:21 CONNECT | VER: 4 | KEEPALIVE: 240 | FLAGS: 192 | USERNAME: PnPArduino.azure-devices.net/PnPDev/?api-version=2020-09-30&DeviceClientType=PnpBridgeUserAgentString%20iothubclient%2f1.3.9%20(native%3b%20WindowsProduct%3a0x00000030%206.2%3b%20x64%3b%20%7bDE23709D-BF48-453A-BEB5-CB189143337A%7d)&model-id=dtmi%3acom%3aexample%3aRootPnpBridgeSerialDevice%3b1 | PWD: XXXX | CLEAN: 0
djaus2 commented 3 years ago

OK I am getting somewhere bubbling along.

PS C:\Temp\pnp> .\pnp
Info:  -- Press Ctrl+C to stop PnpBridge
Info: Using default configuration locationInfo: Starting Azure PnpBridge
Info: Pnp Bridge is running as am IoT egde device.Info: Pnp Bridge creation succeeded.
Info: Connection_type is [dps]Info: Tracing is disabled
Info: IoT Edge Device configuration initialized successfullyInfo: Building Pnp Bridge Adapter Manager, Adapters & Components
Info: Adapter with identity serial-pnp-interface does not have any associated global parameters. Proceeding with adapter creation.Info: Pnp Adapter with adapter ID serial-pnp-interface has been created.
Info: Pnp Adapter Manager created successfully.Info: Opening com port COM7
Info: Pnp components created successfully.Info: Pnp components built in model successfully.
Info: Sent reset requestInfo: Receieved reset response
Info: Sent descriptor request
Info: Initiating DPS client to retrieve IoT Hub connection informationInfo: Receieved descriptor response, of length 281
Info: Device Version : 1Info: Device Name    : Example Thermometer
Info: Interface ID : http://contoso.com/thermometer_exampleInfo:   Property type : 3
Info:   Unit : ms
Info:   Property type : 1
Info:   Name : calibrate
Info:   Display Name : Calibrate Temperature
Info:   Description : Calibrates the thermometer
Error: Time:Wed Aug 25 23:51:53 2021 File:F:\b1\pnpbridge\deps\azure-iot-sdk-c-pnp\provisioning_client\src\prov_device_ll_client.c Func:prov_transport_process_json_reply Line:670 Unsuccessful json encountered: {"errorCode":401000,"trackingId":"edf8709a-3964-49d9-bd6a-d2f3d4e718cd","message":"Unauthorized","timestampUtc":"2021-08-25T13:51:53.8730229Z"}
Error: Time:Wed Aug 25 23:51:53 2021 File:F:\b1\pnpbridge\deps\azure-iot-sdk-c-pnp\provisioning_client\src\prov_transport_mqtt_common.c Func:prov_transport_common_mqtt_dowork Line:1014 Unable to process registration reply.
Error: Time:Wed Aug 25 23:51:54 2021 File:F:\b1\pnpbridge\deps\azure-iot-sdk-c-pnp\provisioning_client\src\prov_device_ll_client.c Func:on_transport_registration_data Line:771 Failure retrieving data from the provisioning service
Error: Time:Wed Aug 25 23:51:54 2021 File:F:\b1\pnpbridge\src\pnpbridge\common\pnp_dps.c Func:provisioningRegisterCallback Line:55 DPS Provisioning callback called with error state 7Error: Time:Wed Aug 25 23:51:54 2021 File:F:\b1\pnpbridge\src\pnpbridge\common\pnp_dps.c Func:PnP_CreateDeviceClientHandle_ViaDps Line:142 Error registering device for DPS
Error: Time:Wed Aug 25 23:51:54 2021 File:F:\b1\pnpbridge\src\pnpbridge\common\pnp_device_client.c Func:AllocateDeviceClientHandle Line:44 Cannot retrieve IoT Hub connection information from DPS client
Error: Time:Wed Aug 25 23:51:54 2021 File:F:\b1\pnpbridge\src\pnpbridge\common\pnp_device_client.c Func:PnP_CreateDeviceClientHandle Line:66 Unable to allocate deviceHandle
Error: Time:Wed Aug 25 23:51:54 2021 File:F:\b1\pnpbridge\src\pnpbridge\src\iothub_comms.c Func:IotComms_InitializeIotDeviceHandle Line:29 PnP_CreateDeviceClientHandle failed
Error: Time:Wed Aug 25 23:51:54 2021 File:F:\b1\pnpbridge\src\pnpbridge\src\pnpbridge.c Func:PnpBridge_RegisterIoTHubHandle Line:283 IotComms_InitializeIotHandle failed.Error: Time:Wed Aug 25 23:51:54 2021 File:F:\b1\pnpbridge\src\pnpbridge\src\pnpbridge.c Func:PnpBridge_Main Line:379 PnpBridge_RegisterIoTHubHandle failed: 2Error: Time:Wed Aug 25 23:51:54 2021 File:F:\b1\pnpbridge\deps\azure-iot-sdk-c-pnp\c-utility\adapters\threadapi_win32.c Func:ThreadAPI_Join Line:45 (result = THREADAPI_INVALID_ARG (2))Info: Cleaning Pnp Bridge resources
PS C:\Temp\pnp>
usivagna commented 3 years ago

Hi David, it looks like you are running the bridge as an Azure IoT Edge runtime module. Are you running the bridge in the dockerized IoT edge runtime environment? If not, try running the bridge as a native application, instructions on how to do so can be found here: /pnpbridge/docs/build_deploy.md#build-and-run-the-bridge-on-an-iot-device-or-gateway

That may fixed some of the errors you are getting with the registering and IoT Hub handle. Hope that helps! Let me know of any further questions.

dipannita08 commented 3 years ago

Full support for DPS provisioning of edge modules through the PnP bridge does not yet exist. The fastest 2 solutions are:

  1. Authenticate and Provision the iot edge device running inside the runtime module using symmetric keys rather than DPS (Instructions here) or,
  2. Run the bridge as a native application rather than as an edge module and provision using symmetric keys OR DPS (both should work)

I went through your sequence of errors and making progress from it: it looks like like you were able to open the connection to the COM port through an instance of the serial PnP adapter. Please make sure that the adapter sends and receives valid json packets.

djaus2 commented 3 years ago

Thanks for the replies

I have been using the pnpbridhe_bin.exe application all along (2 sources):

  1. Downloaded binary from https://github.com/Azure/iot-plug-and-play-bridge/releases
  2. Built for downloaded repository then run as iot-plug-and-play-bridge\pnpbridge\cmake\pnpbridge_x86\src\pnpbridge\samples\console\Debug\pnpbridge_bin.exe No Docker.

In both cases placed config.json in exe directory.

I have now gotten a little further. The bridge is reporting reception of the simulated temperature. Also App reports " Pnp Bridge is running as am IoT egde device."

Info:
 -- Press Ctrl+C to stop PnpBridge

Info: Using default configuration location
Info: Starting Azure PnpBridge
Info: Pnp Bridge is running as am 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 281
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: Pnp components started successfully.
Error: Time:Thu Aug 26 15:37:54 2021 File:C:\Users\DavidJones\source\repos\iot-plug-and-play-bridge\pnpbridge\deps\azure-iot-sdk-c-pnp\iothub_client\src\iothubtransport_mqtt_common.c Func:mqtt_operation_complete_callback Line:1794 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Thu Aug 26 15:37:54 2021 File:C:\Users\DavidJones\source\repos\iot-plug-and-play-bridge\pnpbridge\deps\azure-iot-sdk-c-pnp\iothub_client\src\iothubtransport_mqtt_common.c Func:mqtt_operation_complete_callback Line:1794 Connection Not Accepted: 0x5: Not Authorized
Info: temperature: 12.340000
Error: Time:Thu Aug 26 15:37:55 2021 File:C:\Users\DavidJones\source\repos\iot-plug-and-play-bridge\pnpbridge\deps\azure-iot-sdk-c-pnp\iothub_client\src\iothubtransport_mqtt_common.c Func:mqtt_operation_complete_callback Line:1794 Connection Not Accepted: 0x5: Not Authorized
Info: temperature: 12.340000
Info: temperature: 12.340000
Error: Time:Thu Aug 26 15:37:57 2021 File:C:\Users\DavidJones\source\repos\iot-plug-and-play-bridge\pnpbridge\deps\azure-iot-sdk-c-pnp\iothub_client\src\iothubtransport_mqtt_common.c Func:mqtt_operation_complete_callback Line:1794 Connection Not Accepted: 0x5: Not Authorized
Info: temperature: 12.340000
Info: temperature: 12.340000
Info: temperature: 12.340000
djaus2 commented 3 years ago

Here is my config.json minus the connection info.

NB: Have changed back to using ConnectionString.

{
    "$schema": "../../../pnpbridge/src/pnpbridge_config_schema.json",
    "pnp_bridge_connection_parameters": {
        "connection_type" : "connection_string",
        "connection_string" : "[ ]",
      "root_interface_model_id": "dtmi:com:example:RootPnpBridgeSerialDevice;1",
      "auth_parameters": {
        "auth_type": "symmetric_key",
        "symmetric_key": "[ ]"
      },
      "dps_parameters": {
        "global_prov_uri": "global.azure-devices-provisioning.net",
        "id_scope": "[ ]",
        "device_id": "[ ]"
      }
    },
    "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": "Environment Sensor Device Component",
        "pnp_bridge_component_name": "serialpnp1",
        "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": {
            "Ruuvi" : {
                "company_id": "0x499",
                "endianness": "big",
                "telemetry_descriptor": [
                  {
                    "telemetry_name": "temperature",
                    "data_parse_type": "decimal",
                    "data_offset": 0,
                    "conversion_bias": 0,
                    "conversion_coefficient": 1.0
                  }
                ]
            }
        }
    }

}
djaus2 commented 3 years ago

Note that the

"pnp_bridge_adapter_global_configs": {
        "serial-pnp-interface":

... is a hack from that for Bluetooth. I suspect it requires some tweaking.

djaus2 commented 3 years ago

Can I suggest that a working, config.json be placed with the arduino example, requiring only the connection parameters and the COM Port.

I've done it. See Pull Request: Add config.json to Arduino Serial Sample #70

djaus2 commented 3 years ago

In reverting to ConnectionString I then added the SharedAccessKey to the connection string and it works on the client side:

\Debug> .\pnpbridge_bin
Info:
 -- Press Ctrl+C to stop PnpBridge

Info: Using default configuration location
Info: Starting Azure PnpBridge
Info: Pnp Bridge is running as am IoT egde device.
Info: Pnp Bridge creation succeeded.
Info: Connection_type is [connection_string]
Info: Tracing is disabled
Info: WARNING: SharedAccessKey is included in connection string. Ignoring symmetric_key in config file.
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: Connected to Azure IoT Hub
Info: Receieved reset response
Info: Sent descriptor request
Info: Receieved descriptor response, of length 281
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: Pnp components started successfully.
Info: Processing property update for the device or module twin
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

:)

djaus2 commented 3 years ago

Sample data from Azure IoT Explorer

Thu Aug 26 2021 16:09:04 GMT+1000 (Australian Eastern Standard Time):
{
  "body": {
    "temperature": 12.34
  },
  "enqueuedTime": "Thu Aug 26 2021 16:09:04 GMT+1000 (Australian Eastern Standard Time)",
  "properties": {}
}

:)

djaus2 commented 3 years ago

Now to use some actual sensors on the Arduino Device .. I have plenty of the Grove ones.

djaus2 commented 3 years ago

In finishing 2 questions wrt modeling remain.

Q1. Where are these models: "root_interface_model_id": "dtmi:com:example:RootPnpBridgeSerialDevice;1", This made up one doesn't exist.

One is sample is:

root_interface_model_id": "dtmi:com:example:RootPnpBridgeSampleDevice;1",

In the video at https://techcommunity.microsoft.com/t5/internet-of-things/connect-existing-sensors-to-azure-with-iot-plug-and-play-bridge/ba-p/1686128 which presents a Bluetooth Interface

 "root_interface_model_id": "dtmi:com:example:RootPnpBridgeBluetoothDevice;1"

is used. Update: See next comment

Q2. In the Arduino sample there is a line in ArduinSample.ino

SerialPnP_NewInterface("http://contoso.com/thermometer_example");

Where can one see this model?

djaus2 commented 3 years ago

Have now pushed a Schema file RootPnpBridgeISerialPnPnterfaceModel.json for the Arduino Serial Sample. Pllace it in a local folder then in Azure IoT Explorer set that folder as Local one to find the Model. The config.json needs "root_interface_model_id": "dtmi:contoso:com:serialpnp;1", to match.

This resolves Q1. above

dipannita08 commented 3 years ago

I verified that the logs do indicate running natively and not in a container, glad you could make the sample work :)

To answer your questions regarding the models:

You can leave the "root_interface_model_id": "dtmi:com:example:RootPnpBridgeSampleDevice;1" or create a new one: this will be the top level interface with each individual component mapped within it.

For example (Look at dtmi:com:example:RootPnpBridgeSampleDevice;1 inside iot-plug-and-play-bridge/pnpbridge/docs/schemas/): if you just had one serial pnp thermometer component it would be modeled like:

{ "@id": "dtmi:com:example:RootPnpBridgeSampleDevice;1", "@type": "Interface", "displayName": "Pnp Bridge Root Interface Model", "contents": [ { "@type": "Component", "name": "serialpnpthermometer", "schema": "dtmi:contoso:com:serialpnpthermometer;1" } ], "@context": "dtmi:dtdl:context;2" }

wherein dtmi:contoso:com:serialpnpthermometer;1 (for example) could be modeled like :

[ { "@context": "dtmi:dtdl:context;2", "@id": "dtmi:com:example:Thermostat;1", "@type": "Interface", "contents": [ { "@type": "Telemetry", "name": "temperature", "schema": "double", "unit": "degreeCelsius" }, { "@type": "Property", "name": "targetTemperature", "schema": "double", "unit": "degreeCelsius", "writable": true } ], "extends": [ "dtmi:com:example:baseDevice;1" ] }, { "@context": "dtmi:dtdl:context;2", "@id": "dtmi:com:example:baseDevice;1", "@type": "Interface", "contents": [ { "@type": "Property", "name": "SerialNumber", "schema": "double", "writable": false } ] } ]

Once the model is defined, it can be pushed into the Azure repository or you could have it in some local storage and provide the cloud side with information on where to find the model. More information on this here: https://docs.microsoft.com/en-us/azure/iot-develop/concepts-modeling-guide

and here: https://docs.microsoft.com/en-us/azure/iot-develop/concepts-model-repository

Just remember one instance of PnP Bridge has only 1 "top level" interface, all of its connected devices (supported by one or many adapters) are modeled as components of this top level interface. In this example, all devices are modeled as components of the top level interface "Pnp Bridge Root Interface Model" with the DTMI (model interface ID) "dtmi:com:example:RootPnpBridgeSampleDevice;1"

I hope that helps!

djaus2 commented 3 years ago

Ok thanks for that. Ultimately I want to implement an interface for Grove Sensors. But in the mean time I will work on a Schema for the Arduino Sample as is (simulated temperature) and push that into the Schema directory in the repository. Then work on one for Grove Sensors..