Git Product home page Git Product logo

opentrv-gateway's Introduction

opentrv-gateway

Getting Started

Node and Npm are required for this project.

First need to run npm install to install all of the required modules. Then run npm start to start the server.

Background

API

basePath: /api/v1

trv

GET /trv

Return all of the trv's connected to the gateway

Specifics required type
params no N/A
body No N/A
returns N/A Array

GET /trv/{id}

Return the details of a particular trv that is connected to the gateway

Specifics required type
params Yes, id String
body No N/A
returns N/A Object

PUT /trv/{id}

Update the details of a trv that is connected to the gateway

Specifics required type
params yes, id String
body yes, fields of trv that wished to be changed Object
returns N/A Object

DELETE /trv/{id}

Delete a trv that is connected to the gateway

Specifics required type
params yes, id String
body No N/A
returns N/A N/A

Returns nothing

GET /trv/{id}/isActive

Return whether a particular trv is active or not

Specifics required type
params yes, id String
body No N/A
returns N/A Object

GET /trv/{id}/temperature

Returns the current temperature for a particular trv

Specifics required type
params yes, id String
body No N/A
returns N/A Object

PUT /trv/{id}/temperature

Updates the target temperature for a particular trv

Specifics required type
params yes, id String
body yes, with target temperature property Object
returns N/A N/A

GET /trv/{id}/info

returns a JSON object of time, current temperature, target temperature and activity

schedules

POST /schedule

GET /schedule

GET /schedule/{scheduleId}

PUT /schedule/{scheduleId}

DELETE /schedule/{scheduleId}

opentrv-gateway's People

Contributors

jack-evans avatar

Watchers

 avatar  avatar  avatar

opentrv-gateway's Issues

end to end testing

write tests that require the server and then call the various API's in both success and fail cases

use supertest

gateway returning 500 every now and then

seeing the following happen every now and then after running for a while:

{"name":"trv-request-handler","hostname":"jack","pid":6998,"level":50,"msg":"Encountered unexpected error (undefined) in the getAllTrvsRequestHandler SyntaxError: /home/jack/final-year-project/opentrv-gateway/trvStorage/0383186d-2bd2-454e-b470-c7b46a623a43.json: Unexpected end of JSON input\n    at JSON.parse (<anonymous>)\n    at /home/jack/final-year-project/opentrv-gateway/node_modules/jsonfile/index.js:33:18\n    at /home/jack/final-year-project/opentrv-gateway/node_modules/graceful-fs/graceful-fs.js:78:16\n    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)","time":"2018-05-01T12:46:47.305Z","v":0}

Looks like a problem with jsonfile.... need to investigate

no validation on json body

need some validation on JSON body otherwise a user/consumer can alter the JSON for the device in anyway.

Possibly could provide a metadata property at the root level of the JSON file which will contain any properties that a user wishes to add.

options for validation:
https://www.npmjs.com/package/jsonschema

Create Scheduling piece

Todo:

  • define structure of JSON document (can then be used for validation)
  • POST /schedule
  • GET /schedule
  • GET /schedule/{id}
  • PUT /schedule/{id}
  • DELETE /schedule/{id}

Process for each API

POST /schedule

  • validate against definition of JSON document
  • create in scheduleStorage (save as file to server)
  • Update trvs that are using the schedule (add schedule id to the activeSchedules array)

GET /schedule

  • retrieve all json files stored in the scheduleStorage

GET /schedule/{id}

  • validate the id is of the right format
  • retrieve schedule with the filename corresponding to that id

PUT /schedule/{id}

  • validate against definition of JSON document
  • merge the existing JSON schedule stored and the new one to be stored (will avoid the possibility of a user completely destroying the document and putting the system into a bad state)

DELETE /schedule/{id}

  • check id is of the right format
  • check the schedule exists
  • update the trvs that are using that schedule, removing reference of the schedule
  • remove the schedule from the scheduleStorage

Need to add Logging

Logging is needed to capture all the entry and exit points of the code

will probably use bunyan

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.