Tuesday, November 29, 2016

Home Automation (4): API and DB

I have decided to add to my Home Automation (Concept System) two important pieces:
  • a REST API
  • A Database


For the Database I have decided to adopt MySQL, installed on the Raspberry PI that works as Hub/Gateway.
Here the only important thing that I want to mention is that I have decided to store the datafiles not on the SD card (too many writes, I don’t want to risk to destroy it before the time) but on an external USB disk, attached to a USB Hub (powered). It works fine.
The DB schema will contain two types of data:
  • Reference Data
  • Message Data (from devices)
Data coming from devices are inserted into tables from several NodeRED flows. It is easy and works well.
But I have decided also that I need a REST API, to be able, for example, to easily integrate data-access from a future Mobile UI.
Here, I have made some important decisions, and I have already developed a working prototype to test the decision made and their effectiveness:
  1. The interface of the REST API is documented using OpenAPI (Swagger 2.0)
  2. I have adopted a Top-Down approach: first, design of the Interface, using Swagger, then development of the code
  3. The language selected for the API implementation is JavaScript, with NodeJS
  4.  I have decide to use the Express Framework and Swagger modules
Swagger (OpenAPI: https://www.openapis.org/) is rapidly becoming the standard for documenting a REST API.
Swagger not only is really useful and not-so-complicated for describing the REST API, but using the Swagger NodeJS Modules I can easily access online to the documentation and, with Swagger UI, I have a nice UI to test the API and to use it.
Here you see the a picture of the Swagger UI:
NewImage
I will write some more blog’s posts on Swagger and My REST API. Stay connected.

No comments:

Post a Comment