Skip to content

A small-ish Node JS API allowing to receive data from an Iskra JS based meteo-station and write it to MongoDB

License

Notifications You must be signed in to change notification settings

boboshko/zarya-api

Repository files navigation

Version Community Chat

Zarya API

A small-ish Node JS API allowing to receive data from an Iskra JS (in Russian) based meteo-station and write it to Mongo DB. API includes all the usual method goodness: GET, POST, PUT и DELETE. It also uses Basic auth via HTTP.

💫 Chasing a dream.

First things first

Before starting the development set up MongoDB on your server.

Quick start

Installation

Clone repo to the server:

git clone https://github.com/boboshko/zarya-api.git

Go to cloned repo directory:

cd zarya-api

Install all the necessary packages:

npm install

Connecting to the station

Add values to the environment keys. For example:

export zaryaUrlMongo="mongodb://localhost:27017/"
export zaryaDbName="dbName"
export zaryaCollectionName="collectionName"
export zaryaPort=3012

You can use the same set of values in the app/config/config.js file instead:

module.exports = {
  zaryaUrlMongo: process.env.zaryaUrlMongo || 'mongodb://localhost:27017/',
  zaryaDbName: process.env.zaryaDbName || 'dbName',
  zaryaCollectionName: process.env.zaryaCollectionName || 'collectionName',
  zaryaPort: process.env.zaryaPort || 3012,
};

Authorizing the requests

This API uses Basic auth via HTTP. Login and password are stored in the zaryaUsers variable in app/data/auth.js.

You can choose more complex login/password pair, for sure:

const zaryaUsers = { 'sdoJfde342': 'dskSlK4iu3' };

⚠️ Never share login or password with anyone! (Bad things can happen)

Data format

Created primarily for Iskra JS, this API can work with other shields, too.

Validation scheme is stored in app/data/model.js and by default looks like this:

{
  "station_id": Number,
  "created_at": Number,
  "date_count": Number,
  "temperature": Number,
  "pressure": Number
}

This scheme can also be changed.

Usage

Starting up:

npm run start

For API requests use:

<YOUR_SERVER_IP>:3012/zarya

⚠️ Never share this address with anyone either! (Or, you guessed it, bad things will happen)