Git Product home page Git Product logo

iot-platform-api's Introduction

IoT Platform APIs

Motivation

This project is an assignment. Implemented code would be a nice example of real-time IoT events and how platform APIs capture and present data. In this assignment, IoT device refers to temperature sensor.

Features

IoT Platform APIs provides

  • Collect IoT device data using HTTP endpoints.

  • Saving data point in InfluxDB.

  • Using Apache Kafka to create event stream.

  • Real-time data processing.

sequence-diagram screenshot

How to run

Prerequisite
  • JDK 1.8 (Tested with Oracle JDK)

  • Maven 3.6.x+

  • Docker (18.09.2), Docker Compose (1.23.2)

Run Apache Kafka, ZooKeeper and InfluxDB in Docker
$ docker-compose up
Build
$ mvn clean compile install
Run
$ java -jar target/iot-platform-api-1.0.0.jar

or

$ mvn spring-boot:run
Quick test

Temperature sensor send data

curl -X POST localhost:8080/temperatures \
-H 'Content-Type: application/json' \
-d '{ "unixTimestamp": 1563142700, "temperatureInFahrenheit": 20 }'

example response

{"success":true}

Temperature sensor send data in batch

curl -X POST localhost:8080/batch/temperatures \
-H 'Content-Type: application/json' \
-d '[{ "unixTimestamp": 1563142701, "temperatureInFahrenheit": 21 }, { "unixTimestamp": 1563142702, "temperatureInFahrenheit": 22 }]'

example response

[{"success":true},{"success":true}]

Get aggregated temperature data report

curl -X GET http://localhost:8080/temperatures?startTime=1563142700&endTime=1563142800 \
-H 'Content-Type: application/json'

example response

{
   "deviceId":"e01a7bc8-ee40-48ba-80ee-f8acbaba5f14",
   "data":[
      {
         "unixTimestamp":1563142700,
         "temperatureInFahrenheit":20.0
      },
      {
         "unixTimestamp":1563142701,
         "temperatureInFahrenheit":21.0
      },
      {
         "unixTimestamp":1563142702,
         "temperatureInFahrenheit":22.0
      },
      {
         "unixTimestamp":1563142795,
         "temperatureInFahrenheit":24.0
      }
   ]
}

Design Decisions

  • Authentication and authorization is not taking into consideration. LoggedInUserService.java provides mocked data.

  • When it comes to making software design decisions for IoT devices, it’s important to fit your functional requirements within the capabilities of resource-constrained devices.

    • Communication through two protocols: MQTT, HTTP and Apache Kafka

    • For assignment purpose, I picked HTTP.

    • Good to read: article 1 article 2 article 3

  • Data stream from IoT devices collected by REST API.

    • Eventually put to Apache Kafka.

    • Persisted in storage.

  • Application has both Apache Kafka event producer and consumer. Separate microservice could make it more scalable.

    • Collector REST API endpoint produce event.

    • Reporting/Metrics collector services consume events.

  • InfluxDB is chosen because it well suited for time series data. Fast time range query makes it good choose. Caching on top of service layer could bring more speed to the APIs.

Development

How to run tests
How to run unit tests

To run the unit tests, execute the following commands

mvn clean test-compile test
How to run integration tests

To run the integration tests, execute the following commands

mvn clean test-compile verify -DskipTests=true
How to run both unit tests and integration tests

To run the integration tests, execute the following commands

mvn clean test-compile verify
How to run pitest

To run the mutation tests, execute the following commands

mvn clean test-compile test
mvn org.pitest:pitest-maven:mutationCoverage

Improvements to make

  • Improve architectural design, completed the project in 12 hours.

  • Use MQTT as default protocol, put data events directly to Apache Kafka.

  • Build docker image (plugin already added in the pom).

  • Generate and check OWASP report.

  • Improve code coverage.

    • Apache Kafka topic listener code is not covered with tests.

Licensed under the MIT License, see the LICENSE file for details.

iot-platform-api's People

Contributors

mmahmoodictbd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 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.