DEPRECATED: This repository is no longer maintained. It has been moved to a new location. Please visit our new repository here. This microservice is present under services sub-module.
This service manages most of Azure IoT Hub interactions, such as creating and managing IoT devices, device twins, invoking methods, managing IoT credentials, etc. This service is also used to run queries to retrieve devices belonging to a particular group (defined by the user).
The microservice provides a RESTful endpoint to manage devices, device twins, commands, methods and all the Azure IoT Hub features required by the Azure IoT Remote Monitoring project.
This microservice was built as part of the Azure IoT Remote Monitoring project to provide a generic implementation for an end-to-end IoT solution. More information here.
- Device creation in IoT Hub
- Read for all devices
- Read for a single device
- Query for set of devices
- Update devices
- Delete devices
- Schedule jobs
- Execute methods
- Update the device twin
- Get a list of jobs
- Get a single job
- View the API documentation in the Wiki
- Contributing and Development setup
- Development setup, scripts and tools
You can run the microservice and its dependencies using Docker with the instructions here.
This service has a dependency on the following Azure resources. Follow the instructions for Deploy the Azure services to deploy the required resources.
This service depends on the Storage Adapter microservice. Run the Storage Adapter microservice using the the instructions in the Storage Adapter service README.md.
Note: you can also use a deployed endpoint with Authentication disabled (e.g. https://{your-resource-group}.azurewebsites.net/storageadapter/v1)
In order to run the service, some environment variables need to be created at least once. See specific instructions for IDE or command line setup below for more information. More information on environment variables here.
PCS_AUTH_WEBSERVICE_URL
= http://localhost:9001/v1- The url for the Authentication service from Setup Dependencies
PCS_IOTHUB_CONNSTRING
= {your Azure IoT Hub connection string from Deploy Azure Services}- More information on where to find your IoT Hub connection string here.
PCS_STORAGEADAPTER_WEBSERVICE_URL
= http://localhost:9022/v1- The url for the Storage Adapter service from Setup Dependencies
- Make sure the Prerequisites are set up.
- Install .NET Core 2.x
- Install any recent edition of Visual Studio (Windows/MacOS) or Visual
Studio Code (Windows/MacOS/Linux).
- If you already have Visual Studio installed, then ensure you have .NET Core Tools for Visual Studio 2017 installed (Windows only).
- If you already have VS Code installed, then ensure you have the C# for Visual Studio Code (powered by OmniSharp) extension installed.
- Open the solution in Visual Studio or VS Code
- Define the following environment variables. See Configuration and Environment variables for detailed information for setting these for your enviroment.
PCS_AUTH_WEBSERVICE_URL
= {authentication service endpoint}PCS_IOTHUB_CONNSTRING
= {your Azure IoT Hub connection string}PCS_STORAGEADAPTER_WEBSERVICE_URL
= {storage adapter service endpoint}
- Start the WebService project (e.g. press F5).
- Using an HTTP client like Postman, use the RESTful API to test out the service.
- Make sure the Prerequisites are set up.
- Set the following environment variables in your system. More information on environment variables here.
PCS_AUTH_WEBSERVICE_URL
= {authentication service endpoint}PCS_IOTHUB_CONNSTRING
= {your Azure IoT Hub connection string}PCS_STORAGEADAPTER_WEBSERVICE_URL
= {storage adapter service endpoint}
- Use the scripts in the scripts folder for many frequent tasks:
build
: compile all the projects and run the tests.compile
: compile all the projects.run
: compile the projects and run the service. This will prompt for elevated privileges in Windows to run the web service.
This microservice contains the following projects:
- WebService.csproj - C# web service exposing REST interface for storage functionality
- WebService.Test.csproj - Unit tests for web services functionality
- Services.csproj - C# assembly containining business logic for interacting with Azure Cosmos account with type SQL
- Services.Test.csproj - Unit tests for services functionality
- Solution/scripts - Contains build scripts, docker container creation scripts, and scripts for running the microservice from the command line
The scripts
folder includes a docker subfolder with the files
required to package the service into a Docker image:
Dockerfile
: docker images specificationsbuild
: build a Docker container and store the image in the local registryrun
: run the Docker container from the image stored in the local registrycontent
: a folder with files copied into the image, including the entry point script
The service configuration is accessed via ASP.NET Core configuration adapters, and stored in appsettings.ini. The INI format allows to store values in a readable format, with comments.
The configuration also supports references to environment variables, e.g. to import credentials and network details. Environment variables are not mandatory though, you can for example edit appsettings.ini and write credentials directly in the file. Just be careful not sharing the changes, e.g. sending a Pull Request or checking in the changes in git.
The configuration file in the repository references some environment variables that need to be defined. Depending on the OS and the IDE used, there are several ways to manage environment variables.
- If you're using Visual Studio (Windows/MacOS), the environment variables are loaded from the project settings. Right click on WebService, and select Options/Properties, and find the section with the list of env vars. See WebService/Properties/launchSettings.json.
- Visual Studio Code (Windows/MacOS/Linux) loads the environment variables from .vscode/launch.json
- When running the service with Docker or from the command line, the
application will inherit environment variables values from the system.
- This page describes how to setup env vars in Windows. We suggest to edit and execute once the env-vars-setup.cmd script included in the repository. The settings will persist across terminal sessions and reboots.
- For Linux and MacOS, we suggest to edit and execute env-vars-setup each time, before starting the service. Depending on OS and terminal, there are ways to persist values globally, for more information these pages should help:
Please follow our contribution guidelines. We love PRs too.
Please enter issues, bugs, or suggestions as GitHub Issues here.
Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License.