Coder Social home page Coder Social logo

sensors-api's Introduction

Sensors API

Public API to receive data from multiple IoT sensors

Table of Contents

About The Project

Sensors API is an application which demonstrates the following capabilities:

  • Create an API endpoint which can receive data from a streaming device and store it
  • Create a simulator which posts data at specific intervals to the above endpoint in the format listed below. There should be at least 10 devices reporting through the simulator
  • Create an API endpoint that returns a histogram of status for a given device id

Addicional Notes:

  • Every sensor will always send a "deviceId" (string) and a "timestamp" (ISO-formatted timestamp string)
  • Status can have only one of the following values [ON, OFF, ACTIVE, INACTIVE]

Built With

This project was built with the following technologies:

Getting Started

To get a local copy up and running follow these simple example steps.

Prerequisites

List of things you need to use the software and how to install them.

Env file

Create a copy from template file local.env:

cp local.env .env

Edit the new .env file

ENV=local <--------- (string) Name of the running environment (local, staging, production...)
DEBUG= <------------ (boolean) Enables SQL echo and Hot Reload for API server
DATABASE_URL= <----- (connection string) Database connection string, only `asyncpg` and `aiosqlite` are installed:
                       - postgresql+asyncpg://...:...@db:5432/sensors-api
                       - sqlite+aiosqlite:///db.sqlite3
                       - sqlite+aiosqlite://


# Environment Variables for PostgreSQL container in docker-compose.yaml
POSTGRES_PASSWORD= <--- (string) Password to be created in PostgreSQL container
POSTGRES_USER= <------- (string) Username to be created in PostgreSQL container
POSTGRES_DB= <--------- (string) Database to be created in PostgreSQL container

Installation

Install the project and its dependencies + pre commit hooks running the following:

make install

Run it

Run the API server with:

poetry run api

Run the Simulator with default parameters (10 devices, random streaming interval):

poetry run simulator

Run the Simulator with passing optional parameters:

poetry run simulator --devices=50 --streaming-interval=1 --base-url=http://localhost:8000

Run with Docker and Docker Compose

There's an option to run using Docker containers. The current docker-compose.yml has the following available services:

  • API Server: api
  • Simulator Scripts: simulator
  • PostgreSQL Database: db

You can get them up and running altogether running:

docker-compose up

Or run them separately, first the API:

docker-compose up api

And next the Simulator:

docker-compose up simulator

API Docs

The API documentation using OpenAPI spec (aka Swagger) is be available in /docs endpoint (http://localhost:8000/docs).

Tests

Just run the command above.

make test

Lint and Formatting

Run the following:

make lint

Roadmap

Some possible improvements for this project:

  • Add deployment configuration
  • Add database migration support
  • Add Authentication and Authorization
  • Add more test cases

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Patrick Rodrigues - @pythrick - [email protected]

sensors-api's People

Contributors

pythrick avatar

Watchers

James Cloos avatar  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.