Giter Site home page Giter Site logo

terasys-api's Introduction

Readme

Introduction

Backend API to take in data from IoT devices and serve it to clients via REST endpoints. Devices need to be registered before they can send data to API.

API has been updated to accept only HTTPS requests.

REST API

REST API documentation can be found here

Socket.io

Connection to socket.io is done at https://www.terasyshub.io/

Listen Events

To obtain data from socket.io, you must set it to listen to the type of data you want returned. In this case either temperature or humidity as these are the only ones we have implemented so far.

To get get data from the API, there are two methods:

Polling at intervals

Using this method, it is possible to manually set an interval in the frontend at which to poll the API for data. To do so, emit the event getData to socket.io. The data to provide is as follows:

{
  "mac" : "00:0a:95:9d:68:16",
  "type" : "temperature",
  "last" : 1487868693,
  "token" : {{authtoken}}
}

mac is the mac address of the device to get data for

type is the type of data to be returned

last optional field. Determines up to what time to pull results from. Leave blank to return latest datapoint.

Data is returned as it would be from the REST endpoint.

Registering to database updates

This method returns data to the temperature and humdity events as soon as data is saved in the database.

To be updated whenever data for a device is saved in the DB, simply send the mac address of the device to the register listener like so:

socket.emit('register', {device:'00:0a:95:9d:68:16', token:'{{authtoken}}'});

To stop listening for updates for a device, simply unregister from the device:

socket.emit('unregister', '00:0a:95:9d:68:16');

Webhook Api documentation

There are four endpoints that recieves a post request in this sprint namely:

  • /api/webhook-obd2: this endpoint recieves a post request from the webhook and persist the data in a mongo db there after sending a response status of 200 back to the webhook

  • /api/events/message: this is the endpoint to retrieves all messages events (from most recent to oldest) relating to a particular account's asset and returns an array of message events along with pagination meta data. the endpoint recieves 4 input posts.

    (1) AccountName (compulsory): this is the name of the account as registered by the webhook services provider in which it message events is required.

    (2) limit(optional): the number of most recent events required.

    (3) offset(optional): the number of data to skip when querying.

    (4) asset(compulsory): serial number of the asset which event is required

  • /api/events/track: this is the endpoint to retrieves all track events (from most recent to oldest) relating to a particular account's asset and returns an array of presence events along with pagination meta data. the endpoint recieves 4 input posts.

    (1) AccountName (compulsory): this is the name of the account as registered by the webhook services provider in which it track events is required.

    (2) limit(optional): the number of most recent events required.

    (3) offset(optional): the number of data to skip when querying.

    (4) asset(compulsory): serial number of the asset which event is required

  • /api/events/presence: this is the endpoint to retrieves all presence events (from most recent to oldest) relating to a particular account's asset and returns an array of presence events along with pagination meta data. the endpoint recieves 4 input posts.

    (1) AccountName (compulsory): this is the name of the account as registered by the webhook services provider in which it track events is required.

    (2) limit(optional): the number of most recent events required.

    (3) offset(optional): the number of data to skip when querying.

    (4) asset(compulsory): serial number of the asset which event is required

terasys-api's People

Contributors

gabod2000 avatar irwynks 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.