Giter Site home page Giter Site logo

iot-plugandplay-models's Introduction

Azure/iot-plugandplay-models repository

This repository includes DTDL models that are made publicly available on https://devicemodels.azure.com. These models can be used to create Azure IoT Plug and Play solutions.

Related tools, samples, and specs can be found in the Azure/iot-plugandplay-models-tools repo. The current repo only stores DTDL models.

Submit a model

  1. Create a GitHub account if you do not have one yet: Join GitHub.

    Learn more about GitHub

  2. Sign Contributor License Agreement

  3. Fork the public GitHub repo: https://github.com/Azure/iot-plugandplay-models.

    Learn more about forking a repo

  4. Clone the forked repo. Optionally create a new branch to keep your changes isolated from the main branch.

    By forking and cloning the public GitHub repo, a copy of repo will be created in your GitHub account and a local copy is created in your dev machine. Please use this local copy to make modifications.

  5. Author a new device model with an unique ID using Digital Twin Model Identifier.

    Review the PR requirements for naming conventions.

    [!TIP]
    DTDL Editor for Visual Studio Code could help you with the language syntax (including auto-completion) and also validate the syntax with DTDL v2.

  6. Save the device model JSON file to a local folder.

    E.g. C:\iot-plugandplay-models\MyThermostat.json

  7. Validate the models locally using the dmr-client tool to validate.

  8. Add the new interfaces to the dtmi folder using the folder/filename convention. See the import command below.

  9. Review and cross check with the PR requirements and ensure all elements are conform to DTDL v2 specification.

  10. Commit the changes locally and push to your fork.

  11. From your fork, create a PR that targets the main branch.

    Learn more about pull request

The PR triggers a series of GitHub actions that will validate the new submitted interfaces, and make sure your PR satisfies all the checks.

Microsoft will respond to a PR with all checks in 3 business days.

GitHub Operation Workflow

+-------------------------------------------------+
| iot-plugandplay-models repo (Microsoft)           |
+-------------------------------------------------+
  |          ⭡
  | Fork     | Pull Request (PR)
  🡓          |
+-------------------------------------------------+
| iot-plugandplay-models repo (your Github account) |
+-------------------------------------------------+
  |          ⭡ 
  | Clone    | Commit/Push
  🡓          |
+-------------------------------------------------+
| Your development PC                             |
| - Author device model                           |
| - Import your model to the DTMI folder          |
+-------------------------------------------------+

dmr-client Tool

The tools used to validate the models during the PR checks can also be used to add and validate the DTDL interfaces locally.

Note: This tool requires the .NET SDK (3.1 or greater)

Install dmr-client

Linux/Bash

curl -L https://aka.ms/install-dmr-client-linux | bash

# Expected SHA checksum
curl -sL https://aka.ms/install-dmr-client-linux | shasum -b -a 256
2d1c1ca24943527982ef30f5e8f9716bdbf2ca11407b2af73183453b98d251a0 *-

Windows/Powershell

iwr https://aka.ms/install-dmr-client-windows -UseBasicParsing | iex

# Expected SHA checksum
curl -sL https://aka.ms/install-dmr-client-windows | shasum -b -a 256
0245ae8318e7caf27dd63f3841646f2def3e2ced127ffcb741814be3b063fd7a *-

Update / Uninstall

To update the client you must uninstall the current version first:

dotnet tool uninstall -g microsoft.iot.modelsrepository.commandline

[Note] Previous versions must be uninstalled with dotnet tool uninstall -g dmr-client. Use the dotnet tool list -g command to check the id of the tool you want to uninstall

Import a Model to the dtmi/ folder

If you have your model already stored in json files, you can use the dmr-client import command to add those to the dtmi/ folder with the right file name.

# from the local repo root folder

> dmr-client import --model-file "MyThermostat.json"

This command will rename and locate the file in the appropriate folder

Validate Models

You can validate your models with the dmr-client validate command.

# Validate a model file using the DTDL parser

> dmr-client validate --model-file ./my/model/file.json

Note: The validation uses the latest DTDL parser version to ensure all the interfaces are compatible with the DTDL language spec

To validate external dependencies, those must exist in the local repo. To validate those you can specify a local or remote folder to validate against.

# Validate a model file using the DTDL parser checking dependencies with the current folder as a local repo

> dmr-client validate --model-file ./my/model/file.json --repo .

Strict validation

The Device Model Repo includes additional requirements, these can be validated with the strict flag.

# Validate a model file using the DTDL parser checking dependencies with the current folder as a local repo in strict mode

> dmr-client validate --model-file ./my/model/file.json --repo . --strict

Export models

Models can be exported from a given repo (local or remote) to a single file using a JSON Array.

# Retrieves an interface from a custom repo by DTMI

> dmr-client export --dtmi "dtmi:com:example:Thermostat;1" --repo https://raw.githubusercontent.com/Azure/iot-plugandplay-models/main

Create Index

The model repo can host a index.json file with all the ids avaialble in the repository. Read the Index Spec

# Builds a model index for the repository. If models exceed the page limit new page files will be created relative to the root index.

> dmr-client index --local-repo .
# Build a model index with a custom page limit indicating max models per page.

> dmr-client index --local-repo . --page-limit 100

Create Expanded files

# Expand all models from the root directory of a local models repository following Azure IoT conventions.
# Expanded models are inserted in-place.

> dmr-client expand --local-repo .
# The default --local-repo value is the current directory. Be sure to specifiy the root for --local-repo.

> dmr-client expand

Consuming

There are Azure SDKs available for the models repository in the following languages:

Platform Package Source Samples
.NET Azure.IoT.ModelsRepository Source Samples
Java com.azure/azure-iot-modelsrepository Source Samples
Node @azure/iot-modelsrepository Source Samples
Python azure-iot-modelsrepository Source Samples

Retrieve models without any SDK

Any HTTP client can consume the models by just applying the convention to translate DTMI ids to relative paths:

Eg, the interface:

dtmi:azure:DeviceManagement:DeviceInformation;1

can be retrieved from here:

https://devicemodels.azure.com/dtmi/azure/devicemanagement/deviceinformation-1.json

There are samples for .NET and Node in the Azure/iot-plugandplay-models-tools with code you can use to acquire models from your custom IoT solution.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.