The cloud solution consists of two components: The Registration API, and the Data Collection API.
The the cloud stores data for three types: Users, Sensors, and Sensor Data. Users have sensors and sensors have data.
The registration API handles CRUD (Create, read, update and delete) operations for Users and Sensors, as well as allowing for the querying of sensor data for any given sensor. This API is hosted using the Serverless framework along with AWS API Gateway and operates under the HTTP protocol.How It Works:
The Serverless framework parses the code and divides it into Lambda Functions for each of the CRUD operations. Lambda functions in the context of AWS are sections of code that handle requests to a particular path. These functions and paths are combined using AWS API gateway which assigns lambda functions to a particular path.
The beauty in this approach is that the individual functions can be updated rather than re uploading the entire code. Structurally, each function can be written in a different programming language and pieced together by AWS API Gateway.
This is where the idea of Serverless comes from. There is not one monolith application hosted on a single server. Instead the application is split into several parts that is hosted on different servers pieced together by AWS.Data Collection API
The Data Collection API serves to collect data from any given sensor. It can only collect numerical data and it is not able to do any CRUD operations.How It Works:
The Data Collection API utilizes the Springboot framework and is Written using Java. The application is hosted on AWS using Elastic Beanstalk, which is a service that allows a monolith application to be run on AWS. A Linux instance is created and is used to host the application which is uploaded as a.jar file.How To Deploy:
For the Data Registration api run the following in the project directory:
This will set the access and secret key path variables which are used by Serverless to deploy the API to Amazon Web Services.
Then, run the following:
sls remove && mvn clean install && sls deploy
sls remove removes the existing bucket in the AWS user's account.
mvn clean install builds the project using the existing sources and files.
sls deploy deploys the application to AWS.
Upon successful deployment you should see a listing of the available endpoints.
For the Data Collection api, the project has to be built into a .jar file and uploaded to AWS.
To build run:
./mvnw package -DskipTests
This will create two jar files:
To host in the cloud, simply upload the WebsocketAPI-0.0.1-SNAPSHOT.jar to the cloud provider of your choice.How to Use
The process is as follows:
- Create a user by making a post request to the Users endpoint.
- Create a sensor by making a post request to the Sensors endpoint. Use the User Id created in the previous step for the userId parameter.
- Using the Websocket endpoint, enter a valid sensorId(perhaps the one from the previous step) and data.
- You can query the data for any given sensor by providing the Sensor Data endpoint followed by the sensor's sensorId.