Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

A server made in Nest to manage door-reader access, shutter and light.

License

Notifications You must be signed in to change notification settings

iotbzh/DEPRECATED_domotic-server

Repository files navigation

IOT DOMOTIC SERVER

Description

A server made in Nest to manage door-reader access, shutter and light.

WARNING

This is project is under construction and it is experimental.

Installation

Note: for development without physical card readers and shutter relays set ENV=dev-mock in the .env file. Copy src/example.*.json and change with correct values.

# Copy example json files
cp src/example.config-readers.json src/config-readers.json
cp src/example.config-winstar-relay.json src/config-winstar-relay.json

# then open config-readers.json and config-winstar-relay.json and change with your values

Note: Readers, badges and users follow this level logic:

  • For readers the 'level' property is:

    • 0: private
    • 1: servers, etc
    • 2: public
  • For badges the 'permission' property is:

    • 0: all
    • 1: servers, etc
    • 2: public
  • For users the 'type' property is:

    • 0: super
    • 1: admin
    • 2: normal
    • 3: guest

You can adapt you own logic changing the different services in src folder.

git clone git clone https://github.com/iotbzh/server-domotic.git
cd server-domotic
make all

Extra commands

npx ts-node -r dotenv/config scripts/bcrypt-generator.js

Installing dependencies

This domotic server implements 2 physical components:

  • Civintec CT9 and CN56 NFC card readers (Access Control).
  • Winstar 2 channel relay with 4 network port IO (Shutter control).

They must be at the same folder level as domotic-server.

git clone https://github.com/iotbzh/civintec-reader.git
cd civintec-server
npm install && npm run build

cd ..
git clone https://github.com/iotbzh/winstar-relay
cd winstar-relay
npm install && npm run build

Note: Set the ENV=prod or ENV=dev or ENV=dev-mock in the .env file.

Database

This application use PostgreSQL database. If not installed on your system you can use the docker-compose file included. After installing docker you just need to run docker-compose up -d. You can configure the connection in the .env file under the DATABASE_ variables.

Running the app

# first time
make setup

# development
make devf # terminal 1 to run the frontend (angular) in watch mode.
make devb # terminal 2 to run the backend (nestjs) in watch mode.

# production mode
make all &&
npm start:prod

Alternately install PM2, the daemon process manager that will help you manage and keep your application online.

Change the ecosystem.config.js file and run

# production mode
$  pm2 start ecosystem.config.js --env production

Migrations

Note: This application only includes one migration to create the admin user. The application must be built (npm run build) or running (npm run start).

To run migrations:

npm run typeorm migration:run

or using the cli

npx typeorm migration:run

To rollback migration

npx typeorm migration:revert

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Examples

  • Login:

    curl -X POST "http://localhost:3000/auth/login" -H  "accept: */*" -H  "Content-Type: application/json" -d "{\"email\":\"[email protected]\",\"password\":\"changeme\"}"

    output:

    {
      "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI4NTExNWRlNC02ZjFiLTQ0NzctODViYS04MTM4ZmUzMTYzNjkiLCJpYXQiOjE2MDM5MDU5OTEsImV4cCI6MTYwMzkxMzE5MX0.jTG7RX6okFbAbUfzhn2-dlQPOnJf2EI87SzKfpfh3XU"
    }
  • Get users:

    curl -X GET "http://localhost:3000/users/list" -H  "accept: */*" -H  "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI4NTExNWRlNC02ZjFiLTQ0NzctODViYS04MTM4ZmUzMTYzNjkiLCJpYXQiOjE2MDM5MDU5OTEsImV4cCI6MTYwMzkxMzE5MX0.jTG7RX6okFbAbUfzhn2-dlQPOnJf2EI87SzKfpfh3XU"

    output:

    [
      {
        "id": "85115de4-6f1b-4477-85ba-8138fe316369",
        "created_at": "2020-10-28T15:53:22.164Z",
        "updated_at": "2020-10-28T15:53:22.164Z",
        "disabled": false,
        "first_name": "Admin",
        "last_name": "IOTBZH",
        "email": "[email protected]",
        "type": 0,
        "ldp_id": null,
        "password": "$2b$10$FUCDGataiVyRrwdU4DeTpe/tUhdh/yIQdj/WoPpo2rkR/2Wb.eWbi",
        "badges": []
      }
    ]
  • Create badge:

    curl -X POST "http://localhost:3000/badge/create" -H  "accept: */*" -H  "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI4NTExNWRlNC02ZjFiLTQ0NzctODViYS04MTM4ZmUzMTYzNjkiLCJpYXQiOjE2MDM5MDU5OTEsImV4cCI6MTYwMzkxMzE5MX0.jTG7RX6okFbAbUfzhn2-dlQPOnJf2EI87SzKfpfh3XU" -H  "Content-Type: application/json" -d "{\"uid\":\"1514563213\",\"permission\":0,\"user\":\"85115de4-6f1b-4477-85ba-8138fe316369\"}"

    output:

    {
      "uid": "1514563213",
      "permission": 0,
      "user": "85115de4-6f1b-4477-85ba-8138fe316369",
      "id": "381b9fe1-b962-4c97-9ead-ee5772e2d252",
      "created_at": "2020-10-28T16:52:40.802Z",
      "updated_at": "2020-10-28T16:52:40.802Z",
      "disabled": false
    }

For more api information check console logs where you run make devb or visit http://localhost:3000/api-doc

Useful Documentation

License

Copyright (C) 2020-2021 IoT.bzh Company.

About

A server made in Nest to manage door-reader access, shutter and light.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published