Code Monkey home page Code Monkey logo

device-telemetry-dotnet's Introduction

Build Issues Gitter

Device Telemetry Overview

This service offers read access to device telemetry, full CRUD for rules, and read/write for alarms from storage for the client via a RESTful endpoint.

Features the microservice offers:

  1. Gets a list of telemetry messages for specific parameters
  2. Gets a list of alarms for specific parameters
  3. Gets a single alarm
  4. Modifies alarm status
  5. Create/Read/Update/Delete Rules
    1. Create Rules
    2. Gets a list of rules for specific parameters
    3. Gets a single rule
    4. Modify existing rule
    5. Delete existing rule

Dependencies

  1. DocumentDB Storage
  2. Storage Adapter Webservice

How to use the microservice

Quickstart - Running the service with Docker

  1. Create an instance of Azure Document Db
  2. Follow the Storage quickstart instructions for setting up the Storage Adapter microservice storage.
  3. Find your DocumentDb connection string. See See the tip here if you need help finding it.
  4. Store the "Document Db Connection string" in the env-vars-setup script, then run the script. In MacOS/Linux the environment variables need to be set in the same session where you run Docker Compose, every time a new session is created.
  5. Install Docker Compose
  6. Start the Telemetry service using docker compose:
    cd scripts
    cd docker
    docker-compose up
    
  7. Use an HTTP client such as Postman, to exercise the RESTful API

Local Setup

1. Environment Variables

Run scripts\env-vars-setup.cmd on Windows or source scripts\env-vars-setup on Mac/Linux to set up the environment variables needed to run the service locally. In Windows you can also set these in your system.

If using envornemnt variables, this service requires the following environment variables to be set:

  1. PCS_TELEMETRY_DOCUMENTDB_CONNSTRING = {your Azure Document Db connection string}
  2. PCS_STORAGEADAPTER_WEBSERVICE_URL = http://localhost:9022/v1

Running the service with Visual Studio

  1. Install any edition of Visual Studio 2017 or Visual Studio for Mac. When installing check ".NET Core" workload. If you already have Visual Studio installed, then ensure you have .NET Core Tools for Visual Studio 2017 installed (Windows only).
  2. Create an instance of Azure Document Db
  3. Follow the Storage quickstart instructions for setting up and running the Storage Adapter microservice.
  4. Open the solution in Visual Studio
  5. Edit the WebService project properties, and define the following required environment variables. In Windows you can also set these in your system.
    1. PCS_TELEMETRY_DOCUMENTDB_CONNSTRING = {your Azure Document Db connection string}
    2. PCS_STORAGEADAPTER_WEBSERVICE_URL = http://localhost:9022/v1
  6. In Visual Studio, start the WebService project
  7. Using an HTTP client like Postman, use the RESTful API

Project Structure

The solution contains the following projects and folders:

  • Code for the application is in app/com.microsoft.azure.iotsolutions.telemetry/
    • WebService - ASP.NET Web API exposing a RESTful API for for managing Ruels, Alarms, and Messages
    • Services - Library containing common business logic for interacting with storage and the StorageAdapter
  • Tests are in the test folder
    • WebService - Tests for web services functionality
    • Service - Tests for services functionality
  • Scripts - a folder containing scripts from the command line console, to build and run the solution, and other frequent tasks.
  • Routes - defines the URL mapping to web service classes

Build and Run from the command line

The scripts folder contains scripts 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.

Building a customized Docker image

The scripts folder includes a docker subfolder with the scripts required to package the service into a Docker image:

  • Dockerfile: Docker image specifications
  • build: build a Docker image and store the image in the local registry
  • run: run the Docker container from the image stored in the local registry
  • content: a folder with files copied into the image, including the entry point script

You can also start Device Telemetry and its dependencies in one simple step, using Docker Compose with the docker-compose.yml file in the project:

cd scripts
cd docker
docker-compose up

The Docker compose configuration requires the Storage and StorageAdapter web service URL environment variables, described previously.

Configuration and Environment variables

The service configuration is stored using ASP.NET Core configuration adapters, in appsettings.ini. The INI format allows to store values in a readable format, with comments. The application also supports references to environment variables, which is used to import credentials and networking details.

The configuration files in the repository reference some environment variables that need to be created at least once. Depending on your OS and the IDE, there are several ways to manage environment variables:

Other resources

Contributing to the solution

Please follow our contribution guidelines. We love PRs too.

Troubleshooting

{TODO}

Feedback

Please enter issues, bugs, or suggestions as GitHub Issues here: https://github.com/Azure/device-telemetry-dotnet/issues.

device-telemetry-dotnet's People

Contributors

dluc avatar jillcary avatar microsoftopensource avatar msftgits avatar ppathan avatar tiagoshibata avatar xzsheng avatar

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.