Giter Club home page Giter Club logo

thermostats's Introduction

README

Web API for storing readings from IoT thermostats and reporting a simple statistics on them.

Things you may want to cover:

Ruby version

ruby '2.3.1'

System dependencies

gem 'rails', '~> 5.2.3' 
gem 'sidekiq', '3.3.3'
gem 'redis'
gem 'redis-namespace'
gem 'redis-rails'
gem 'redis-rack-cache'

Installation

Installing RVM:

1  sudo apt-get update
2  sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt1-dev
3  sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
4  curl -L https://get.rvm.io | bash -s stable
5  source ~/.rvm/scripts/rvm
6  echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc

Installing Ruby :

7  rvm install
8  rvm update 2.0.0
9  rvm use 2.0.0 --default
10  ruby -v

Installing Rails:

	11  gem install rails ~> 5.2.3

Usage:

git checkout https://github.com/dileeppdkr/thermostats.git
cd thermostats
bundle install
rails s

#API's:

##Create Thermostats (Post thermostats)

curl -X POST \
	http://localhost:3000/thermostats \
	-H 'Content-Type: application/x-www-form-urlencoded' \
	-H 'Postman-Token: 45816116-d251-4e3c-a972-6e97b29040e1,c26166d3-d73a-416d-8b63-088ca49a591d' \
	-H 'cache-control: no-cache,no-cache' \
	-d 'location=BTM%20sector%202'

Response:
{
  "thermostats": {
      "id": 30,
      "household_token": "c48453eb-0df4-45ca-909e-c7357fac96f6",
      "location": "BTM sector 2"
  }
}

##Create Readings for a thermostat (Post reading)

curl -X POST \
	http://localhost:3000/readings \
	-H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Postman-Token: c13766c4-047e-4531-8d19-8c275e102333' \
  -H 'cache-control: no-cache' \
  -d 'household_token=aaad3985-9a70-4959-85b8-eb3700cf1b1a&temperature=34.4&humidity=11&battery_charge=1053'

Response:
{
  "sequence_id": 29
}

##GET Reading

curl -X GET \
'http://localhost:3000/readings/26?household_token=6306a49e-d604-4860-8a0a-3188671e7a26' \
-H 'Postman-Token: 56f2f698-23c2-4c11-b895-fba65622f4d1' \
-H 'cache-control: no-cache'

Response:
{
  "id": 26,
  "thermostat_id": 23,
  "temperature": 43.4,
  "humidity": 26,
  "battery_charge": 1453
}

##GET Stats

curl -X GET \
'http://localhost:3000/readings?household_token=aaad3985-9a70-4959-85b8-eb3700cf1b1a' \
-H 'Postman-Token: e58494d2-0b44-4caf-95a1-5b2e6f77550a' \
-H 'cache-control: no-cache'

Response:
{
  "thermostat_data": [
      {
          "temperature": {
              "avg": 46.4,
              "min": 34.4,
              "max": 52.4
          }
      },
      {
          "humidity": {
              "avg": 20.33,
              "min": 11,
              "max": 25
          }
      },
      {
          "battery_charge": {
              "avg": 1186.33,
              "min": 1053,
              "max": 1253
          }
      }
  ]
}

Test:

rspec spec

thermostats's People

Contributors

dileeppdkr 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.