Skip to content

Latest commit

 

History

History
45 lines (35 loc) · 1.81 KB

DEVELOP_BACKEND.md

File metadata and controls

45 lines (35 loc) · 1.81 KB

Local backend server deployment guide

Downloads

  1. Install PostgreSQL.
  2. Install NodeJS.
  3. Clone this repository (e.g. enter git clone https://github.com/Happytreat/dynalite.git in your command-line terminal).
  4. Change directory to the newly created dynalite directory by entering cd dynalite.

NodeJS setup

  1. Change directory to the src folder by entering the command cd src.
  2. Install the required packages by entering npm install.
  3. Create a file named .env in the current directory (refer to .env.backup).
  4. Open .env and enter the following:
DATABASE_URL=postgres://<username>:<password>@<hostname>:<port>/<database_name>
ALGORITHM=<algorithm>
KEY=<key>

Replace the fields in < > accordingly.

Example:

DATABASE_URL=postgres://postgres:password@localhost:5432/postgres
ALGORITHM=aes-128-cbc
KEY=helloWorldSecureKey21
  • 5432 is the default port for PostgreSQL
  • We do not actually use the above example values in deployment and neither should you

Local server setup

  1. Run this project on your local server by using npm start.
  2. Stop the server by using CTRL + C.

Testing

  1. To test Dynalite without a Raspberry Pi, refer to COAP-CLI. An example command would be: coap post coap://localhost/ -p "Hello COAP".
  2. Dynalite receives POST COAP messages at coap://localhost/ which are stored in a PostgreSQL table.
  3. Dynalite displays these stored messages at http://localhost:3000/.

Testing COAP Post Endpoint

  1. Encrypt your payload: node ./test/crypto_test.js '{"rpiId":"Room1","timestamp":"Mon Oct 28 2019 21:20:20 GMT+0800 (Singapore Standard Time)","isOccupied":false}'
  2. Send encrypted output through coap: coap post coap://localhost/ -p <output from step_1>